• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

input-output-hk / atala-prism-building-blocks / 5507804387

10 Jul 2023 12:02PM UTC coverage: 28.366% (+0.3%) from 28.076%
5507804387

Pull #575

bvoiturier
doc(prism-agent): document DID-related events in webhook.md
Pull Request #575: feat(prism-agent): simple event mechanism using webhook

409 of 409 new or added lines in 17 files covered. (100.0%)

2758 of 9723 relevant lines covered (28.37%)

0.28 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

59.46
/connect/lib/core/src/main/scala/io/iohk/atala/connect/core/service/ConnectionServiceNotifier.scala
1
package io.iohk.atala.connect.core.service
2

3
import io.iohk.atala.connect.core.model.ConnectionRecord
4
import io.iohk.atala.connect.core.model.error.ConnectionServiceError
5
import io.iohk.atala.event.notification.{Event, EventNotificationService}
6
import io.iohk.atala.mercury.model.DidId
7
import io.iohk.atala.mercury.protocol.connection.{ConnectionRequest, ConnectionResponse}
8
import zio.{IO, URLayer, ZIO, ZLayer}
9

10
import java.util.UUID
11

12
class ConnectionServiceNotifier(
13
    svc: ConnectionService,
14
    eventNotificationService: EventNotificationService
15
) extends ConnectionService {
16

17
  private val connectionUpdatedEvent = "ConnectionUpdated"
18

1✔
19
  override def createConnectionInvitation(
20
      label: Option[String],
21
      pairwiseDID: DidId
22
  ): IO[ConnectionServiceError, ConnectionRecord] =
1✔
23
    notifyOnSuccess(svc.createConnectionInvitation(label, pairwiseDID))
24

1✔
25
  override def receiveConnectionInvitation(invitation: String): IO[ConnectionServiceError, ConnectionRecord] =
1✔
26
    notifyOnSuccess(svc.receiveConnectionInvitation(invitation))
27

1✔
28
  override def acceptConnectionInvitation(
29
      recordId: UUID,
30
      pairwiseDid: DidId
31
  ): IO[ConnectionServiceError, ConnectionRecord] =
1✔
32
    notifyOnSuccess(svc.acceptConnectionInvitation(recordId, pairwiseDid))
33

1✔
34
  override def markConnectionRequestSent(recordId: UUID): IO[ConnectionServiceError, ConnectionRecord] =
1✔
35
    notifyOnSuccess(svc.markConnectionRequestSent(recordId))
36

1✔
37
  override def receiveConnectionRequest(request: ConnectionRequest): IO[ConnectionServiceError, ConnectionRecord] =
1✔
38
    notifyOnSuccess(svc.receiveConnectionRequest(request))
39

1✔
40
  override def acceptConnectionRequest(recordId: UUID): IO[ConnectionServiceError, ConnectionRecord] =
1✔
41
    notifyOnSuccess(svc.acceptConnectionRequest(recordId))
42

1✔
43
  override def markConnectionResponseSent(recordId: UUID): IO[ConnectionServiceError, ConnectionRecord] =
1✔
44
    notifyOnSuccess(svc.markConnectionResponseSent(recordId))
45

1✔
46
  override def receiveConnectionResponse(response: ConnectionResponse): IO[ConnectionServiceError, ConnectionRecord] =
1✔
47
    notifyOnSuccess(svc.receiveConnectionResponse(response))
48

1✔
49
  private[this] def notifyOnSuccess(effect: IO[ConnectionServiceError, ConnectionRecord]) =
1✔
50
    for {
51
      record <- effect
1✔
52
      _ <- notify(record)
53
    } yield record
54

1✔
55
  private[this] def notify(record: ConnectionRecord) = {
1✔
56
    val result = for {
×
57
      producer <- eventNotificationService.producer[ConnectionRecord]("Connect")
×
58
      _ <- producer.send(Event(connectionUpdatedEvent, record))
59
    } yield ()
×
60
    result.catchAll(e => ZIO.logError(s"Notification service error: $e"))
61
  }
62

×
63
  override def getConnectionRecord(recordId: UUID): IO[ConnectionServiceError, Option[ConnectionRecord]] =
×
64
    svc.getConnectionRecord(recordId)
65

×
66
  override def getConnectionRecordByThreadId(thid: String): IO[ConnectionServiceError, Option[ConnectionRecord]] =
×
67
    svc.getConnectionRecordByThreadId(thid)
68

×
69
  override def deleteConnectionRecord(recordId: UUID): IO[ConnectionServiceError, Int] =
×
70
    svc.deleteConnectionRecord(recordId)
71

×
72
  override def reportProcessingFailure(recordId: UUID, failReason: Option[String]): IO[ConnectionServiceError, Unit] =
×
73
    svc.reportProcessingFailure(recordId, failReason)
74

×
75
  override def getConnectionRecords(): IO[ConnectionServiceError, Seq[ConnectionRecord]] =
×
76
    svc.getConnectionRecords()
77

×
78
  override def getConnectionRecordsByStates(
79
      ignoreWithZeroRetries: Boolean,
80
      limit: Int,
81
      states: ConnectionRecord.ProtocolState*
82
  ): IO[ConnectionServiceError, Seq[ConnectionRecord]] =
×
83
    svc.getConnectionRecordsByStates(ignoreWithZeroRetries, limit, states: _*)
84
}
85

86
object ConnectionServiceNotifier {
87
  val layer: URLayer[ConnectionService & EventNotificationService, ConnectionService] =
1✔
88
    ZLayer.fromFunction(ConnectionServiceNotifier(_, _))
89
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc