All Downloads are FREE. Search and download functionalities are using the official Maven repository.

it.tidalwave.integritychecker.archive.impl.ScanArchiveActor Maven / Gradle / Ivy

/*
 * #%L
 * *********************************************************************************************************************
 *
 * SolidBlue - open source safe data
 * http://solidblue.tidalwave.it - hg clone https://bitbucket.org/tidalwave/solidblue-src
 * %%
 * Copyright (C) 2011 - 2014 Tidalwave s.a.s. (http://tidalwave.it)
 * %%
 * *********************************************************************************************************************
 *
 * 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.
 *
 * *********************************************************************************************************************
 *
 * $Id$
 *
 * *********************************************************************************************************************
 * #L%
 */
package it.tidalwave.integritychecker.archive.impl;

import javax.annotation.Nonnull;
import javax.annotation.concurrent.NotThreadSafe;
import java.nio.file.Path;
import it.tidalwave.netbeans.util.Locator;
import it.tidalwave.messagebus.annotation.ListensTo;
import it.tidalwave.actor.annotation.Actor;
import it.tidalwave.actor.io.filescan.FileScanRequestMessage;
import it.tidalwave.integritychecker.archive.OpenScanArchiveRequest;
import it.tidalwave.integritychecker.archive.ScanArchive;
import it.tidalwave.integritychecker.archive.ScanRequest;
import lombok.extern.slf4j.Slf4j;
import static it.tidalwave.actor.io.filescan.FileExtensionFilter.*;

/***********************************************************************************************************************
 *
 * @author  Fabrizio Giudici
 * @version $Id$
 *
 **********************************************************************************************************************/
@Actor @NotThreadSafe @Slf4j
public class ScanArchiveActor
  {
    private final String[] extensions = { "mp3", "m4a", "m4p", "NEF", "nef", "ARW", "arw", "JPG", "jpg", "TIF", "tif" };

    private final ScanArchive scanArchive = Locator.find(ScanArchive.class);

    private Path folder; // FIXME: move to scanArchive status

    /*******************************************************************************************************************
     *
     * On reception of a new {@link OpenScanArchiveRequest} it stores the folder for the next scans.
     *
     ******************************************************************************************************************/
    void onOpenScanArchiveRequest (final @ListensTo @Nonnull OpenScanArchiveRequest openScanRequest)
      {
        log.info("onOpenScanArchiveRequest({})", openScanRequest);
        this.folder = openScanRequest.getFolder();
      }

    /*******************************************************************************************************************
     *
     * Starts a scan when a new {@link ScanRequest} is received. This message can be accepted only after a
     * {@link OpenScanArchiveRequest} has been received to specify the folder to perform the scan upon.
     *
     ******************************************************************************************************************/
    void onScanRequest (final @ListensTo @Nonnull ScanRequest scanRequest)
      {
        log.info("onScanRequest({})", scanRequest);

        if (folder == null)
          {
            throw new IllegalStateException("No folder selected - a previous OpenScanArchiveRequest is required");
          }

        FileScanRequestMessage.forFolder(folder)
                              .withFilter(withExtensions(extensions))
                              .send();
      }
  }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy