Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import app.softnetwork.notification.persistence.typed.{
}
import app.softnetwork.persistence.jdbc.query.{JdbcJournalProvider, JdbcSchema, JdbcSchemaProvider}
import app.softnetwork.scheduler.api.SchedulerApi
import app.softnetwork.scheduler.config.SchedulerSettings

trait AllNotificationsApi extends SchedulerApi with NotificationApplication[Notification] {

Expand All @@ -28,7 +29,7 @@ trait AllNotificationsApi extends SchedulerApi with NotificationApplication[Noti
with AllNotificationsHandler
with JdbcJournalProvider
with JdbcSchemaProvider {
override val tag = s"${AllNotificationsBehavior.persistenceId}-scheduler"
override val tag: String = SchedulerSettings.tag(AllNotificationsBehavior.persistenceId)
override lazy val schemaType: JdbcSchema.SchemaType = jdbcSchemaType
override implicit val system: ActorSystem[_] = sys
}
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ ThisBuild / organization := "app.softnetwork"

name := "notification"

ThisBuild / version := "0.1.6.2"
ThisBuild / version := "0.2.0"

ThisBuild / scalaVersion := "2.12.15"

Expand Down
16 changes: 8 additions & 8 deletions common/src/main/protobuf/api/notification.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ service NotificationServiceApi {
}

message AddMailRequest{
org.softnetwork.notification.model.Mail mail = 1;
app.softnetwork.notification.model.Mail mail = 1;
}

message AddSMSRequest{
org.softnetwork.notification.model.SMS sms = 1;
app.softnetwork.notification.model.SMS sms = 1;
}

message AddPushRequest{
org.softnetwork.notification.model.Push push = 1;
app.softnetwork.notification.model.Push push = 1;
}

message AddNotificationResponse{
Expand All @@ -46,25 +46,25 @@ message RemoveNotificationResponse{
}

message SendMailRequest{
org.softnetwork.notification.model.Mail mail = 1;
app.softnetwork.notification.model.Mail mail = 1;
}

message SendSMSRequest{
org.softnetwork.notification.model.SMS sms = 1;
app.softnetwork.notification.model.SMS sms = 1;
}

message SendPushRequest{
org.softnetwork.notification.model.Push push = 1;
app.softnetwork.notification.model.Push push = 1;
}

message SendNotificationResponse{
repeated org.softnetwork.notification.model.NotificationStatusResult results = 1;
repeated app.softnetwork.notification.model.NotificationStatusResult results = 1;
}

message GetNotificationStatusRequest{
string uuid = 1;
}

message GetNotificationStatusResponse{
repeated org.softnetwork.notification.model.NotificationStatusResult results = 1;
repeated app.softnetwork.notification.model.NotificationStatusResult results = 1;
}
66 changes: 27 additions & 39 deletions common/src/main/protobuf/message/notification.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,32 @@ syntax = "proto2";

import "scalapb/scalapb.proto";
import "model/notifications.proto";
import "message/schedule.proto";

package org.softnetwork.notification.message;
package app.softnetwork.notification.message;

option (scalapb.options) = {
single_file: true
flat_package: true
import: "app.softnetwork.persistence.message._"
import: "org.softnetwork.akka.message.SchedulerEvents._"
import: "app.softnetwork.persistence.model._"
import: "app.softnetwork.notification.message._"
import: "app.softnetwork.scheduler.message.SchedulerEvents._"
import: "app.softnetwork.notification.model._"
import: "org.softnetwork.notification.model._"
preamble: "sealed trait NotificationEvent extends Event{def uuid: String}"
preamble: "sealed trait NotificationRecordedEvent[T<:Notification] extends NotificationEvent{def notification: T; val uuid = notification.uuid}"
preamble: "sealed trait NotificationToSchedulerEvent extends SchedulerEventWithCommand with NotificationEvent with Entity {val uuid = ALL_KEY}"
preamble: "trait NotificationCommandEvent extends NotificationEvent"
preamble: "trait AddNotificationCommandEvent extends NotificationCommandEvent {def notification: Notification; val uuid = notification.uuid}"
preamble: "trait WrapNotificationCommandEvent extends NotificationCommandEvent {def event: NotificationCommandEvent; lazy val uuid = event.uuid}"
preamble: "sealed trait NotificationEvent extends ExternalSchedulerEvent"
preamble: "trait ExternalNotificationEvent extends NotificationEvent"
preamble: "trait NotificationCommandEvent extends ExternalNotificationEvent {def command: Option[NotificationCommand]}"
preamble: "trait AddNotificationCommandEvent extends ExternalNotificationEvent {def notification: Notification}"
preserve_unknown_fields: false
};

message MailRecordedEvent{
message NotificationRecordedEvent {
option (scalapb.message).extends = "ProtobufEvent";
option (scalapb.message).extends = "NotificationRecordedEvent[Mail]";
required org.softnetwork.notification.model.Mail notification = 1;
}

message SMSRecordedEvent{
option (scalapb.message).extends = "ProtobufEvent";
option (scalapb.message).extends = "NotificationRecordedEvent[SMS]";
required org.softnetwork.notification.model.SMS notification = 1;
}

message PushRecordedEvent{
option (scalapb.message).extends = "ProtobufEvent";
option (scalapb.message).extends = "NotificationRecordedEvent[Push]";
required org.softnetwork.notification.model.Push notification = 1;
option (scalapb.message).extends = "NotificationEvent";
option (scalapb.message).extends = "NotificationRecordedEventDecorator";
oneof wrapped {
app.softnetwork.notification.model.Mail mail = 1;
app.softnetwork.notification.model.SMS sms = 2;
app.softnetwork.notification.model.Push push = 3;
}
}

message NotificationRemovedEvent{
Expand All @@ -48,38 +36,38 @@ message NotificationRemovedEvent{
required string uuid = 1;
}

message ScheduleForNotificationAdded{
message ExternalEntityToNotificationEvent{
option (scalapb.message).extends = "ProtobufEvent";
option (scalapb.message).extends = "NotificationToSchedulerEvent";
required app.softnetwork.scheduler.message.AddSchedule command = 1;
}

message ScheduleForNotificationRemoved{
option (scalapb.message).extends = "ProtobufEvent";
option (scalapb.message).extends = "NotificationToSchedulerEvent";
required app.softnetwork.scheduler.message.RemoveSchedule command = 1;
option (scalapb.message).extends = "NotificationEvent";
option (scalapb.message).extends = "ExternalEntityToNotificationEventDecorator";
oneof wrapped {
app.softnetwork.notification.message.AddMailCommandEvent addMail = 1;
app.softnetwork.notification.message.AddSMSCommandEvent addSMS = 2;
app.softnetwork.notification.message.AddPushCommandEvent addPush = 3;
app.softnetwork.notification.message.RemoveNotificationCommandEvent removeNotification = 4;
}
}

message AddMailCommandEvent{
option (scalapb.message).extends = "ProtobufEvent";
option (scalapb.message).extends = "AddNotificationCommandEvent";
required org.softnetwork.notification.model.Mail notification = 1;
required app.softnetwork.notification.model.Mail notification = 1;
}

message AddSMSCommandEvent{
option (scalapb.message).extends = "ProtobufEvent";
option (scalapb.message).extends = "AddNotificationCommandEvent";
required org.softnetwork.notification.model.SMS notification = 1;
required app.softnetwork.notification.model.SMS notification = 1;
}

message AddPushCommandEvent{
option (scalapb.message).extends = "ProtobufEvent";
option (scalapb.message).extends = "AddNotificationCommandEvent";
required org.softnetwork.notification.model.Push notification = 1;
required app.softnetwork.notification.model.Push notification = 1;
}

message RemoveNotificationCommandEvent{
option (scalapb.message).extends = "ProtobufEvent";
option (scalapb.message).extends = "NotificationCommandEvent";
option (scalapb.message).extends = "ExternalNotificationEvent";
required string uuid = 1;
}
2 changes: 1 addition & 1 deletion common/src/main/protobuf/model/notificationType.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ syntax = "proto2";

import "scalapb/scalapb.proto";

package org.softnetwork.notification.model;
package app.softnetwork.notification.model;

option (scalapb.options) = {
single_file: true
Expand Down
7 changes: 3 additions & 4 deletions common/src/main/protobuf/model/notifications.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "model/platform.proto";
import "model/notificationType.proto";
import "google/protobuf/timestamp.proto";

package org.softnetwork.notification.model;
package app.softnetwork.notification.model;

option (scalapb.options) = {
single_file: true
Expand All @@ -14,7 +14,6 @@ option (scalapb.options) = {
import: "app.softnetwork.persistence.model._"
import: "app.softnetwork.serialization._"
import: "app.softnetwork.protobuf.ScalaPBTypeMappers._"
import: "app.softnetwork.notification.model._"
preserve_unknown_fields: false
};

Expand Down Expand Up @@ -133,12 +132,12 @@ message Push{
required string id = 21 [default = ""];
required int32 badge = 22 [default = 0];
optional string sound = 23;
optional string app = 24;
optional string application = 24;
}

message PushPayload{
option (scalapb.message).extends = "ProtobufDomainObject";
required string app = 1;
required string application = 1;
required string title = 2;
required string body = 3;
required int32 badge = 4 [default = 0];
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/protobuf/model/platform.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ syntax = "proto2";

import "scalapb/scalapb.proto";

package org.softnetwork.notification.model;
package app.softnetwork.notification.model;

option (scalapb.options) = {
single_file: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package app.softnetwork.notification.api
import akka.actor.typed.ActorSystem
import akka.grpc.GrpcClientSettings
import app.softnetwork.api.server.client.{GrpcClient, GrpcClientFactory}
import org.softnetwork.notification.model.{Mail, NotificationStatusResult, Push, SMS}
import app.softnetwork.notification.model.{Mail, NotificationStatusResult, Push, SMS}

import scala.concurrent.Future

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package app.softnetwork.notification

import app.softnetwork.persistence.message._
import org.softnetwork.akka.model.Schedule
import app.softnetwork.scheduler.model.Schedule
import app.softnetwork.notification.model.Notification
import org.softnetwork.notification.model.NotificationStatusResult
import app.softnetwork.notification.model.NotificationStatusResult

/** Created by smanciot on 15/04/2020.
*/
Expand Down Expand Up @@ -89,4 +89,30 @@ package object message {

case object Schedule4NotificationNotTriggered
extends NotificationErrorMessage("Schedule4NotificationNotTriggered")

trait NotificationRecordedEventDecorator { _: NotificationRecordedEvent =>
def notification: Option[Notification] =
wrapped match {
case r: NotificationRecordedEvent.Wrapped.Mail => Some(r.value)
case r: NotificationRecordedEvent.Wrapped.Sms => Some(r.value)
case r: NotificationRecordedEvent.Wrapped.Push => Some(r.value)
case _ => None
}
}

trait ExternalEntityToNotificationEventDecorator extends NotificationCommandEvent {
_: ExternalEntityToNotificationEvent =>
override def command: Option[NotificationCommand] =
wrapped match {
case r: ExternalEntityToNotificationEvent.Wrapped.AddMail =>
Some(AddNotification(r.value.notification))
case r: ExternalEntityToNotificationEvent.Wrapped.AddSMS =>
Some(AddNotification(r.value.notification))
case r: ExternalEntityToNotificationEvent.Wrapped.AddPush =>
Some(AddNotification(r.value.notification))
case r: ExternalEntityToNotificationEvent.Wrapped.RemoveNotification =>
Some(RemoveNotification(r.value.uuid))
case _ => None
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import java.util.Date

import app.softnetwork.persistence.model.State

import org.softnetwork.notification.model._
import app.softnetwork.notification.model._

import scala.language.reflectiveCalls

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import app.softnetwork.protobuf.ScalaPBSerializers
import ScalaPBSerializers.GeneratedEnumSerializer
import app.softnetwork.serialization._
import org.json4s.Formats
import org.softnetwork.notification.model.{MailType, NotificationStatus, NotificationType, Platform}
import app.softnetwork.notification.model.{MailType, NotificationStatus, NotificationType, Platform}

import scala.language.implicitConversions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package app.softnetwork.notification

import akka.actor.typed.ActorSystem
import app.softnetwork.notification.model.Notification
import org.softnetwork.notification.model.{
import app.softnetwork.notification.model.{
Mail,
NotificationAck,
NotificationStatus,
Expand Down Expand Up @@ -52,8 +52,10 @@ package object spi {

implicit def toPushPayload(notification: Push): PushPayload = {
PushPayload.defaultInstance
.withApp(
notification.app.getOrElse(notification.from.alias.getOrElse(notification.from.value))
.withApplication(
notification.application.getOrElse(
notification.from.alias.getOrElse(notification.from.value)
)
)
.withTitle(notification.subject)
.withBody(notification.message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ 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.schedule.api.SchedulerServiceApiHandler
import app.softnetwork.scheduler.api.SchedulerServiceApiHandler

import scala.concurrent.Future

Expand Down
Loading