diff --git a/Core/src/org/sleuthkit/autopsy/appservices/AutopsyService.java b/Core/src/org/sleuthkit/autopsy/appservices/AutopsyService.java index 6e07fbe5fe..7ef7e30f01 100644 --- a/Core/src/org/sleuthkit/autopsy/appservices/AutopsyService.java +++ b/Core/src/org/sleuthkit/autopsy/appservices/AutopsyService.java @@ -1,7 +1,7 @@ /* * Autopsy Forensic Browser * - * Copyright 2011-2016 Basis Technology Corp. + * Copyright 2016-2019 Basis Technology Corp. * Contact: carrier sleuthkit org * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryDatabaseUpdateService.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryDatabaseUpdateService.java new file mode 100755 index 0000000000..62cb31153a --- /dev/null +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryDatabaseUpdateService.java @@ -0,0 +1,91 @@ +/* + * Autopsy Forensic Browser + * + * Copyright 2019 Basis Technology Corp. + * Contact: carrier sleuthkit 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.imagegallery; + +import org.openide.util.NbBundle; +import org.openide.util.lookup.ServiceProvider; +import org.openide.util.lookup.ServiceProviders; +import org.sleuthkit.autopsy.appservices.AutopsyService; +import org.sleuthkit.autopsy.progress.ProgressIndicator; +import org.sleuthkit.datamodel.TskCoreException; + +/** + * An Autopsy service that creates/opens a local drawables database and + * creates/updates the Image Gallery tables in the case database. + */ +@ServiceProviders(value = { + @ServiceProvider(service = AutopsyService.class) +}) +@NbBundle.Messages({ + "ImageGalleryDatabaseUpdateService.serviceName=Image Gallery Database Update Service" +}) +public class ImageGalleryDatabaseUpdateService implements AutopsyService { + + @Override + public String getServiceName() { + return Bundle.ImageGalleryDatabaseUpdateService_serviceName(); + } + + /** + * Creates an image gallery controller for the current case. As a result, + * creates/opens a local drawables database and creates/updates the Image + * Gallery tables in the case database. + * + * @param context The case context which includes things such as the case, a + * progress indicator for the operation, a cancellation + * request flag, etc. + * + * @throws + * org.sleuthkit.autopsy.appservices.AutopsyService.AutopsyServiceException + */ + @NbBundle.Messages({ + "ImageGalleryDatabaseUpdateService.openCaseResources.progressMessage.start=Opening Image Gallery databases...", + "ImageGalleryDatabaseUpdateService.openCaseResources.progressMessage.finish=Opened Image Gallery databases.",}) + @Override + public void openCaseResources(CaseContext context) throws AutopsyServiceException { + if (context.cancelRequested()) { + return; + } + ProgressIndicator progress = context.getProgressIndicator(); + progress.start(Bundle.ImageGalleryDatabaseUpdateService_openCaseResources_progressMessage_start()); + try { + ImageGalleryModule.createController(context.getCase()); + } catch (TskCoreException ex) { + throw new AutopsyServiceException("Error opening Image Gallery databases", ex); + } + progress.progress(Bundle.ImageGalleryDatabaseUpdateService_openCaseResources_progressMessage_finish()); + } + + /** + * Shuts down the image gallery controller for the current case. As a + * result, closes the local drawables database. + * + * @param context The case context which includes things such as the case, a + * progress indicator for the operation, a cancellation + * request flag, etc. + * + * @throws + * org.sleuthkit.autopsy.appservices.AutopsyService.AutopsyServiceException + */ + @Override + public void closeCaseResources(CaseContext context) throws AutopsyServiceException { + ImageGalleryModule.shutDownController(); + } + +} diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryModule.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryModule.java index 3c89a3b3fb..6c9f96db53 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryModule.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryModule.java @@ -76,6 +76,32 @@ public class ImageGalleryModule { @GuardedBy("controllerLock") private static ImageGalleryController controller; + /** + * Creates an image gallery controller for a case, assumed to be the current + * case. As a result, creates/opens a local drawables database and + * creates/updates the Image Gallery tables in the case database. + * + * @param currentCase The current case. + * + * @throws TskCoreException + */ + static void createController(Case currentCase) throws TskCoreException { + synchronized (controllerLock) { + controller = new ImageGalleryController(currentCase); + } + } + + /** + * Shuts down the current image gallery controller. + */ + static void shutDownController() { + synchronized (controllerLock) { + if (controller != null) { + controller.shutDown(); + } + } + } + /** * Gets the per case image gallery controller for the current case. The * controller is changed in the case event listener. @@ -88,10 +114,9 @@ public class ImageGalleryModule { synchronized (controllerLock) { if (controller == null) { try { - Case currentCase = Case.getCurrentCaseThrows(); - controller = new ImageGalleryController(currentCase); + createController(Case.getCurrentCaseThrows()); } catch (NoCurrentCaseException ex) { - throw new TskCoreException("Failed to get ", ex); + throw new TskCoreException("Failed to get current case", ex); } } return controller; @@ -178,7 +203,6 @@ public class ImageGalleryModule { * node that is running the ingest job. On a remote node, image * files are processed as a group when the ingest job is complete. */ - // RJCTODO: DO we need to handle any events at all on an auot ingest node? if (((AutopsyEvent) event).getSourceType() != AutopsyEvent.SourceType.LOCAL) { return; } @@ -245,28 +269,9 @@ public class ImageGalleryModule { @Override public void propertyChange(PropertyChangeEvent event) { - // RJCTODO: DO we need to handle any events at all on an auot ingest node? Case.Events eventType = Case.Events.valueOf(event.getPropertyName()); - if (eventType == Case.Events.CURRENT_CASE) { - synchronized (controllerLock) { - if (event.getNewValue() != null) { - /* - * CURRENT_CASE(_OPENED) event. - */ - Case newCase = (Case) event.getNewValue(); - try { - controller = new ImageGalleryController(newCase); - } catch (TskCoreException ex) { - logger.log(Level.SEVERE, String.format("Failed to construct controller for new case %s (%s)", newCase.getDisplayName(), newCase.getName()), ex); - } - } else if (event.getOldValue() != null) { - /* - * CURRENT_CASE(_CLOSED) event. - */ - SwingUtilities.invokeLater(ImageGalleryTopComponent::closeTopComponent); - controller.shutDown(); - } - } + if (eventType == Case.Events.CURRENT_CASE && event.getOldValue() != null) { + SwingUtilities.invokeLater(ImageGalleryTopComponent::closeTopComponent); } else { ImageGalleryController currentController; try { @@ -330,7 +335,6 @@ public class ImageGalleryModule { /* * Only handling data source analysis events. */ - // RJCTODO: Do we need to handle any events at all on an auto ingest node? // RJCTODO: This would be less messy if IngestManager supported // subscribing for a subset of events the way case does, and it the // conditional blocks became method calls.