Skip to content

Commit ce3a875

Browse files
authored
Merge pull request #6 from SOFTNETWORK-APP/feature/message
update notification model and message packages - update events for …
2 parents 2dc1d63 + 79daca8 commit ce3a875

34 files changed

+253
-203
lines changed

api/src/main/scala/app/softnetwork/notification/api/AllNotificationsApi.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import app.softnetwork.notification.persistence.typed.{
1414
}
1515
import app.softnetwork.persistence.jdbc.query.{JdbcJournalProvider, JdbcSchema, JdbcSchemaProvider}
1616
import app.softnetwork.scheduler.api.SchedulerApi
17+
import app.softnetwork.scheduler.config.SchedulerSettings
1718

1819
trait AllNotificationsApi extends SchedulerApi with NotificationApplication[Notification] {
1920

@@ -28,7 +29,7 @@ trait AllNotificationsApi extends SchedulerApi with NotificationApplication[Noti
2829
with AllNotificationsHandler
2930
with JdbcJournalProvider
3031
with JdbcSchemaProvider {
31-
override val tag = s"${AllNotificationsBehavior.persistenceId}-scheduler"
32+
override val tag: String = SchedulerSettings.tag(AllNotificationsBehavior.persistenceId)
3233
override lazy val schemaType: JdbcSchema.SchemaType = jdbcSchemaType
3334
override implicit val system: ActorSystem[_] = sys
3435
}

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ ThisBuild / organization := "app.softnetwork"
3131

3232
name := "notification"
3333

34-
ThisBuild / version := "0.1.6.2"
34+
ThisBuild / version := "0.2.0"
3535

3636
ThisBuild / scalaVersion := "2.12.15"
3737

common/src/main/protobuf/api/notification.proto

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ service NotificationServiceApi {
2222
}
2323

2424
message AddMailRequest{
25-
org.softnetwork.notification.model.Mail mail = 1;
25+
app.softnetwork.notification.model.Mail mail = 1;
2626
}
2727

2828
message AddSMSRequest{
29-
org.softnetwork.notification.model.SMS sms = 1;
29+
app.softnetwork.notification.model.SMS sms = 1;
3030
}
3131

3232
message AddPushRequest{
33-
org.softnetwork.notification.model.Push push = 1;
33+
app.softnetwork.notification.model.Push push = 1;
3434
}
3535

3636
message AddNotificationResponse{
@@ -46,25 +46,25 @@ message RemoveNotificationResponse{
4646
}
4747

4848
message SendMailRequest{
49-
org.softnetwork.notification.model.Mail mail = 1;
49+
app.softnetwork.notification.model.Mail mail = 1;
5050
}
5151

5252
message SendSMSRequest{
53-
org.softnetwork.notification.model.SMS sms = 1;
53+
app.softnetwork.notification.model.SMS sms = 1;
5454
}
5555

5656
message SendPushRequest{
57-
org.softnetwork.notification.model.Push push = 1;
57+
app.softnetwork.notification.model.Push push = 1;
5858
}
5959

6060
message SendNotificationResponse{
61-
repeated org.softnetwork.notification.model.NotificationStatusResult results = 1;
61+
repeated app.softnetwork.notification.model.NotificationStatusResult results = 1;
6262
}
6363

6464
message GetNotificationStatusRequest{
6565
string uuid = 1;
6666
}
6767

6868
message GetNotificationStatusResponse{
69-
repeated org.softnetwork.notification.model.NotificationStatusResult results = 1;
69+
repeated app.softnetwork.notification.model.NotificationStatusResult results = 1;
7070
}

common/src/main/protobuf/message/notification.proto

Lines changed: 27 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,32 @@ syntax = "proto2";
22

33
import "scalapb/scalapb.proto";
44
import "model/notifications.proto";
5-
import "message/schedule.proto";
65

7-
package org.softnetwork.notification.message;
6+
package app.softnetwork.notification.message;
87

98
option (scalapb.options) = {
109
single_file: true
1110
flat_package: true
1211
import: "app.softnetwork.persistence.message._"
13-
import: "org.softnetwork.akka.message.SchedulerEvents._"
1412
import: "app.softnetwork.persistence.model._"
15-
import: "app.softnetwork.notification.message._"
13+
import: "app.softnetwork.scheduler.message.SchedulerEvents._"
1614
import: "app.softnetwork.notification.model._"
17-
import: "org.softnetwork.notification.model._"
18-
preamble: "sealed trait NotificationEvent extends Event{def uuid: String}"
19-
preamble: "sealed trait NotificationRecordedEvent[T<:Notification] extends NotificationEvent{def notification: T; val uuid = notification.uuid}"
20-
preamble: "sealed trait NotificationToSchedulerEvent extends SchedulerEventWithCommand with NotificationEvent with Entity {val uuid = ALL_KEY}"
21-
preamble: "trait NotificationCommandEvent extends NotificationEvent"
22-
preamble: "trait AddNotificationCommandEvent extends NotificationCommandEvent {def notification: Notification; val uuid = notification.uuid}"
23-
preamble: "trait WrapNotificationCommandEvent extends NotificationCommandEvent {def event: NotificationCommandEvent; lazy val uuid = event.uuid}"
15+
preamble: "sealed trait NotificationEvent extends ExternalSchedulerEvent"
16+
preamble: "trait ExternalNotificationEvent extends NotificationEvent"
17+
preamble: "trait NotificationCommandEvent extends ExternalNotificationEvent {def command: Option[NotificationCommand]}"
18+
preamble: "trait AddNotificationCommandEvent extends ExternalNotificationEvent {def notification: Notification}"
2419
preserve_unknown_fields: false
2520
};
2621

27-
message MailRecordedEvent{
22+
message NotificationRecordedEvent {
2823
option (scalapb.message).extends = "ProtobufEvent";
29-
option (scalapb.message).extends = "NotificationRecordedEvent[Mail]";
30-
required org.softnetwork.notification.model.Mail notification = 1;
31-
}
32-
33-
message SMSRecordedEvent{
34-
option (scalapb.message).extends = "ProtobufEvent";
35-
option (scalapb.message).extends = "NotificationRecordedEvent[SMS]";
36-
required org.softnetwork.notification.model.SMS notification = 1;
37-
}
38-
39-
message PushRecordedEvent{
40-
option (scalapb.message).extends = "ProtobufEvent";
41-
option (scalapb.message).extends = "NotificationRecordedEvent[Push]";
42-
required org.softnetwork.notification.model.Push notification = 1;
24+
option (scalapb.message).extends = "NotificationEvent";
25+
option (scalapb.message).extends = "NotificationRecordedEventDecorator";
26+
oneof wrapped {
27+
app.softnetwork.notification.model.Mail mail = 1;
28+
app.softnetwork.notification.model.SMS sms = 2;
29+
app.softnetwork.notification.model.Push push = 3;
30+
}
4331
}
4432

4533
message NotificationRemovedEvent{
@@ -48,38 +36,38 @@ message NotificationRemovedEvent{
4836
required string uuid = 1;
4937
}
5038

51-
message ScheduleForNotificationAdded{
39+
message ExternalEntityToNotificationEvent{
5240
option (scalapb.message).extends = "ProtobufEvent";
53-
option (scalapb.message).extends = "NotificationToSchedulerEvent";
54-
required app.softnetwork.scheduler.message.AddSchedule command = 1;
55-
}
56-
57-
message ScheduleForNotificationRemoved{
58-
option (scalapb.message).extends = "ProtobufEvent";
59-
option (scalapb.message).extends = "NotificationToSchedulerEvent";
60-
required app.softnetwork.scheduler.message.RemoveSchedule command = 1;
41+
option (scalapb.message).extends = "NotificationEvent";
42+
option (scalapb.message).extends = "ExternalEntityToNotificationEventDecorator";
43+
oneof wrapped {
44+
app.softnetwork.notification.message.AddMailCommandEvent addMail = 1;
45+
app.softnetwork.notification.message.AddSMSCommandEvent addSMS = 2;
46+
app.softnetwork.notification.message.AddPushCommandEvent addPush = 3;
47+
app.softnetwork.notification.message.RemoveNotificationCommandEvent removeNotification = 4;
48+
}
6149
}
6250

6351
message AddMailCommandEvent{
6452
option (scalapb.message).extends = "ProtobufEvent";
6553
option (scalapb.message).extends = "AddNotificationCommandEvent";
66-
required org.softnetwork.notification.model.Mail notification = 1;
54+
required app.softnetwork.notification.model.Mail notification = 1;
6755
}
6856

6957
message AddSMSCommandEvent{
7058
option (scalapb.message).extends = "ProtobufEvent";
7159
option (scalapb.message).extends = "AddNotificationCommandEvent";
72-
required org.softnetwork.notification.model.SMS notification = 1;
60+
required app.softnetwork.notification.model.SMS notification = 1;
7361
}
7462

7563
message AddPushCommandEvent{
7664
option (scalapb.message).extends = "ProtobufEvent";
7765
option (scalapb.message).extends = "AddNotificationCommandEvent";
78-
required org.softnetwork.notification.model.Push notification = 1;
66+
required app.softnetwork.notification.model.Push notification = 1;
7967
}
8068

8169
message RemoveNotificationCommandEvent{
8270
option (scalapb.message).extends = "ProtobufEvent";
83-
option (scalapb.message).extends = "NotificationCommandEvent";
71+
option (scalapb.message).extends = "ExternalNotificationEvent";
8472
required string uuid = 1;
8573
}

common/src/main/protobuf/model/notificationType.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ syntax = "proto2";
22

33
import "scalapb/scalapb.proto";
44

5-
package org.softnetwork.notification.model;
5+
package app.softnetwork.notification.model;
66

77
option (scalapb.options) = {
88
single_file: true

common/src/main/protobuf/model/notifications.proto

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import "model/platform.proto";
55
import "model/notificationType.proto";
66
import "google/protobuf/timestamp.proto";
77

8-
package org.softnetwork.notification.model;
8+
package app.softnetwork.notification.model;
99

1010
option (scalapb.options) = {
1111
single_file: true
@@ -14,7 +14,6 @@ option (scalapb.options) = {
1414
import: "app.softnetwork.persistence.model._"
1515
import: "app.softnetwork.serialization._"
1616
import: "app.softnetwork.protobuf.ScalaPBTypeMappers._"
17-
import: "app.softnetwork.notification.model._"
1817
preserve_unknown_fields: false
1918
};
2019

@@ -133,12 +132,12 @@ message Push{
133132
required string id = 21 [default = ""];
134133
required int32 badge = 22 [default = 0];
135134
optional string sound = 23;
136-
optional string app = 24;
135+
optional string application = 24;
137136
}
138137

139138
message PushPayload{
140139
option (scalapb.message).extends = "ProtobufDomainObject";
141-
required string app = 1;
140+
required string application = 1;
142141
required string title = 2;
143142
required string body = 3;
144143
required int32 badge = 4 [default = 0];

common/src/main/protobuf/model/platform.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ syntax = "proto2";
22

33
import "scalapb/scalapb.proto";
44

5-
package org.softnetwork.notification.model;
5+
package app.softnetwork.notification.model;
66

77
option (scalapb.options) = {
88
single_file: true

common/src/main/scala/app/softnetwork/notification/api/NotificationClient.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package app.softnetwork.notification.api
33
import akka.actor.typed.ActorSystem
44
import akka.grpc.GrpcClientSettings
55
import app.softnetwork.api.server.client.{GrpcClient, GrpcClientFactory}
6-
import org.softnetwork.notification.model.{Mail, NotificationStatusResult, Push, SMS}
6+
import app.softnetwork.notification.model.{Mail, NotificationStatusResult, Push, SMS}
77

88
import scala.concurrent.Future
99

common/src/main/scala/app/softnetwork/notification/message/package.scala

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package app.softnetwork.notification
22

33
import app.softnetwork.persistence.message._
4-
import org.softnetwork.akka.model.Schedule
4+
import app.softnetwork.scheduler.model.Schedule
55
import app.softnetwork.notification.model.Notification
6-
import org.softnetwork.notification.model.NotificationStatusResult
6+
import app.softnetwork.notification.model.NotificationStatusResult
77

88
/** Created by smanciot on 15/04/2020.
99
*/
@@ -89,4 +89,30 @@ package object message {
8989

9090
case object Schedule4NotificationNotTriggered
9191
extends NotificationErrorMessage("Schedule4NotificationNotTriggered")
92+
93+
trait NotificationRecordedEventDecorator { _: NotificationRecordedEvent =>
94+
def notification: Option[Notification] =
95+
wrapped match {
96+
case r: NotificationRecordedEvent.Wrapped.Mail => Some(r.value)
97+
case r: NotificationRecordedEvent.Wrapped.Sms => Some(r.value)
98+
case r: NotificationRecordedEvent.Wrapped.Push => Some(r.value)
99+
case _ => None
100+
}
101+
}
102+
103+
trait ExternalEntityToNotificationEventDecorator extends NotificationCommandEvent {
104+
_: ExternalEntityToNotificationEvent =>
105+
override def command: Option[NotificationCommand] =
106+
wrapped match {
107+
case r: ExternalEntityToNotificationEvent.Wrapped.AddMail =>
108+
Some(AddNotification(r.value.notification))
109+
case r: ExternalEntityToNotificationEvent.Wrapped.AddSMS =>
110+
Some(AddNotification(r.value.notification))
111+
case r: ExternalEntityToNotificationEvent.Wrapped.AddPush =>
112+
Some(AddNotification(r.value.notification))
113+
case r: ExternalEntityToNotificationEvent.Wrapped.RemoveNotification =>
114+
Some(RemoveNotification(r.value.uuid))
115+
case _ => None
116+
}
117+
}
92118
}

common/src/main/scala/app/softnetwork/notification/model/Notification.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import java.util.Date
44

55
import app.softnetwork.persistence.model.State
66

7-
import org.softnetwork.notification.model._
7+
import app.softnetwork.notification.model._
88

99
import scala.language.reflectiveCalls
1010

0 commit comments

Comments
 (0)