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

hyperledger / identus-cloud-agent / 11056380298

26 Sep 2024 04:28PM CUT coverage: 48.66% (+0.05%) from 48.609%
11056380298

Pull #1375

yshyn-iohk
fix: migration to a new eudi.openid4vci library

Signed-off-by: Yurii Shynbuiev <yurii.shynbuiev@iohk.io>
Pull Request #1375: fix: OAS and http clients for Kotliln and TypeScript

34 of 81 new or added lines in 25 files covered. (41.98%)

182 existing lines in 53 files now uncovered.

7860 of 16153 relevant lines covered (48.66%)

0.49 hits per line

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

73.81
/pollux/sql-doobie/src/main/scala/org/hyperledger/identus/pollux/sql/model/db/CredentialSchema.scala
1
package org.hyperledger.identus.pollux.sql.model.db
2

3
import io.getquill.*
4
import io.getquill.context.json.PostgresJsonExtensions
5
import io.getquill.doobie.DoobieContext
6
import io.getquill.idiom.*
7
import org.hyperledger.identus.pollux.core.model.schema.Schema
8
import org.hyperledger.identus.pollux.core.model.ResourceResolutionMethod
9
import org.hyperledger.identus.shared.models.WalletId
10

11
import java.time.temporal.ChronoUnit
12
import java.time.OffsetDateTime
13
import java.util.UUID
14

15
case class CredentialSchema(
16
    guid: UUID,
17
    id: UUID,
18
    name: String,
19
    version: String,
20
    author: String,
21
    authored: OffsetDateTime,
22
    tags: Seq[String],
23
    description: String,
24
    `type`: String,
25
    schema: JsonValue[Schema],
26
    resolutionMethod: ResourceResolutionMethod,
27
    walletId: WalletId
28
) {
29
  lazy val uniqueConstraintKey = author + name + version
1✔
30

31
  def withTruncatedTimestamp(unit: ChronoUnit = ChronoUnit.MICROS): CredentialSchema =
1✔
32
    copy(authored = authored.truncatedTo(unit))
1✔
33

34
}
35

36
object CredentialSchema {
37
  def fromModel(
1✔
38
      m: org.hyperledger.identus.pollux.core.model.schema.CredentialSchema,
39
      walletId: WalletId
40
  ): CredentialSchema =
41
    CredentialSchema(
42
      guid = m.guid,
43
      id = m.id,
44
      name = m.name,
45
      version = m.version,
46
      author = m.author,
47
      authored = m.authored,
48
      tags = m.tags,
49
      description = m.description,
50
      `type` = m.`type`,
51
      schema = JsonValue(m.schema),
52
      resolutionMethod = m.resolutionMethod,
53
      walletId = walletId
54
    )
55

56
  def toModel(
1✔
57
      db: CredentialSchema
58
  ): org.hyperledger.identus.pollux.core.model.schema.CredentialSchema = {
59
    org.hyperledger.identus.pollux.core.model.schema.CredentialSchema(
60
      guid = db.guid,
61
      id = db.id,
62
      name = db.name,
63
      version = db.version,
64
      author = db.author,
65
      authored = db.authored,
66
      tags = db.tags,
67
      description = db.description,
68
      `type` = db.`type`,
69
      resolutionMethod = db.resolutionMethod,
70
      schema = db.schema.value
71
    )
72
  }
73
}
74

75
object CredentialSchemaSql
76
    extends DoobieContext.Postgres(SnakeCase)
77
    with PostgresJsonExtensions
