Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* add isSequenceOf to knora-base ontology * add hasSequenceBounds to knora-base * bump knora-base version * better error messages * test: write test to create isSequenceOf resource classes for video resources in ontology * update testdata according to modified knora-base ontology * test: add test for audio sequence in ontology * make ontology model slightly slimmer * add sequence bounds property to ontology tests * fix minor oversights in knora-base * minor refactorings * start working on a test ontology and dataset for sequences * add ontology constants * add test for dynamically creating a video resource * bump API version again * add audio (including subclasses of isSequenceOf etc.) to sequences ontology * add audio resource to sequences data * add tests for audio sequences with ontology-specific sub-props of isSequenceOf etc. * refactor: remove some code duplication * create client test data * add newly created test data to list of expected test data * add noop upgrade plugin * use Validation in OntologyHelpers * replace more throws with validations * fix validation * createPropertyCommand value object in schema slice * remove client test data * add isSequenceOf to anything ontology * update test data to change anything ontology * add unit tests to ontology part of the changes * add documentation * first improvements according to review * Update LangString.scala * improve LangString value object * add tests for LangString value object * move language code error messages in the right place * add documentation to SchemaCommands * add tests for SchemaCommands * rename V3 smartIri in OntologiesRoute * apply feedback from review * fix problems after merge conflicts * add logging to unsafeMake * tidy up language code stuff Co-authored-by: Ivan Subotic <400790+subotic@users.noreply.github.com>
- Loading branch information
1 parent
3eddfc4
commit 74366d4
Showing
60 changed files
with
10,565 additions
and
6,973 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
dsp-schema/core/src/main/scala/dsp/schema/domain/SchemaCommands.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package dsp.schema.domain | ||
|
||
import dsp.errors.ValidationException | ||
import dsp.valueobjects.LangString | ||
import dsp.valueobjects.Schema | ||
import zio.prelude.Validation | ||
|
||
import java.time.Instant | ||
|
||
/** | ||
* SmartIri placeholder value object. | ||
* WARNING: don't use this in production code. First find a solution how we deal with SmartIri in the new codebase. | ||
* | ||
* // TODO: this is only a placeholder for SmartIri - eventually we need a proper solution for IRI value objects. | ||
*/ | ||
case class SmartIri(value: String) | ||
|
||
/** | ||
* Command/Value object representing a command to create a property on a schema/ontology. | ||
* WARNING: This should not be used in production code before the SmartIri value object is propertly implemented. | ||
*/ | ||
sealed abstract case class CreatePropertyCommand private ( | ||
ontologyIri: SmartIri, | ||
lastModificationDate: Instant, | ||
propertyIri: SmartIri, | ||
subjectType: Option[SmartIri], | ||
objectType: SmartIri, // must be `kb:Value`, unless it's a link property, then it should be a `kb:Resource` | ||
label: LangString, | ||
comment: Option[LangString], | ||
superProperties: List[SmartIri], | ||
guiObject: Schema.GuiObject | ||
) | ||
|
||
object CreatePropertyCommand { | ||
def make( | ||
ontologyIri: SmartIri, // TODO: should eventally be schemaId value object, etc. | ||
lastModificationDate: Instant, | ||
propertyIri: SmartIri, | ||
subjectType: Option[SmartIri], | ||
objectType: SmartIri, | ||
label: LangString, | ||
comment: Option[LangString], | ||
superProperties: List[SmartIri], | ||
guiObject: Schema.GuiObject | ||
): Validation[ValidationException, CreatePropertyCommand] = | ||
Validation.succeed( | ||
new CreatePropertyCommand( | ||
ontologyIri = ontologyIri, | ||
lastModificationDate = lastModificationDate, | ||
propertyIri = propertyIri, | ||
subjectType = subjectType, | ||
objectType = objectType, | ||
label = label, | ||
comment = comment, | ||
superProperties = superProperties, | ||
guiObject = guiObject | ||
) {} | ||
) | ||
} |
51 changes: 51 additions & 0 deletions
51
dsp-schema/core/src/test/scala/dsp/schema/domain/SchemaCommandsSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package dsp.schema.domain | ||
|
||
import dsp.constants.SalsahGui | ||
import dsp.valueobjects.LangString | ||
import dsp.valueobjects.LanguageCode | ||
import dsp.valueobjects.Schema | ||
import zio._ | ||
import zio.prelude.Validation | ||
import zio.test.Assertion._ | ||
import zio.test._ | ||
|
||
import java.time.Instant | ||
|
||
/** | ||
* This spec is used to test [[dsp.schema.domain.SchemaCommands]]. | ||
*/ | ||
object SchemaCommandsSpec extends ZIOSpecDefault { | ||
|
||
def spec = (createPropertyCommandTest) | ||
|
||
private val createPropertyCommandTest = suite("CreatePropertyCommand")( | ||
test("create a createPropertyCommand") { | ||
val ontologyIri = SmartIri("Ontology IRI") | ||
val lastModificationDate = Instant.now() | ||
val propertyIri = SmartIri("") | ||
val subjectType = None | ||
val objectType = SmartIri("Object Type") | ||
val superProperties = List(SmartIri("Super Property IRI")) | ||
(for { | ||
label <- LangString.make(LanguageCode.en, "some label") | ||
commentLangString <- LangString.make(LanguageCode.en, "some comment") | ||
comment = Some(commentLangString) | ||
guiAttribute <- Schema.GuiAttribute.make("hlist=<http://rdfh.ch/lists/082F/PbRLUy66TsK10qNP1mBwzA>") | ||
guiElement <- Schema.GuiElement.make(SalsahGui.List) | ||
guiObject <- Schema.GuiObject.make(guiAttributes = List(guiAttribute), guiElement = Some(guiElement)) | ||
command = CreatePropertyCommand.make( | ||
ontologyIri = ontologyIri, | ||
lastModificationDate = lastModificationDate, | ||
propertyIri = propertyIri, | ||
subjectType = subjectType, | ||
objectType = objectType, | ||
label = label, | ||
comment = comment, | ||
superProperties = superProperties, | ||
guiObject = guiObject | ||
) | ||
} yield assert(command.toEither)(isRight)).toZIO | ||
} | ||
) | ||
|
||
} |
64 changes: 64 additions & 0 deletions
64
dsp-shared/src/main/scala/dsp/valueobjects/LangString.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package dsp.valueobjects | ||
|
||
import dsp.errors.ValidationException | ||
import zio.prelude.Validation | ||
import zio._ | ||
|
||
/** | ||
* LangString value object | ||
*/ | ||
sealed abstract case class LangString private (language: LanguageCode, value: String) | ||
|
||
object LangString { | ||
|
||
/** | ||
* Creates a [[zio.prelude.Validation]] that either fails with a ValidationException or succeeds with a LangString value object. | ||
* | ||
* @param language a [[LanguageCode]] value object representing the language of the LangString. | ||
* @param value the string value of the LangString. | ||
* @return a Validation of a LangString value object. | ||
*/ | ||
def make(language: LanguageCode, value: String): Validation[ValidationException, LangString] = | ||
if (value.isBlank()) { | ||
Validation.fail(ValidationException(LangStringErrorMessages.LangStringValueEmpty)) | ||
} else { | ||
Validation.succeed(new LangString(language, value) {}) | ||
} | ||
|
||
/** | ||
* Creates a [[zio.prelude.Validation]] that either fails with a ValidationException or succeeds with a LangString value object. | ||
* | ||
* @param language a two-digit language code string representing the language of the LangString. | ||
* @param value the string value of the LangString. | ||
* @return a Validation of a LangString value object. | ||
*/ | ||
def makeFromStrings(language: String, value: String): Validation[ValidationException, LangString] = | ||
for { | ||
languageCode <- LanguageCode.make(language) | ||
langString <- LangString.make(languageCode, value) | ||
} yield langString | ||
|
||
/** | ||
* Unsafely creates a LangString value object. | ||
* Warning: skips all validation. Should not be used unless there is no possibility for the data to be invalid. | ||
* | ||
* @param languagea [[LanguageCode]] value object representing the language of the LangString. | ||
* @param value the string value of the LangString. | ||
* @return a LanguageCode value object | ||
*/ | ||
def unsafeMake(language: LanguageCode, value: String): LangString = | ||
LangString | ||
.make(language = language, value = value) | ||
.fold( | ||
e => { | ||
val unsafe = new LangString(language, value) {} | ||
ZIO.logWarning(s"Called unsafeMake() for an invalid $unsafe: $e") // TODO-BL: get this to actually log | ||
unsafe | ||
}, | ||
langString => langString | ||
) | ||
} | ||
|
||
object LangStringErrorMessages { | ||
val LangStringValueEmpty = "String value cannot be empty." | ||
} |
51 changes: 51 additions & 0 deletions
51
dsp-shared/src/main/scala/dsp/valueobjects/LanguageCode.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright © 2021 - 2022 Swiss National Data and Service Center for the Humanities and/or DaSCH Service Platform contributors. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package dsp.valueobjects | ||
|
||
import dsp.errors.ValidationException | ||
import zio.prelude.Validation | ||
|
||
/** | ||
* LanguageCode value object. | ||
*/ | ||
sealed abstract case class LanguageCode private (value: String) | ||
|
||
object LanguageCode { self => | ||
val DE: String = "de" | ||
val EN: String = "en" | ||
val FR: String = "fr" | ||
val IT: String = "it" | ||
val RM: String = "rm" | ||
// TODO-BL: with NewTypes we shouldn't need the strings separately anymore, as the valueobject can be used just like a string value | ||
|
||
val SupportedLanguageCodes: Set[String] = Set( | ||
DE, | ||
EN, | ||
FR, | ||
IT, | ||
RM | ||
) | ||
|
||
def make(value: String): Validation[ValidationException, LanguageCode] = | ||
if (value.isEmpty) { | ||
Validation.fail(ValidationException(LanguageCodeErrorMessages.LanguageCodeMissing)) | ||
} else if (!SupportedLanguageCodes.contains(value)) { | ||
Validation.fail(ValidationException(LanguageCodeErrorMessages.LanguageCodeInvalid(value))) | ||
} else { | ||
Validation.succeed(new LanguageCode(value) {}) | ||
} | ||
|
||
lazy val en: LanguageCode = new LanguageCode(EN) {} | ||
lazy val de: LanguageCode = new LanguageCode(DE) {} | ||
lazy val fr: LanguageCode = new LanguageCode(FR) {} | ||
lazy val it: LanguageCode = new LanguageCode(IT) {} | ||
lazy val rm: LanguageCode = new LanguageCode(RM) {} | ||
} | ||
|
||
object LanguageCodeErrorMessages { | ||
val LanguageCodeMissing = "LanguageCode cannot be empty." | ||
def LanguageCodeInvalid(lang: String) = s"LanguageCode '$lang' is invalid." | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.