Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/slicebox/slicebox into d…
Browse files Browse the repository at this point in the history
…evelop
  • Loading branch information
KarlSjostrand committed Sep 9, 2018
2 parents 531939e + 20bc159 commit 8bf0ba4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ slicebox {
with-ssl = false
}

directory-watch {
delete-on-import = false
}

dicom-storage {
file-system {
name = "on-disk"
Expand Down
5 changes: 4 additions & 1 deletion src/main/scala/se/nimsa/sbx/app/Slicebox.scala
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ trait SliceboxBase extends SliceboxRoutes with DicomStreamOps with JsonFormats w
val boxService: ActorRef = system.actorOf(BoxServiceActor.props(boxDao, apiBaseURL, storage), name = "BoxService")
val scpService: ActorRef = system.actorOf(ScpServiceActor.props(scpDao, storage), name = "ScpService")
val scuService: ActorRef = system.actorOf(ScuServiceActor.props(scuDao, storage), name = "ScuService")
val directoryService: ActorRef = system.actorOf(DirectoryWatchServiceActor.props(directoryWatchDao, storage), name = "DirectoryService")
val directoryService: ActorRef = {
val deleteWatchedDirectory: Boolean = sliceboxConfig.getBoolean("directory-watch.delete-on-import")
system.actorOf(DirectoryWatchServiceActor.props(directoryWatchDao, storage, deleteWatchedDirectory), name = "DirectoryService")
}
val seriesTypeService: ActorRef = system.actorOf(SeriesTypeServiceActor.props(seriesTypeDao, storage), name = "SeriesTypeService")
val forwardingService: ActorRef = system.actorOf(ForwardingServiceActor.props(forwardingDao, storage), name = "ForwardingService")
val importService: ActorRef = system.actorOf(ImportServiceActor.props(importDao), name = "ImportService")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import scala.util.control.NonFatal

class DirectoryWatchActor(watchedDirectory: WatchedDirectory,
storage: StorageService,
deleteWatchedDirectory: Boolean,
metaDataServicePath: String = "../../MetaDataService",
anonymizationServicePath: String = "../../AnonymizationService")
(implicit val materializer: Materializer, timeout: Timeout) extends Actor with DicomStreamOps {
Expand Down Expand Up @@ -69,9 +70,11 @@ class DirectoryWatchActor(watchedDirectory: WatchedDirectory,
else
StreamSource.empty // other (symlinks etc): ignore
}
.mapAsync(5) { path => // do import
.mapAsync(5) { path => // do import, delete if successful (might be permission issues here)
storeDicomData(FileIO.fromPath(path), sbxSource, storage, Contexts.imageDataContexts, reverseAnonymization = true).map { metaData =>
system.eventStream.publish(ImageAdded(metaData.image.id, sbxSource, !metaData.imageAdded))
system.eventStream.publish(ImageAdded(metaData.image.id, sbxSource, !metaData.imageAdded))
if (deleteWatchedDirectory)
Files.deleteIfExists(path)
}.recover {
case NonFatal(e) =>
SbxLog.error("Directory", s"Could not add file ${Paths.get(watchedDirectory.path).relativize(path)}: ${e.getMessage}")
Expand Down Expand Up @@ -102,5 +105,5 @@ class DirectoryWatchActor(watchedDirectory: WatchedDirectory,
}

object DirectoryWatchActor {
def props(watchedDirectory: WatchedDirectory, storage: StorageService)(implicit materializer: Materializer, timeout: Timeout): Props = Props(new DirectoryWatchActor(watchedDirectory, storage))
def props(watchedDirectory: WatchedDirectory, storage: StorageService, deleteWatchedDirectory: Boolean)(implicit materializer: Materializer, timeout: Timeout): Props = Props(new DirectoryWatchActor(watchedDirectory, storage, deleteWatchedDirectory))
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import se.nimsa.sbx.storage.StorageService
import se.nimsa.sbx.util.ExceptionCatching
import se.nimsa.sbx.util.FutureUtil.await

class DirectoryWatchServiceActor(directoryWatchDao: DirectoryWatchDAO, storage: StorageService)(implicit materializer: Materializer, timeout: Timeout) extends Actor with ExceptionCatching {
class DirectoryWatchServiceActor(directoryWatchDao: DirectoryWatchDAO, storage: StorageService, deleteWatchedDirectory: Boolean)(implicit materializer: Materializer, timeout: Timeout) extends Actor with ExceptionCatching {
val log = Logging(context.system, this)

setupWatches()
Expand Down Expand Up @@ -63,7 +63,7 @@ class DirectoryWatchServiceActor(directoryWatchDao: DirectoryWatchDAO, storage:
val watchedDirectory = addDirectory(directory)

context.child(watchedDirectory.id.toString).getOrElse(
context.actorOf(DirectoryWatchActor.props(watchedDirectory, storage), watchedDirectory.id.toString))
context.actorOf(DirectoryWatchActor.props(watchedDirectory, storage, deleteWatchedDirectory), watchedDirectory.id.toString))

sender ! watchedDirectory
}
Expand All @@ -89,7 +89,7 @@ class DirectoryWatchServiceActor(directoryWatchDao: DirectoryWatchDAO, storage:
watchedDirectories foreach (watchedDirectory => {
val path = Paths.get(watchedDirectory.path)
if (Files.isDirectory(path))
context.actorOf(DirectoryWatchActor.props(watchedDirectory, storage), watchedDirectory.id.toString)
context.actorOf(DirectoryWatchActor.props(watchedDirectory, storage, deleteWatchedDirectory), watchedDirectory.id.toString)
else
deleteDirectory(watchedDirectory.id)
})
Expand All @@ -113,5 +113,5 @@ class DirectoryWatchServiceActor(directoryWatchDao: DirectoryWatchDAO, storage:
}

object DirectoryWatchServiceActor {
def props(directoryWatchDao: DirectoryWatchDAO, storage: StorageService)(implicit materializer: Materializer, timeout: Timeout): Props = Props(new DirectoryWatchServiceActor(directoryWatchDao, storage))
def props(directoryWatchDao: DirectoryWatchDAO, storage: StorageService, deleteWatchedDirectory: Boolean)(implicit materializer: Materializer, timeout: Timeout): Props = Props(new DirectoryWatchServiceActor(directoryWatchDao, storage, deleteWatchedDirectory))
}

0 comments on commit 8bf0ba4

Please sign in to comment.