78
    with PostgresEnumEncoders {
79

80
  def insert(schema: CredentialSchema) = run {
1✔
81
    quote(
82
      query[CredentialSchema]
83
        .insertValue(lift(schema))
84
    ).returning(cs => cs)
85
  }
86

87
  def findByGUID(guid: UUID, resolutionMethod: ResourceResolutionMethod) = run {
1✔
88
    quote(
89
      query[CredentialSchema]
90
        .filter(_.guid == lift(guid))
91
        .filter(_.resolutionMethod == lift(resolutionMethod))
92
        .take(1)
93
    )
94
  }
95

96
  // NOTE: this function is not used
97
  def findByID(id: UUID) = run {
×
98
    quote(query[CredentialSchema].filter(_.id == lift(id)))
99
  }
100

101
  def getAllVersions(id: UUID, author: String, resolutionMethod: ResourceResolutionMethod) = run {
1✔
102
    quote(
103
      query[CredentialSchema]
104
        .filter(_.id == lift(id))
105
        .filter(_.author == lift(author))
106
        .filter(_.resolutionMethod == lift(resolutionMethod))
107
        .sortBy(_.version)(ord = Ord.asc)
108
    )
109
  }
110

111
  def update(schema: CredentialSchema) = run {
1✔
112
    quote {
113
      query[CredentialSchema]
114
        .filter(_.guid == lift(schema.guid))
115
        .updateValue(lift(schema))
116
        .returning(s => s)
117
    }
118
  }
119

120
  def delete(guid: UUID) = run {
1✔
121
    quote {
122
      query[CredentialSchema]
123
        .filter(_.guid == lift(guid))
124
        .delete
125
        .returning(cs => cs)
126
    }
127
  }
128

129
  def deleteAll = run {
1✔
130
    quote {
131
      query[CredentialSchema].delete
132
    }
133
  }
134

135
  def totalCount = run {
1✔
136
    quote {
137
      query[CredentialSchema].size
138
    }
139
  }
140

141
  def lookupCount(
1✔
142
      idOpt: Option[UUID] = None,
1✔
143
      authorOpt: Option[String] = None,
1✔
144
      nameOpt: Option[String] = None,
1✔
145
      versionOpt: Option[String] = None,
1✔
146
      tagOpt: Option[String] = None,
1✔
NEW
147
      resolutionMethod: ResourceResolutionMethod = ResourceResolutionMethod.http
×
148
  ) = run {
×
149
    val q =
150
      idOpt.fold(quote(query[CredentialSchema]))(id =>
1✔
151
        quote(
152
          query[CredentialSchema]
153
            .filter(cs => cs.id == lift(id))
154
        )
155
      )
156

157
    q.dynamic
1✔
158
      .filterOpt(authorOpt)((cs, author) => quote(cs.author.like(author)))
159
      .filterOpt(nameOpt)((cs, name) => quote(cs.name.like(name)))
160
      .filterOpt(versionOpt)((cs, version) => quote(cs.version.like(version)))
161
      .filter(cs =>
1✔
162
        tagOpt
163
          .fold(quote(true))(tag => quote(cs.tags.contains(lift(tag))))
1✔
164
      )
165
      .filter(_.resolutionMethod == lift(resolutionMethod))
1✔
166
      .size
1✔
167
  }
168

169
  def lookup(
1✔
170
      idOpt: Option[UUID] = None,
1✔
171
      authorOpt: Option[String] = None,
×
172
      nameOpt: Option[String] = None,
×
173
      versionOpt: Option[String] = None,
×
174
      tagOpt: Option[String] = None,
×
175
      offset: Int = 0,
×
176
      limit: Int = 1000,
×
NEW
177
      resolutionMethod: ResourceResolutionMethod = ResourceResolutionMethod.http
×
UNCOV
178
  ) = run {
×
179
    val q =
180
      idOpt.fold(quote(query[CredentialSchema]))(id =>
1✔
181
        quote(
182
          query[CredentialSchema]
183
            .filter(cs => cs.id == lift(id))
184
        )
185
      )
186

187
    q.dynamic
1✔
188
      .filterOpt(authorOpt)((cs, author) => quote(cs.author.like(author)))
189
      .filterOpt(nameOpt)((cs, name) => quote(cs.name.like(name)))
190
      .filterOpt(versionOpt)((cs, version) => quote(cs.version.like(version)))
191
      .filter(cs =>
1✔
192
        tagOpt
193
          .fold(quote(true))(tag => quote(cs.tags.contains(lift(tag))))
1✔
194
      )
195
      .filter(_.resolutionMethod == lift(resolutionMethod))
1✔
196
      .sortBy(cs => cs.id)
197
      .drop(offset)
198
      .take(limit)
199
  }
200
}
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