diff --git a/api/build.sbt b/api/build.sbt index 6229d2e..163f582 100644 --- a/api/build.sbt +++ b/api/build.sbt @@ -28,6 +28,6 @@ organization := "app.softnetwork.notification" name := "notification-api" libraryDependencies ++= Seq( - "app.softnetwork.persistence" %% "persistence-jdbc" % Versions.genericPersistence, + "app.softnetwork.persistence" %% "akka-persistence-jdbc" % Versions.genericPersistence, "app.softnetwork.scheduler" %% "scheduler-api" % Versions.scheduler ) diff --git a/api/src/main/scala/app/softnetwork/notification/api/AllNotificationsWithSchedulerApi.scala b/api/src/main/scala/app/softnetwork/notification/api/AllNotificationsWithSchedulerApi.scala new file mode 100644 index 0000000..a8eb08e --- /dev/null +++ b/api/src/main/scala/app/softnetwork/notification/api/AllNotificationsWithSchedulerApi.scala @@ -0,0 +1,25 @@ +package app.softnetwork.notification.api + +import akka.actor.typed.ActorSystem +import akka.http.scaladsl.model.{HttpRequest, HttpResponse} +import app.softnetwork.persistence.launch.PersistentEntity +import app.softnetwork.persistence.query.EventProcessorStream +import app.softnetwork.scheduler.api.{SchedulerApi, SchedulerServiceApiHandler} + +import scala.concurrent.Future + +trait AllNotificationsWithSchedulerApi extends AllNotificationsApi with SchedulerApi { + + override def entities: ActorSystem[_] => Seq[PersistentEntity[_, _, _, _]] = sys => + schedulerEntities(sys) ++ notificationEntities(sys) + + override def eventProcessorStreams: ActorSystem[_] => Seq[EventProcessorStream[_]] = sys => + schedulerEventProcessorStreams(sys) ++ + notificationEventProcessorStreams(sys) + + override def grpcServices + : ActorSystem[_] => Seq[PartialFunction[HttpRequest, Future[HttpResponse]]] = system => + notificationServers(system).map( + NotificationServiceApiHandler.partial(_)(system) + ) :+ SchedulerServiceApiHandler.partial(schedulerServer(system))(system) +} diff --git a/api/src/main/scala/app/softnetwork/notification/api/AllNotificationsWithSchedulerPostgresLauncher.scala b/api/src/main/scala/app/softnetwork/notification/api/AllNotificationsWithSchedulerPostgresLauncher.scala new file mode 100644 index 0000000..7a76daa --- /dev/null +++ b/api/src/main/scala/app/softnetwork/notification/api/AllNotificationsWithSchedulerPostgresLauncher.scala @@ -0,0 +1,7 @@ +package app.softnetwork.notification.api + +import app.softnetwork.persistence.jdbc.query.PostgresSchemaProvider + +object AllNotificationsWithSchedulerPostgresLauncher + extends AllNotificationsWithSchedulerApi + with PostgresSchemaProvider diff --git a/core/build.sbt b/core/build.sbt index 13e4feb..c279fb7 100644 --- a/core/build.sbt +++ b/core/build.sbt @@ -1,9 +1,3 @@ -import app.softnetwork.sbt.build._ - organization := "app.softnetwork.notification" name := "notification-core" - -libraryDependencies ++= Seq( - "app.softnetwork.scheduler" %% "scheduler-core" % Versions.scheduler -) diff --git a/core/src/main/scala/app/softnetwork/notification/launch/NotificationApplication.scala b/core/src/main/scala/app/softnetwork/notification/launch/NotificationApplication.scala index 8100611..3d0d964 100644 --- a/core/src/main/scala/app/softnetwork/notification/launch/NotificationApplication.scala +++ b/core/src/main/scala/app/softnetwork/notification/launch/NotificationApplication.scala @@ -6,7 +6,6 @@ import app.softnetwork.api.server.launch.HealthCheckApplication import app.softnetwork.notification.api.NotificationServiceApiHandler import app.softnetwork.notification.model.Notification import app.softnetwork.persistence.query.SchemaProvider -import app.softnetwork.scheduler.api.SchedulerServiceApiHandler import scala.concurrent.Future @@ -18,5 +17,5 @@ trait NotificationApplication[T <: Notification] : ActorSystem[_] => Seq[PartialFunction[HttpRequest, Future[HttpResponse]]] = system => notificationServers(system).map( NotificationServiceApiHandler.partial(_)(system) - ) :+ SchedulerServiceApiHandler.partial(schedulerServer(system))(system) + ) } diff --git a/core/src/main/scala/app/softnetwork/notification/launch/NotificationGuardian.scala b/core/src/main/scala/app/softnetwork/notification/launch/NotificationGuardian.scala index 8df0b36..551e044 100644 --- a/core/src/main/scala/app/softnetwork/notification/launch/NotificationGuardian.scala +++ b/core/src/main/scala/app/softnetwork/notification/launch/NotificationGuardian.scala @@ -8,14 +8,14 @@ import app.softnetwork.notification.persistence.query.{ Scheduler2NotificationProcessorStream } import app.softnetwork.notification.persistence.typed.NotificationBehavior -import app.softnetwork.persistence.launch.PersistentEntity +import app.softnetwork.persistence.launch.{PersistenceGuardian, PersistentEntity} import app.softnetwork.persistence.query.{EventProcessorStream, SchemaProvider} -import app.softnetwork.scheduler.launch.SchedulerGuardian -import app.softnetwork.scheduler.persistence.query.Scheduler2EntityProcessorStream +import com.typesafe.scalalogging.StrictLogging import scala.language.implicitConversions -trait NotificationGuardian[T <: Notification] extends SchedulerGuardian { _: SchemaProvider => +trait NotificationGuardian[T <: Notification] extends PersistenceGuardian with StrictLogging { + _: SchemaProvider => import app.softnetwork.persistence.launch.PersistenceGuardian._ @@ -27,31 +27,21 @@ trait NotificationGuardian[T <: Notification] extends SchedulerGuardian { _: Sch /** initialize all entities */ override def entities: ActorSystem[_] => Seq[PersistentEntity[_, _, _, _]] = sys => - schedulerEntities(sys) ++ notificationEntities(sys) + notificationEntities(sys) def scheduler2NotificationProcessorStream : ActorSystem[_] => Option[Scheduler2NotificationProcessorStream] = _ => None - override def scheduler2EntityProcessorStreams - : ActorSystem[_] => Seq[Scheduler2EntityProcessorStream[_, _]] = sys => - scheduler2NotificationProcessorStream(sys) match { - case Some(value) => Seq(value) - case _ => Seq.empty - } - def notificationCommandProcessorStream : ActorSystem[_] => Option[NotificationCommandProcessorStream] = _ => None def notificationEventProcessorStreams: ActorSystem[_] => Seq[EventProcessorStream[_]] = sys => - notificationCommandProcessorStream(sys) match { - case Some(value) => Seq(value) - case _ => Seq.empty - } + Seq(scheduler2NotificationProcessorStream(sys)).flatten ++ + Seq(notificationCommandProcessorStream(sys)).flatten /** initialize all event processor streams */ override def eventProcessorStreams: ActorSystem[_] => Seq[EventProcessorStream[_]] = sys => - schedulerEventProcessorStreams(sys) ++ notificationEventProcessorStreams(sys) /** initialize all notification servers diff --git a/core/src/main/scala/app/softnetwork/notification/persistence/typed/NotificationBehavior.scala b/core/src/main/scala/app/softnetwork/notification/persistence/typed/NotificationBehavior.scala index 49b215a..b4680b9 100644 --- a/core/src/main/scala/app/softnetwork/notification/persistence/typed/NotificationBehavior.scala +++ b/core/src/main/scala/app/softnetwork/notification/persistence/typed/NotificationBehavior.scala @@ -18,7 +18,6 @@ import app.softnetwork.persistence.typed._ import app.softnetwork.notification.message._ import app.softnetwork.notification.model._ import app.softnetwork.notification.spi.NotificationProvider -import app.softnetwork.notification.model._ import app.softnetwork.scheduler.config.SchedulerSettings import app.softnetwork.notification.model.NotificationStatus._ diff --git a/project/src/main/scala/app/softnetwork/sbt/build/Versions.scala b/project/src/main/scala/app/softnetwork/sbt/build/Versions.scala index b4d292e..4ef13d9 100644 --- a/project/src/main/scala/app/softnetwork/sbt/build/Versions.scala +++ b/project/src/main/scala/app/softnetwork/sbt/build/Versions.scala @@ -4,7 +4,7 @@ object Versions { val genericPersistence = "0.2.5.15" - val scheduler = "0.2.0" + val scheduler = "0.2.1" val server = "0.2.6.2" diff --git a/testkit/src/main/scala/app/softnetwork/notification/api/NotificationGrpcServer.scala b/testkit/src/main/scala/app/softnetwork/notification/api/NotificationGrpcServer.scala index 3f6f1d2..b6548b5 100644 --- a/testkit/src/main/scala/app/softnetwork/notification/api/NotificationGrpcServer.scala +++ b/testkit/src/main/scala/app/softnetwork/notification/api/NotificationGrpcServer.scala @@ -1,14 +1,17 @@ package app.softnetwork.notification.api import akka.http.scaladsl.testkit.PersistenceScalatestGrpcTest +import app.softnetwork.api.server.scalatest.ServerTestKit import app.softnetwork.notification.launch.NotificationGuardian import app.softnetwork.notification.model.Notification import app.softnetwork.persistence.scalatest.InMemoryPersistenceTestKit +import app.softnetwork.scheduler.launch.SchedulerGuardian import org.scalatest.Suite trait NotificationGrpcServer[T <: Notification] extends PersistenceScalatestGrpcTest with NotificationGrpcServices[T] - with InMemoryPersistenceTestKit { _: Suite with NotificationGuardian[T] => + with InMemoryPersistenceTestKit { + _: Suite with NotificationGuardian[T] with SchedulerGuardian with ServerTestKit => override lazy val additionalConfig: String = notificationGrpcConfig } diff --git a/testkit/src/main/scala/app/softnetwork/notification/api/NotificationGrpcServices.scala b/testkit/src/main/scala/app/softnetwork/notification/api/NotificationGrpcServices.scala index 5938d35..c0c6952 100644 --- a/testkit/src/main/scala/app/softnetwork/notification/api/NotificationGrpcServices.scala +++ b/testkit/src/main/scala/app/softnetwork/notification/api/NotificationGrpcServices.scala @@ -6,11 +6,12 @@ import app.softnetwork.api.server.scalatest.ServerTestKit import app.softnetwork.notification.launch.NotificationGuardian import app.softnetwork.notification.model.Notification import app.softnetwork.scheduler.api.SchedulerGrpcServices +import app.softnetwork.scheduler.launch.SchedulerGuardian import scala.concurrent.Future trait NotificationGrpcServices[T <: Notification] extends SchedulerGrpcServices { - _: NotificationGuardian[T] with ServerTestKit => + _: NotificationGuardian[T] with SchedulerGuardian with ServerTestKit => override def grpcServices : ActorSystem[_] => Seq[PartialFunction[HttpRequest, Future[HttpResponse]]] = system => diff --git a/testkit/src/main/scala/app/softnetwork/notification/scalatest/NotificationTestKit.scala b/testkit/src/main/scala/app/softnetwork/notification/scalatest/NotificationTestKit.scala index a795a65..8fe5c46 100644 --- a/testkit/src/main/scala/app/softnetwork/notification/scalatest/NotificationTestKit.scala +++ b/testkit/src/main/scala/app/softnetwork/notification/scalatest/NotificationTestKit.scala @@ -13,6 +13,8 @@ import app.softnetwork.scheduler.scalatest.SchedulerTestKit import com.typesafe.config.Config import org.scalatest.Suite import app.softnetwork.notification.model.{BasicDevice, From, Mail, Platform, Push, SMS} +import app.softnetwork.persistence.launch.PersistentEntity +import app.softnetwork.persistence.query.EventProcessorStream import java.net.ServerSocket @@ -73,4 +75,11 @@ trait NotificationTestKit[T <: Notification] asystem.eventStream.tell(Subscribe(probe.ref)) lazy val client: NotificationClient = NotificationClient(asystem) + + override def entities: ActorSystem[_] => Seq[PersistentEntity[_, _, _, _]] = sys => + schedulerEntities(sys) ++ notificationEntities(sys) + + override def eventProcessorStreams: ActorSystem[_] => Seq[EventProcessorStream[_]] = sys => + schedulerEventProcessorStreams(sys) ++ + notificationEventProcessorStreams(sys) }