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

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

27 Sep 2023 09:41AM UTC coverage: 29.012% (-0.1%) from 29.134%
6324188894

Pull #693

bvoiturier
Merge branch 'main' into feat/new-anoncred-endpoints
Pull Request #693: [WIP] feat: new IssuedCredentialFormat for anoncred

726 of 726 new or added lines in 50 files covered. (100.0%)

3592 of 12381 relevant lines covered (29.01%)

0.29 hits per line

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

57.5
/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 io.iohk.atala.shared.models.WalletAccessContext
9
import zio.{URLayer, ZIO, ZLayer}
10

11
import java.time.Duration
12
import java.util.UUID
13

14
class ConnectionServiceNotifier(
15
    svc: ConnectionService,
16
    eventNotificationService: EventNotificationService
17
) extends ConnectionService {
18

19
  private val connectionUpdatedEvent = "ConnectionUpdated"
20

1✔
21
  override def createConnectionInvitation(
22
      label: Option[String],
23
      pairwiseDID: DidId
24
  ): ZIO[WalletAccessContext, ConnectionServiceError, ConnectionRecord] =
1✔
25
    notifyOnSuccess(svc.createConnectionInvitation(label, pairwiseDID))
26

1✔
27
  override def receiveConnectionInvitation(
28
      invitation: String
29
  ): ZIO[WalletAccessContext, ConnectionServiceError, ConnectionRecord] =
1✔
30
    notifyOnSuccess(svc.receiveConnectionInvitation(invitation))
31

1✔
32
  override def acceptConnectionInvitation(
33
      recordId: UUID,
34
      pairwiseDid: DidId
35
  ): ZIO[WalletAccessContext, ConnectionServiceError, ConnectionRecord] =
1✔
36
    notifyOnSuccess(svc.acceptConnectionInvitation(recordId, pairwiseDid))
37

1✔
38
  override def markConnectionRequestSent(
39
      recordId: UUID
40
  ): ZIO[WalletAccessContext, ConnectionServiceError, ConnectionRecord] =
1✔
41
    notifyOnSuccess(svc.markConnectionRequestSent(recordId))
42

1✔
43
  override def receiveConnectionRequest(
44
      request: ConnectionRequest,
45
      expirationTime: Option[Duration]
46
  ): ZIO[WalletAccessContext, ConnectionServiceError, ConnectionRecord] =
1✔
47
    notifyOnSuccess(svc.receiveConnectionRequest(request, expirationTime))
48

1✔
49
  override def acceptConnectionRequest(
50
      recordId: UUID
51
  ): ZIO[WalletAccessContext, ConnectionServiceError, ConnectionRecord] =
1✔
52
    notifyOnSuccess(svc.acceptConnectionRequest(recordId))
53

1✔
54
  override def markConnectionResponseSent(
55
      recordId: UUID
56
  ): ZIO[WalletAccessContext, ConnectionServiceError, ConnectionRecord] =
1✔
57
    notifyOnSuccess(svc.markConnectionResponseSent(recordId))
58

×
59
  override def markConnectionInvitationExpired(
60
      recordId: UUID
61
  ): ZIO[WalletAccessContext, ConnectionServiceError, ConnectionRecord] =
×
62
    notifyOnSuccess(svc.markConnectionInvitationExpired(recordId))
63

1✔
64
  override def receiveConnectionResponse(
65
      response: ConnectionResponse
66
  ): ZIO[WalletAccessContext, ConnectionServiceError, ConnectionRecord] =
1✔
67
    notifyOnSuccess(svc.receiveConnectionResponse(response))
68

1✔
69
  private[this] def notifyOnSuccess(effect: ZIO[WalletAccessContext, ConnectionServiceError, ConnectionRecord]) =
1✔
70
    for {
71
      record <- effect
1✔
72
      _ <- notify(record)
73
    } yield record
74

1✔
75
  private[this] def notify(record: ConnectionRecord) = {
1✔
76
    val result = for {
×
77
      walletId <- ZIO.serviceWith[WalletAccessContext](_.walletId)
1✔
78
      producer <- eventNotificationService.producer[ConnectionRecord]("Connect")
×
79
      _ <- producer.send(Event(connectionUpdatedEvent, record, walletId))
80
    } yield ()
×
81
    result.catchAll(e => ZIO.logError(s"Notification service error: $e"))
82
  }
83

×
84
  override def getConnectionRecord(
85
      recordId: UUID
86
  ): ZIO[WalletAccessContext, ConnectionServiceError, Option[ConnectionRecord]] =
×
87
    svc.getConnectionRecord(recordId)
88

×
89
  override def getConnectionRecordByThreadId(
90
      thid: String
91
  ): ZIO[WalletAccessContext, ConnectionServiceError, Option[ConnectionRecord]] =
×
92
    svc.getConnectionRecordByThreadId(thid)
93

×
94
  override def deleteConnectionRecord(recordId: UUID): ZIO[WalletAccessContext, ConnectionServiceError, Int] =
×
95
    svc.deleteConnectionRecord(recordId)
96

×
97
  override def reportProcessingFailure(
98
      recordId: UUID,
99
      failReason: Option[String]
100
  ): ZIO[WalletAccessContext, ConnectionServiceError, Unit] =
×
101
    svc.reportProcessingFailure(recordId, failReason)
102

×
103
  override def getConnectionRecords(): ZIO[WalletAccessContext, ConnectionServiceError, Seq[ConnectionRecord]] =
×
104
    svc.getConnectionRecords()
105

×
106
  override def getConnectionRecordsByStates(
107
      ignoreWithZeroRetries: Boolean,
108
      limit: Int,
109
      states: ConnectionRecord.ProtocolState*
110
  ): ZIO[WalletAccessContext, ConnectionServiceError, Seq[ConnectionRecord]] =
×
111
    svc.getConnectionRecordsByStates(ignoreWithZeroRetries, limit, states: _*)
112
}
113

114
object ConnectionServiceNotifier {
115
  val layer: URLayer[ConnectionService & EventNotificationService, ConnectionService] =
1✔
116
    ZLayer.fromFunction(ConnectionServiceNotifier(_, _))
117
}
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