1 /*
2  *  Make.org Core API
3  *  Copyright (C) 2018 Make.org
4  *
5  * This program is free software: you can redistribute it and/or modify
6  *  it under the terms of the GNU Affero General Public License as
7  *  published by the Free Software Foundation, either version 3 of the
8  *  License, or (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU Affero General Public License for more details.
14  *
15  *  You should have received a copy of the GNU Affero General Public License
16  *  along with this program.  If not, see <https://www.gnu.org/licenses/>.
17  *
18  */
19 
20 package org.make.api.technical.crm
21 
22 import akka.actor.typed.Behavior
23 import grizzled.slf4j.Logging
24 import org.make.api.technical.KafkaProducerBehavior
25 import org.make.core.{DateHelper, MakeSerializable}
26 
27 import java.time.{Instant, ZoneOffset, ZonedDateTime}
28 
29 class MailJetEventProducerBehavior extends KafkaProducerBehavior[MailJetEvent, MailJetEventWrapper] with Logging {
30   override protected val topicKey: String = MailJetEventProducerBehavior.topicKey
31   override protected def wrapEvent(event: MailJetEvent): MailJetEventWrapper = {
32     logger.debug(s"Produce MailJetEvent: ${event.toString}")
33     MailJetEventWrapper(version = MakeSerializable.V1, id = event.email, date = event.time.map { timestamp =>
34       ZonedDateTime.from(Instant.ofEpochMilli(timestamp * 1000).atZone(ZoneOffset.UTC))
35     }.getOrElse(DateHelper.now()), event = event)
36   }
37 }
38 
39 object MailJetEventProducerBehavior {
40   def apply(): Behavior[MailJetEvent] = new MailJetEventProducerBehavior().createBehavior(name)
41 
42   val name: String = "mailjet-events-producer"
43   val topicKey: String = "mailjet-events"
44 }
Line Stmt Id Pos Tree Symbol Tests Code
30 7743 1163 - 1200 Select org.make.api.technical.crm.MailJetEventProducerBehavior.topicKey org.scalatest.testsuite MailJetEventProducerBehavior.topicKey
32 6915 1286 - 1342 Apply grizzled.slf4j.Logger.debug MailJetEventProducerBehavior.this.logger.debug(("Produce MailJetEvent: ".+(event.toString()): String))
33 6183 1377 - 1396 Select org.make.core.MakeSerializable.V1 org.make.core.MakeSerializable.V1
33 5656 1403 - 1414 Select org.make.api.technical.crm.MailJetEvent.email event.email
33 6921 1347 - 1590 Apply org.make.api.technical.crm.MailJetEventWrapper.apply MailJetEventWrapper.apply(org.make.core.MakeSerializable.V1, event.email, event.time.map[java.time.ZonedDateTime](((timestamp: Long) => java.time.ZonedDateTime.from(java.time.Instant.ofEpochMilli(timestamp.*(1000)).atZone(java.time.ZoneOffset.UTC)))).getOrElse[java.time.ZonedDateTime](org.make.core.DateHelper.now()), event)
34 7174 1499 - 1515 Apply scala.Long.* timestamp.*(1000)
34 7269 1459 - 1540 Apply java.time.ZonedDateTime.from java.time.ZonedDateTime.from(java.time.Instant.ofEpochMilli(timestamp.*(1000)).atZone(java.time.ZoneOffset.UTC))
34 7604 1478 - 1539 Apply java.time.Instant.atZone java.time.Instant.ofEpochMilli(timestamp.*(1000)).atZone(java.time.ZoneOffset.UTC)
34 6225 1524 - 1538 Select java.time.ZoneOffset.UTC java.time.ZoneOffset.UTC
35 6397 1557 - 1573 Apply org.make.core.DefaultDateHelper.now org.make.core.DateHelper.now()
35 7850 1423 - 1574 Apply scala.Option.getOrElse event.time.map[java.time.ZonedDateTime](((timestamp: Long) => java.time.ZonedDateTime.from(java.time.Instant.ofEpochMilli(timestamp.*(1000)).atZone(java.time.ZoneOffset.UTC)))).getOrElse[java.time.ZonedDateTime](org.make.core.DateHelper.now())
40 6144 1726 - 1730 Select org.make.api.technical.crm.MailJetEventProducerBehavior.name org.scalatest.testsuite MailJetEventProducerBehavior.this.name
40 5752 1676 - 1731 Apply org.make.api.technical.KafkaProducerBehavior.createBehavior org.scalatest.testsuite new MailJetEventProducerBehavior().createBehavior(MailJetEventProducerBehavior.this.name)
42 7175 1754 - 1779 Literal <nosymbol> org.scalatest.testsuite "mailjet-events-producer"
43 6327 1805 - 1821 Literal <nosymbol> org.scalatest.testsuite "mailjet-events"