Skip to content

Commit f183d7d

Browse files
irinaschubertsubotic
andauthored
fix(cardinality): Check cardinality with multiple inherited classes (DEV-1189) (#2164)
* check that always the stricter cardinality is taken * add unit tests * remove replaced method * add comments * introduce value objects for cardinalities * check cardinality compatibility in case of multiple super classes * fix error message * clean up docstrings * fix broken docs link * remove unused project * fix error in docs * add testdata and tests * fix build.sbt * simplify test data * improve comments * cleanup imports * fix bad references for coverage * improve comments * reintroduce return * wrap case objects * simplify test * fix missing import * implement feedback from review * run scalafmt Co-authored-by: Ivan Subotic <400790+subotic@users.noreply.github.com>
1 parent 79b88d2 commit f183d7d

46 files changed

Lines changed: 672 additions & 426 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Makefile‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@ test: build ## runs all tests
209209
sbt -v coverage "userHandler/test"
210210
sbt -v coverage "userInterface/test"
211211
sbt -v coverage "userRepo/test"
212-
sbt -v coverage "valueObjects/test"
213212
sbt -v coverage "webapi/test"
214213
sbt coverageAggregate
215214

‎build.sbt‎

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,20 @@ lazy val buildSettings = Seq(
2727
lazy val rootBaseDir = ThisBuild / baseDirectory
2828

2929
lazy val root: Project = Project(id = "root", file("."))
30-
.aggregate(webapi, sipi, shared, valueObjects, userCore, userHandler, userRepo, userInterface)
30+
.aggregate(
31+
webapi,
32+
sipi,
33+
shared,
34+
userCore,
35+
userHandler,
36+
userRepo,
37+
userInterface,
38+
roleCore,
39+
roleRepo,
40+
roleHandler,
41+
roleInterface,
42+
schemaCore
43+
)
3144
.enablePlugins(GitVersioning, GitBranchPrompt)
3245
.settings(
3346
// values set for all sub-projects
@@ -231,16 +244,6 @@ lazy val webapiJavaTestOptions = Seq(
231244
// DSP's new codebase
232245
//////////////////////////////////////
233246

234-
// Value Objects project
235-
236-
lazy val valueObjects = project
237-
.in(file("dsp-value-objects"))
238-
.settings(
239-
name := "valueObjects",
240-
libraryDependencies ++= Dependencies.valueObjectsLibraryDependencies,
241-
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework"))
242-
)
243-
244247
// Role projects
245248

246249
lazy val roleInterface = project

‎docs/02-knora-ontologies/knora-base.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ In Knora, each item of data belongs to some particular project. Each project usi
3232

3333
- `projectShortname` (1): A short name that can be used to identify the project in configuration files and the like.
3434

35-
- `projectLongname` (1): The full name of the project.
35+
- `projectLongname` (0-1): The full name of the project.
3636

3737
- `projectShortcode` (1): A hexadecimal code that uniquely identifies the project. These codes are assigned to projects
3838
by the [DaSCH](http://dasch.swiss/).

‎docs/Readme.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## MkDocs Documentation
44

55
This folder contains the sources to the DSP-API documentation website published
6-
under <http://docs-api.dasch.swiss>
6+
under <https://docs.dasch.swiss/>
77

88
The `src` folder contains the following documentation sources:
99

‎dsp-role/handler/src/main/scala/dsp/role/handler/RoleHandler.scala‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,10 @@ final case class RoleHandler(repo: RoleRepo) {
138138
* Companion object providing the layer with an initialized implementation
139139
*/
140140
object RoleHandler {
141-
val layer: ZLayer[RoleRepo, Nothing, RoleHandler] = {
141+
val layer: ZLayer[RoleRepo, Nothing, RoleHandler] =
142142
ZLayer {
143143
for {
144144
repo <- ZIO.service[RoleRepo]
145145
} yield RoleHandler(repo)
146146
}.tap(_ => ZIO.logInfo(">>> Role Handler initilaized <<<"))
147-
}
148147
}

‎dsp-role/repo/src/main/scala/dsp/role/repo/impl/RoleRepoLive.scala‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,10 @@ final case class RoleRepoLive(
6363
* Companion object providing the layer with an initialized implementation of [[RoleRepo]]
6464
*/
6565
object RoleRepoLive {
66-
val layer: ZLayer[Any, Nothing, RoleRepo] = {
66+
val layer: ZLayer[Any, Nothing, RoleRepo] =
6767
ZLayer {
6868
for {
6969
roles <- TMap.empty[UUID, Role].commit
7070
} yield RoleRepoLive(roles)
7171
}.tap(_ => ZIO.logInfo(">>> Role repository initialized <<<"))
72-
}
7372
}

‎dsp-role/repo/src/test/scala/dsp/role/repo/impl/RoleRepoMock.scala‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,10 @@ final case class RoleRepoMock(
6363
* Companion object providing the layer with an initialized implementation of [[RoleRepo]]
6464
*/
6565
object RoleRepoMock {
66-
val layer: ZLayer[Any, Nothing, RoleRepo] = {
66+
val layer: ZLayer[Any, Nothing, RoleRepo] =
6767
ZLayer {
6868
for {
6969
roles <- TMap.empty[UUID, Role].commit
7070
} yield RoleRepoMock(roles)
7171
}.tap(_ => ZIO.logInfo(">>> In-memory role repository initialized <<<"))
72-
}
7372
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright © 2021 - 2022 Data and Service Center for the Humanities and/or DaSCH Service Platform contributors.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package dsp.schema.domain
7+
8+
import Cardinality._
9+
10+
/**
11+
* Represents a cardinality value object.
12+
*/
13+
sealed trait Cardinality { self =>
14+
15+
/**
16+
* The string representation of the cardinality
17+
*/
18+
val value: String
19+
20+
/**
21+
* Checks whether a cardinality is stricter than another one.
22+
*
23+
* @param that the cardinality to be compared against
24+
* @return `true` if the present cardinality is stricter than `that`, `false` otherwise
25+
*/
26+
def isStricterThan(that: Cardinality): Boolean =
27+
if (self == that) {
28+
false
29+
} else {
30+
self match {
31+
case MustHaveOne => true
32+
case MustHaveSome => that == MayHaveMany
33+
case MayHaveOne => that == MayHaveMany
34+
case MayHaveMany => false
35+
}
36+
}
37+
}
38+
39+
object Cardinality {
40+
41+
/**
42+
* The cardinality of a property that must have one value.
43+
*/
44+
final case object MustHaveOne extends Cardinality {
45+
override val value: String = "1"
46+
}
47+
48+
/**
49+
* The cardinality of a property that must have at least one value.
50+
*/
51+
final case object MustHaveSome extends Cardinality {
52+
override val value: String = "1-n"
53+
}
54+
55+
/**
56+
* The cardinality of a property that may have one value.
57+
*/
58+
final case object MayHaveOne extends Cardinality {
59+
override val value: String = "0-1"
60+
}
61+
62+
/**
63+
* The cardinality of a property that may have one or more values.
64+
*/
65+
final case object MayHaveMany extends Cardinality {
66+
override val value: String = "0-n"
67+
}
68+
}

‎dsp-schema/core/src/main/scala/dsp/schema/domain/SchemaFunctionalDomain.scala‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ object SchemaDomain extends App {
210210
implicit def isSubtypeOf2[A, B >: A]: NotSubtypeOf[A, B] = new NotSubtypeOf[A, B] {}
211211
}
212212

213-
//trying it out
213+
// trying it out
214214
val ontoInfo = OntologyInfo("test", "http://example.org/test", "Test", "Test")
215215

216216
val classOne = OntologyClass("ClassOne", "Class One", "Class One")
@@ -230,8 +230,8 @@ object SchemaDomain extends App {
230230
.withClass(classOne)
231231
.withClass(classTwo)
232232
.withProperty(propertyOne)
233-
//.withProperty(propertyOne)
234-
//.withProperty(propertyTwo)
233+
// .withProperty(propertyOne)
234+
// .withProperty(propertyTwo)
235235
.withCardinality(cardOne)
236236
.withCardinality(cardOne)
237237

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
package dsp.schema.handler
22

3-
object CreateSchema {
4-
5-
}
3+
object CreateSchema {}

0 commit comments

Comments
 (0)