Skip to content

Commit

Permalink
refactor: Introduce PredicateInfoV2Builder & ReadPropertyInfoV2Builde…
Browse files Browse the repository at this point in the history
…r and simplify api transformation rule (#3385)
  • Loading branch information
seakayone authored Oct 18, 2024
1 parent a248973 commit 9bc08fa
Show file tree
Hide file tree
Showing 8 changed files with 803 additions and 2,020 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class OntologyFormatsE2ESpec extends E2ESpec {
private def makeFile(fileEnding: String = "jsonld"): Path =
Paths.get("..", "test_data", "generated_test_data", "ontologyR2RV2", s"$fileBasename.$fileEnding")

def storeAsTtl: Unit = {
private def storeAsTtl(): Unit = {
val jsonStr = readFile()
val model = parseJsonLd(jsonStr)
val ttlStr = RdfFormatUtil.format(model, Turtle)
Expand All @@ -68,7 +68,7 @@ class OntologyFormatsE2ESpec extends E2ESpec {
val newOutputFile = makeFile()
Files.createDirectories(newOutputFile.getParent)
FileUtil.writeTextFile(newOutputFile, responseStr)
if (persistTtl) storeAsTtl
if (persistTtl) storeAsTtl()
else ()
}
}
Expand Down
23 changes: 23 additions & 0 deletions webapi/src/main/scala/org/knora/webapi/LanguageCode.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright © 2021 - 2024 Swiss National Data and Service Center for the Humanities and/or DaSCH Service Platform contributors.
* SPDX-License-Identifier: Apache-2.0
*/

package org.knora.webapi

/**
* Constants for language codes.
*/
enum LanguageCode(val code: String) {
case DE extends LanguageCode("de")
case EN extends LanguageCode("en")
case FR extends LanguageCode("fr")
case IT extends LanguageCode("it")
case RM extends LanguageCode("rm")
}

object LanguageCode {
def from(value: String): Option[LanguageCode] = values.find(_.code == value)
def isSupported(value: String): Boolean = from(value).isDefined
def isNotSupported(value: String): Boolean = !isSupported(value)
}
25 changes: 0 additions & 25 deletions webapi/src/main/scala/org/knora/webapi/LanguageCodes.scala

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,9 @@ object StringLiteralV2 {
implicit val codec: JsonCodec[StringLiteralV2] = DeriveJsonCodec.gen[StringLiteralV2]
implicit val schema: Schema[StringLiteralV2] = Schema.derived[StringLiteralV2]

def from(value: String, lang: LanguageCode): StringLiteralV2 =
from(value, Some(lang.code))

def from(value: String, language: Option[String]): StringLiteralV2 = language match {
case Some(_) if value.isEmpty => throw BadRequestException("String value is missing.")
case _ => StringLiteralV2(value, language)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ case class JsonLDArray(value: Seq[JsonLDValue]) extends JsonLDValue {
(s, errFun) => Iri.toSparqlEncodedString(s).getOrElse(errFun)
val lang = obj.requireStringWithValidation(JsonLDKeywords.LANGUAGE, validationFun)

if (!LanguageCodes.SupportedLanguageCodes(lang)) {
if (LanguageCode.isNotSupported(lang)) {
throw BadRequestException(s"Unsupported language code: $lang")
}

Expand Down
Loading

0 comments on commit 9bc08fa

Please sign in to comment.