Skip to content

Commit

Permalink
Migrate the fulltext search to tapir
Browse files Browse the repository at this point in the history
  • Loading branch information
seakayone committed Dec 3, 2023
1 parent 5e1f23b commit 3f86148
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 200 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import org.knora.webapi.messages.util.rdf.JsonLDUtil
import org.knora.webapi.messages.util.search.SparqlQueryConstants
import org.knora.webapi.routing.UnsafeZioRun
import org.knora.webapi.routing.v2.ResourcesRouteV2
import org.knora.webapi.routing.v2.SearchRouteV2
import org.knora.webapi.routing.v2.StandoffRouteV2
import org.knora.webapi.routing.v2.ValuesRouteV2
import org.knora.webapi.sharedtestdata.SharedTestDataADM
Expand All @@ -54,13 +53,9 @@ import pekko.http.scaladsl.model.headers.BasicHttpCredentials
*/
class SearchRouteV2R2RSpec extends R2RSpec {
private implicit val stringFormatter: StringFormatter = StringFormatter.getGeneralInstance
private val searchPathNew = UnsafeZioRun
private val searchPath = UnsafeZioRun
.runOrThrow(ZIO.serviceWith[SearchApiRoutes](_.routes))
.reduce(_ ~ _)
private val searchPathOld = DSPApiDirectives.handleErrors(appConfig)(
SearchRouteV2(routeData.appConfig.v2.fulltextSearch.searchValueMinLength).makeRoute
)
private val searchPath = searchPathNew ~ searchPathOld

private val resourcePath =
DSPApiDirectives.handleErrors(appConfig)(ResourcesRouteV2(appConfig).makeRoute)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ final case class SearchResponderV2Live(
limitToStandoffClass: Option[SmartIri]
): Task[ResourceCountV2] =
for {
_ <- ensureIsFulltextSearch(searchValue)
searchValue <- validateSearchString(searchValue)
limitToResourceClass <- ZIO.foreach(limitToResourceClass)(ensureResourceClassIri)
limitToStandoffClass <- ZIO.foreach(limitToStandoffClass)(ensureStandoffClass)

Check warning on line 257 in webapi/src/main/scala/org/knora/webapi/responders/v2/SearchResponderV2.scala

View check run for this annotation

Codecov / codecov/patch

webapi/src/main/scala/org/knora/webapi/responders/v2/SearchResponderV2.scala#L254-L257

Added lines #L254 - L257 were not covered by tests
countSparql <- ZIO.attempt(
sparql.v2.txt
.searchFulltext(
Expand Down Expand Up @@ -300,6 +304,10 @@ final case class SearchResponderV2Live(
): Task[ReadResourcesSequenceV2] = {
import org.knora.webapi.messages.util.search.FullTextMainQueryGenerator.FullTextSearchConstants
for {
_ <- ensureIsFulltextSearch(searchValue)
searchValue <- validateSearchString(searchValue)
limitToResourceClass <- ZIO.foreach(limitToResourceClass)(ensureResourceClassIri)
limitToStandoffClass <- ZIO.foreach(limitToStandoffClass)(ensureStandoffClass)

Check warning on line 310 in webapi/src/main/scala/org/knora/webapi/responders/v2/SearchResponderV2.scala

View check run for this annotation

Codecov / codecov/patch

webapi/src/main/scala/org/knora/webapi/responders/v2/SearchResponderV2.scala#L307-L310

Added lines #L307 - L310 were not covered by tests
searchSparql <-
ZIO.attempt(
sparql.v2.txt
Expand Down Expand Up @@ -856,7 +864,7 @@ final case class SearchResponderV2Live(
): Task[ResourceCountV2] =
for {
searchValue <- validateSearchString(searchValue)
_ <- ensureIsNotFullTextSearch(searchValue)
_ <- ensureIsFulltextSearch(searchValue)
limitToResourceClass <- ZIO.foreach(limitToResourceClass)(ensureResourceClassIri)
searchTerm = MatchStringWhileTyping(searchValue).generateLiteralForLuceneIndexWithoutExactSequence

Check warning on line 869 in webapi/src/main/scala/org/knora/webapi/responders/v2/SearchResponderV2.scala

View check run for this annotation

Codecov / codecov/patch

webapi/src/main/scala/org/knora/webapi/responders/v2/SearchResponderV2.scala#L866-L869

Added lines #L866 - L869 were not covered by tests
countSparql =
Expand All @@ -882,7 +890,14 @@ final case class SearchResponderV2Live(
} else { ZIO.fail(BadRequestException(errMsg)) }

Check failure on line 890 in webapi/src/main/scala/org/knora/webapi/responders/v2/SearchResponderV2.scala

View workflow job for this annotation

GitHub Actions / WebApi Integration Test Results

org.knora.webapi.responders.v2.SearchResponderV2Spec ► The search responder v2 should perform a search by label for incunabula:book that contain 'Narrenschiff'

Failed test found in: ./integration/target/test-reports/TEST-org.knora.webapi.responders.v2.SearchResponderV2Spec.xml Error: sbt.ForkMain$ForkError: zio.FiberFailure: Resource class IRI <http://www.knora.org/ontology/0803/incunabula#book> is not a valid Knora API v2 entity IRI
Raw output
sbt.ForkMain$ForkError: zio.FiberFailure: Resource class IRI <http://www.knora.org/ontology/0803/incunabula#book> is not a valid Knora API v2 entity IRI
	at org.knora.webapi.responders.v2.SearchResponderV2Live.$anonfun$ensureResourceClassIri$2(SearchResponderV2.scala:890)
	at zio.ZIO$.$anonfun$fail$1(ZIO.scala:3151)
	at zio.ZIO$.$anonfun$failCause$3(ZIO.scala:3160)
	at org.knora.webapi.responders.v2.SearchResponderV2Live.ensureResourceClassIri(SearchResponderV2.scala:890)
	at org.knora.webapi.responders.v2.SearchResponderV2Live.searchResourcesByLabelV2(SearchResponderV2.scala:930)
	at org.knora.webapi.routing.UnsafeZioRun.runOrThrow(UnsafeZioRun.scala:32)
Caused by: sbt.ForkMain$ForkError: dsp.errors.BadRequestException: Resource class IRI <http://www.knora.org/ontology/0803/incunabula#book> is not a valid Knora API v2 entity IRI
	at org.knora.webapi.responders.v2.SearchResponderV2Live.$anonfun$ensureResourceClassIri$2(SearchResponderV2.scala:890)
	at zio.ZIO$.$anonfun$fail$1(ZIO.scala:3151)
	at zio.ZIO$.$anonfun$failCause$3(ZIO.scala:3160)
	at zio.internal.FiberRuntime.runLoop(FiberRuntime.scala:890)
	at zio.internal.FiberRuntime.evaluateEffect(FiberRuntime.scala:381)
	at zio.internal.FiberRuntime.start(FiberRuntime.scala:1339)
	at zio.Runtime$UnsafeAPIV1.runOrFork(Runtime.scala:160)
	at zio.Runtime$UnsafeAPIV1.run(Runtime.scala:132)
	at org.knora.webapi.routing.UnsafeZioRun$.$anonfun$runOrThrow$1(UnsafeZioRun.scala:32)
	at zio.Unsafe$.unsafe(Unsafe.scala:37)
	at org.knora.webapi.routing.UnsafeZioRun$.runOrThrow(UnsafeZioRun.scala:32)
	at org.knora.webapi.responders.v2.SearchResponderV2Spec.$anonfun$new$10(SearchResponderV2Spec.scala:154)
	at org.scalatest.OutcomeOf.outcomeOf(OutcomeOf.scala:85)
	at org.scalatest.OutcomeOf.outcomeOf$(OutcomeOf.scala:83)
	at org.scalatest.OutcomeOf$.outcomeOf(OutcomeOf.scala:104)
	at org.scalatest.Transformer.apply(Transformer.scala:22)
	at org.scalatest.Transformer.apply(Transformer.scala:20)
	at org.scalatest.wordspec.AnyWordSpecLike$$anon$3.apply(AnyWordSpecLike.scala:1240)
	at org.scalatest.TestSuite.withFixture(TestSuite.scala:196)
	at org.scalatest.TestSuite.withFixture$(TestSuite.scala:195)
	at org.scalatest.wordspec.AnyWordSpec.withFixture(AnyWordSpec.scala:1880)
	at org.scalatest.wordspec.AnyWordSpecLike.invokeWithFixture$1(AnyWordSpecLike.scala:1238)
	at org.scalatest.wordspec.AnyWordSpecLike.$anonfun$runTest$1(AnyWordSpecLike.scala:1250)
	at org.scalatest.SuperEngine.runTestImpl(Engine.scala:306)
	at org.scalatest.wordspec.AnyWordSpecLike.runTest(AnyWordSpecLike.scala:1250)
	at org.scalatest.wordspec.AnyWordSpecLike.runTest$(AnyWordSpecLike.scala:1232)
	at org.scalatest.wordspec.AnyWordSpec.runTest(AnyWordSpec.scala:1880)
	at org.scalatest.wordspec.AnyWordSpecLike.$anonfun$runTests$1(AnyWordSpecLike.scala:1309)
	at org.scalatest.SuperEngine.$anonfun$runTestsInBranch$1(Engine.scala:413)
	at scala.collection.immutable.List.foreach(List.scala:333)
	at org.scalatest.SuperEngine.traverseSubNodes$1(Engine.scala:401)
	at org.scalatest.SuperEngine.runTestsInBranch(Engine.scala:390)
	at org.scalatest.SuperEngine.$anonfun$runTestsInBranch$1(Engine.scala:427)
	at scala.collection.immutable.List.foreach(List.scala:333)
	at org.scalatest.SuperEngine.traverseSubNodes$1(Engine.scala:401)
	at org.scalatest.SuperEngine.runTestsInBranch(Engine.scala:396)
	at org.scalatest.SuperEngine.runTestsImpl(Engine.scala:475)
	at org.scalatest.wordspec.AnyWordSpecLike.runTests(AnyWordSpecLike.scala:1309)
	at org.scalatest.wordspec.AnyWordSpecLike.runTests$(AnyWordSpecLike.scala:1308)
	at org.scalatest.wordspec.AnyWordSpec.runTests(AnyWordSpec.scala:1880)
	at org.scalatest.Suite.run(Suite.scala:1114)
	at org.scalatest.Suite.run$(Suite.scala:1096)
	at org.scalatest.wordspec.AnyWordSpec.org$scalatest$wordspec$AnyWordSpecLike$$super$run(AnyWordSpec.scala:1880)
	at org.scalatest.wordspec.AnyWordSpecLike.$anonfun$run$1(AnyWordSpecLike.scala:1354)
	at org.scalatest.SuperEngine.runImpl(Engine.scala:535)
	at org.scalatest.wordspec.AnyWordSpecLike.run(AnyWordSpecLike.scala:1354)
	at org.scalatest.wordspec.AnyWordSpecLike.run$(AnyWordSpecLike.scala:1352)
	at org.knora.webapi.CoreSpec.org$scalatest$BeforeAndAfterAll$$super$run(CoreSpec.scala:32)
	at org.scalatest.BeforeAndAfterAll.liftedTree1$1(BeforeAndAfterAll.scala:213)
	at org.scalatest.BeforeAndAfterAll.run(BeforeAndAfterAll.scala:210)
	at org.scalatest.BeforeAndAfterAll.run$(BeforeAndAfterAll.scala:208)
	at org.knora.webapi.CoreSpec.run(CoreSpec.scala:32)
	at org.scalatest.tools.Framework.org$scalatest$tools$Framework$$runSuite(Framework.scala:321)
	at org.scalatest.tools.Framework$ScalaTestTask.execute(Framework.scala:517)
	at sbt.ForkMain$Run.lambda$runTest$1(ForkMain.java:414)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
	at java.base/java.lang.Thread.run(Thread.java:1583)

Check failure on line 890 in webapi/src/main/scala/org/knora/webapi/responders/v2/SearchResponderV2.scala

View workflow job for this annotation

GitHub Actions / WebApi Integration Test Results

org.knora.webapi.responders.v2.SearchResponderV2Spec ► The search responder v2 should perform a search by label for incunabula:book that contain 'Das Narrenschiff'

Failed test found in: ./integration/target/test-reports/TEST-org.knora.webapi.responders.v2.SearchResponderV2Spec.xml Error: sbt.ForkMain$ForkError: zio.FiberFailure: Resource class IRI <http://www.knora.org/ontology/0803/incunabula#book> is not a valid Knora API v2 entity IRI
Raw output
sbt.ForkMain$ForkError: zio.FiberFailure: Resource class IRI <http://www.knora.org/ontology/0803/incunabula#book> is not a valid Knora API v2 entity IRI
	at org.knora.webapi.responders.v2.SearchResponderV2Live.$anonfun$ensureResourceClassIri$2(SearchResponderV2.scala:890)
	at zio.ZIO$.$anonfun$fail$1(ZIO.scala:3151)
	at zio.ZIO$.$anonfun$failCause$3(ZIO.scala:3160)
	at org.knora.webapi.responders.v2.SearchResponderV2Live.ensureResourceClassIri(SearchResponderV2.scala:890)
	at org.knora.webapi.responders.v2.SearchResponderV2Live.searchResourcesByLabelV2(SearchResponderV2.scala:930)
	at org.knora.webapi.routing.UnsafeZioRun.runOrThrow(UnsafeZioRun.scala:32)
Caused by: sbt.ForkMain$ForkError: dsp.errors.BadRequestException: Resource class IRI <http://www.knora.org/ontology/0803/incunabula#book> is not a valid Knora API v2 entity IRI
	at org.knora.webapi.responders.v2.SearchResponderV2Live.$anonfun$ensureResourceClassIri$2(SearchResponderV2.scala:890)
	at zio.ZIO$.$anonfun$fail$1(ZIO.scala:3151)
	at zio.ZIO$.$anonfun$failCause$3(ZIO.scala:3160)
	at zio.internal.FiberRuntime.runLoop(FiberRuntime.scala:890)
	at zio.internal.FiberRuntime.evaluateEffect(FiberRuntime.scala:381)
	at zio.internal.FiberRuntime.start(FiberRuntime.scala:1339)
	at zio.Runtime$UnsafeAPIV1.runOrFork(Runtime.scala:160)
	at zio.Runtime$UnsafeAPIV1.run(Runtime.scala:132)
	at org.knora.webapi.routing.UnsafeZioRun$.$anonfun$runOrThrow$1(UnsafeZioRun.scala:32)
	at zio.Unsafe$.unsafe(Unsafe.scala:37)
	at org.knora.webapi.routing.UnsafeZioRun$.runOrThrow(UnsafeZioRun.scala:32)
	at org.knora.webapi.responders.v2.SearchResponderV2Spec.$anonfun$new$11(SearchResponderV2Spec.scala:169)
	at org.scalatest.OutcomeOf.outcomeOf(OutcomeOf.scala:85)
	at org.scalatest.OutcomeOf.outcomeOf$(OutcomeOf.scala:83)
	at org.scalatest.OutcomeOf$.outcomeOf(OutcomeOf.scala:104)
	at org.scalatest.Transformer.apply(Transformer.scala:22)
	at org.scalatest.Transformer.apply(Transformer.scala:20)
	at org.scalatest.wordspec.AnyWordSpecLike$$anon$3.apply(AnyWordSpecLike.scala:1240)
	at org.scalatest.TestSuite.withFixture(TestSuite.scala:196)
	at org.scalatest.TestSuite.withFixture$(TestSuite.scala:195)
	at org.scalatest.wordspec.AnyWordSpec.withFixture(AnyWordSpec.scala:1880)
	at org.scalatest.wordspec.AnyWordSpecLike.invokeWithFixture$1(AnyWordSpecLike.scala:1238)
	at org.scalatest.wordspec.AnyWordSpecLike.$anonfun$runTest$1(AnyWordSpecLike.scala:1250)
	at org.scalatest.SuperEngine.runTestImpl(Engine.scala:306)
	at org.scalatest.wordspec.AnyWordSpecLike.runTest(AnyWordSpecLike.scala:1250)
	at org.scalatest.wordspec.AnyWordSpecLike.runTest$(AnyWordSpecLike.scala:1232)
	at org.scalatest.wordspec.AnyWordSpec.runTest(AnyWordSpec.scala:1880)
	at org.scalatest.wordspec.AnyWordSpecLike.$anonfun$runTests$1(AnyWordSpecLike.scala:1309)
	at org.scalatest.SuperEngine.$anonfun$runTestsInBranch$1(Engine.scala:413)
	at scala.collection.immutable.List.foreach(List.scala:333)
	at org.scalatest.SuperEngine.traverseSubNodes$1(Engine.scala:401)
	at org.scalatest.SuperEngine.runTestsInBranch(Engine.scala:390)
	at org.scalatest.SuperEngine.$anonfun$runTestsInBranch$1(Engine.scala:427)
	at scala.collection.immutable.List.foreach(List.scala:333)
	at org.scalatest.SuperEngine.traverseSubNodes$1(Engine.scala:401)
	at org.scalatest.SuperEngine.runTestsInBranch(Engine.scala:396)
	at org.scalatest.SuperEngine.runTestsImpl(Engine.scala:475)
	at org.scalatest.wordspec.AnyWordSpecLike.runTests(AnyWordSpecLike.scala:1309)
	at org.scalatest.wordspec.AnyWordSpecLike.runTests$(AnyWordSpecLike.scala:1308)
	at org.scalatest.wordspec.AnyWordSpec.runTests(AnyWordSpec.scala:1880)
	at org.scalatest.Suite.run(Suite.scala:1114)
	at org.scalatest.Suite.run$(Suite.scala:1096)
	at org.scalatest.wordspec.AnyWordSpec.org$scalatest$wordspec$AnyWordSpecLike$$super$run(AnyWordSpec.scala:1880)
	at org.scalatest.wordspec.AnyWordSpecLike.$anonfun$run$1(AnyWordSpecLike.scala:1354)
	at org.scalatest.SuperEngine.runImpl(Engine.scala:535)
	at org.scalatest.wordspec.AnyWordSpecLike.run(AnyWordSpecLike.scala:1354)
	at org.scalatest.wordspec.AnyWordSpecLike.run$(AnyWordSpecLike.scala:1352)
	at org.knora.webapi.CoreSpec.org$scalatest$BeforeAndAfterAll$$super$run(CoreSpec.scala:32)
	at org.scalatest.BeforeAndAfterAll.liftedTree1$1(BeforeAndAfterAll.scala:213)
	at org.scalatest.BeforeAndAfterAll.run(BeforeAndAfterAll.scala:210)
	at org.scalatest.BeforeAndAfterAll.run$(BeforeAndAfterAll.scala:208)
	at org.knora.webapi.CoreSpec.run(CoreSpec.scala:32)
	at org.scalatest.tools.Framework.org$scalatest$tools$Framework$$runSuite(Framework.scala:321)
	at org.scalatest.tools.Framework$ScalaTestTask.execute(Framework.scala:517)
	at sbt.ForkMain$Run.lambda$runTest$1(ForkMain.java:414)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
	at java.base/java.lang.Thread.run(Thread.java:1583)

Check failure on line 890 in webapi/src/main/scala/org/knora/webapi/responders/v2/SearchResponderV2.scala

View workflow job for this annotation

GitHub Actions / WebApi Integration Test Results

org.knora.webapi.responders.v2.SearchResponderV2Spec ► The search responder v2 should perform a count search query by label for incunabula:book that contain 'Narrenschiff'

Failed test found in: ./integration/target/test-reports/TEST-org.knora.webapi.responders.v2.SearchResponderV2Spec.xml Error: sbt.ForkMain$ForkError: zio.FiberFailure: Resource class IRI <http://www.knora.org/ontology/0803/incunabula#book> is not a valid Knora API v2 entity IRI
Raw output
sbt.ForkMain$ForkError: zio.FiberFailure: Resource class IRI <http://www.knora.org/ontology/0803/incunabula#book> is not a valid Knora API v2 entity IRI
	at org.knora.webapi.responders.v2.SearchResponderV2Live.$anonfun$ensureResourceClassIri$2(SearchResponderV2.scala:890)
	at zio.ZIO$.$anonfun$fail$1(ZIO.scala:3151)
	at zio.ZIO$.$anonfun$failCause$3(ZIO.scala:3160)
	at org.knora.webapi.responders.v2.SearchResponderV2Live.ensureResourceClassIri(SearchResponderV2.scala:890)
	at org.knora.webapi.responders.v2.SearchResponderV2Live.searchResourcesByLabelCountV2(SearchResponderV2.scala:868)
	at org.knora.webapi.routing.UnsafeZioRun.runOrThrow(UnsafeZioRun.scala:32)
Caused by: sbt.ForkMain$ForkError: dsp.errors.BadRequestException: Resource class IRI <http://www.knora.org/ontology/0803/incunabula#book> is not a valid Knora API v2 entity IRI
	at org.knora.webapi.responders.v2.SearchResponderV2Live.$anonfun$ensureResourceClassIri$2(SearchResponderV2.scala:890)
	at zio.ZIO$.$anonfun$fail$1(ZIO.scala:3151)
	at zio.ZIO$.$anonfun$failCause$3(ZIO.scala:3160)
	at zio.internal.FiberRuntime.runLoop(FiberRuntime.scala:890)
	at zio.internal.FiberRuntime.evaluateEffect(FiberRuntime.scala:381)
	at zio.internal.FiberRuntime.start(FiberRuntime.scala:1339)
	at zio.Runtime$UnsafeAPIV1.runOrFork(Runtime.scala:160)
	at zio.Runtime$UnsafeAPIV1.run(Runtime.scala:132)
	at org.knora.webapi.routing.UnsafeZioRun$.$anonfun$runOrThrow$1(UnsafeZioRun.scala:32)
	at zio.Unsafe$.unsafe(Unsafe.scala:37)
	at org.knora.webapi.routing.UnsafeZioRun$.runOrThrow(UnsafeZioRun.scala:32)
	at org.knora.webapi.responders.v2.SearchResponderV2Spec.$anonfun$new$12(SearchResponderV2Spec.scala:185)
	at org.scalatest.OutcomeOf.outcomeOf(OutcomeOf.scala:85)
	at org.scalatest.OutcomeOf.outcomeOf$(OutcomeOf.scala:83)
	at org.scalatest.OutcomeOf$.outcomeOf(OutcomeOf.scala:104)
	at org.scalatest.Transformer.apply(Transformer.scala:22)
	at org.scalatest.Transformer.apply(Transformer.scala:20)
	at org.scalatest.wordspec.AnyWordSpecLike$$anon$3.apply(AnyWordSpecLike.scala:1240)
	at org.scalatest.TestSuite.withFixture(TestSuite.scala:196)
	at org.scalatest.TestSuite.withFixture$(TestSuite.scala:195)
	at org.scalatest.wordspec.AnyWordSpec.withFixture(AnyWordSpec.scala:1880)
	at org.scalatest.wordspec.AnyWordSpecLike.invokeWithFixture$1(AnyWordSpecLike.scala:1238)
	at org.scalatest.wordspec.AnyWordSpecLike.$anonfun$runTest$1(AnyWordSpecLike.scala:1250)
	at org.scalatest.SuperEngine.runTestImpl(Engine.scala:306)
	at org.scalatest.wordspec.AnyWordSpecLike.runTest(AnyWordSpecLike.scala:1250)
	at org.scalatest.wordspec.AnyWordSpecLike.runTest$(AnyWordSpecLike.scala:1232)
	at org.scalatest.wordspec.AnyWordSpec.runTest(AnyWordSpec.scala:1880)
	at org.scalatest.wordspec.AnyWordSpecLike.$anonfun$runTests$1(AnyWordSpecLike.scala:1309)
	at org.scalatest.SuperEngine.$anonfun$runTestsInBranch$1(Engine.scala:413)
	at scala.collection.immutable.List.foreach(List.scala:333)
	at org.scalatest.SuperEngine.traverseSubNodes$1(Engine.scala:401)
	at org.scalatest.SuperEngine.runTestsInBranch(Engine.scala:390)
	at org.scalatest.SuperEngine.$anonfun$runTestsInBranch$1(Engine.scala:427)
	at scala.collection.immutable.List.foreach(List.scala:333)
	at org.scalatest.SuperEngine.traverseSubNodes$1(Engine.scala:401)
	at org.scalatest.SuperEngine.runTestsInBranch(Engine.scala:396)
	at org.scalatest.SuperEngine.runTestsImpl(Engine.scala:475)
	at org.scalatest.wordspec.AnyWordSpecLike.runTests(AnyWordSpecLike.scala:1309)
	at org.scalatest.wordspec.AnyWordSpecLike.runTests$(AnyWordSpecLike.scala:1308)
	at org.scalatest.wordspec.AnyWordSpec.runTests(AnyWordSpec.scala:1880)
	at org.scalatest.Suite.run(Suite.scala:1114)
	at org.scalatest.Suite.run$(Suite.scala:1096)
	at org.scalatest.wordspec.AnyWordSpec.org$scalatest$wordspec$AnyWordSpecLike$$super$run(AnyWordSpec.scala:1880)
	at org.scalatest.wordspec.AnyWordSpecLike.$anonfun$run$1(AnyWordSpecLike.scala:1354)
	at org.scalatest.SuperEngine.runImpl(Engine.scala:535)
	at org.scalatest.wordspec.AnyWordSpecLike.run(AnyWordSpecLike.scala:1354)
	at org.scalatest.wordspec.AnyWordSpecLike.run$(AnyWordSpecLike.scala:1352)
	at org.knora.webapi.CoreSpec.org$scalatest$BeforeAndAfterAll$$super$run(CoreSpec.scala:32)
	at org.scalatest.BeforeAndAfterAll.liftedTree1$1(BeforeAndAfterAll.scala:213)
	at org.scalatest.BeforeAndAfterAll.run(BeforeAndAfterAll.scala:210)
	at org.scalatest.BeforeAndAfterAll.run$(BeforeAndAfterAll.scala:208)
	at org.knora.webapi.CoreSpec.run(CoreSpec.scala:32)
	at org.scalatest.tools.Framework.org$scalatest$tools$Framework$$runSuite(Framework.scala:321)
	at org.scalatest.tools.Framework$ScalaTestTask.execute(Framework.scala:517)
	at sbt.ForkMain$Run.lambda$runTest$1(ForkMain.java:414)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
	at java.base/java.lang.Thread.run(Thread.java:1583)

Check failure on line 890 in webapi/src/main/scala/org/knora/webapi/responders/v2/SearchResponderV2.scala

View workflow job for this annotation

GitHub Actions / WebApi Integration Test Results

org.knora.webapi.responders.v2.SearchResponderV2Spec ► The search responder v2 should perform a a count search query by label for incunabula:book that contain 'Passio sancti Meynrhadi martyris et heremite'

Failed test found in: ./integration/target/test-reports/TEST-org.knora.webapi.responders.v2.SearchResponderV2Spec.xml Error: sbt.ForkMain$ForkError: zio.FiberFailure: Resource class IRI <http://www.knora.org/ontology/0803/incunabula#book> is not a valid Knora API v2 entity IRI
Raw output
sbt.ForkMain$ForkError: zio.FiberFailure: Resource class IRI <http://www.knora.org/ontology/0803/incunabula#book> is not a valid Knora API v2 entity IRI
	at org.knora.webapi.responders.v2.SearchResponderV2Live.$anonfun$ensureResourceClassIri$2(SearchResponderV2.scala:890)
	at zio.ZIO$.$anonfun$fail$1(ZIO.scala:3151)
	at zio.ZIO$.$anonfun$failCause$3(ZIO.scala:3160)
	at org.knora.webapi.responders.v2.SearchResponderV2Live.ensureResourceClassIri(SearchResponderV2.scala:890)
	at org.knora.webapi.responders.v2.SearchResponderV2Live.searchResourcesByLabelCountV2(SearchResponderV2.scala:868)
	at org.knora.webapi.routing.UnsafeZioRun.runOrThrow(UnsafeZioRun.scala:32)
Caused by: sbt.ForkMain$ForkError: dsp.errors.BadRequestException: Resource class IRI <http://www.knora.org/ontology/0803/incunabula#book> is not a valid Knora API v2 entity IRI
	at org.knora.webapi.responders.v2.SearchResponderV2Live.$anonfun$ensureResourceClassIri$2(SearchResponderV2.scala:890)
	at zio.ZIO$.$anonfun$fail$1(ZIO.scala:3151)
	at zio.ZIO$.$anonfun$failCause$3(ZIO.scala:3160)
	at zio.internal.FiberRuntime.runLoop(FiberRuntime.scala:890)
	at zio.internal.FiberRuntime.evaluateEffect(FiberRuntime.scala:381)
	at zio.internal.FiberRuntime.start(FiberRuntime.scala:1339)
	at zio.Runtime$UnsafeAPIV1.runOrFork(Runtime.scala:160)
	at zio.Runtime$UnsafeAPIV1.run(Runtime.scala:132)
	at org.knora.webapi.routing.UnsafeZioRun$.$anonfun$runOrThrow$1(UnsafeZioRun.scala:32)
	at zio.Unsafe$.unsafe(Unsafe.scala:37)
	at org.knora.webapi.routing.UnsafeZioRun$.runOrThrow(UnsafeZioRun.scala:32)
	at org.knora.webapi.responders.v2.SearchResponderV2Spec.$anonfun$new$13(SearchResponderV2Spec.scala:199)
	at org.scalatest.OutcomeOf.outcomeOf(OutcomeOf.scala:85)
	at org.scalatest.OutcomeOf.outcomeOf$(OutcomeOf.scala:83)
	at org.scalatest.OutcomeOf$.outcomeOf(OutcomeOf.scala:104)
	at org.scalatest.Transformer.apply(Transformer.scala:22)
	at org.scalatest.Transformer.apply(Transformer.scala:20)
	at org.scalatest.wordspec.AnyWordSpecLike$$anon$3.apply(AnyWordSpecLike.scala:1240)
	at org.scalatest.TestSuite.withFixture(TestSuite.scala:196)
	at org.scalatest.TestSuite.withFixture$(TestSuite.scala:195)
	at org.scalatest.wordspec.AnyWordSpec.withFixture(AnyWordSpec.scala:1880)
	at org.scalatest.wordspec.AnyWordSpecLike.invokeWithFixture$1(AnyWordSpecLike.scala:1238)
	at org.scalatest.wordspec.AnyWordSpecLike.$anonfun$runTest$1(AnyWordSpecLike.scala:1250)
	at org.scalatest.SuperEngine.runTestImpl(Engine.scala:306)
	at org.scalatest.wordspec.AnyWordSpecLike.runTest(AnyWordSpecLike.scala:1250)
	at org.scalatest.wordspec.AnyWordSpecLike.runTest$(AnyWordSpecLike.scala:1232)
	at org.scalatest.wordspec.AnyWordSpec.runTest(AnyWordSpec.scala:1880)
	at org.scalatest.wordspec.AnyWordSpecLike.$anonfun$runTests$1(AnyWordSpecLike.scala:1309)
	at org.scalatest.SuperEngine.$anonfun$runTestsInBranch$1(Engine.scala:413)
	at scala.collection.immutable.List.foreach(List.scala:333)
	at org.scalatest.SuperEngine.traverseSubNodes$1(Engine.scala:401)
	at org.scalatest.SuperEngine.runTestsInBranch(Engine.scala:390)
	at org.scalatest.SuperEngine.$anonfun$runTestsInBranch$1(Engine.scala:427)
	at scala.collection.immutable.List.foreach(List.scala:333)
	at org.scalatest.SuperEngine.traverseSubNodes$1(Engine.scala:401)
	at org.scalatest.SuperEngine.runTestsInBranch(Engine.scala:396)
	at org.scalatest.SuperEngine.runTestsImpl(Engine.scala:475)
	at org.scalatest.wordspec.AnyWordSpecLike.runTests(AnyWordSpecLike.scala:1309)
	at org.scalatest.wordspec.AnyWordSpecLike.runTests$(AnyWordSpecLike.scala:1308)
	at org.scalatest.wordspec.AnyWordSpec.runTests(AnyWordSpec.scala:1880)
	at org.scalatest.Suite.run(Suite.scala:1114)
	at org.scalatest.Suite.run$(Suite.scala:1096)
	at org.scalatest.wordspec.AnyWordSpec.org$scalatest$wordspec$AnyWordSpecLike$$super$run(AnyWordSpec.scala:1880)
	at org.scalatest.wordspec.AnyWordSpecLike.$anonfun$run$1(AnyWordSpecLike.scala:1354)
	at org.scalatest.SuperEngine.runImpl(Engine.scala:535)
	at org.scalatest.wordspec.AnyWordSpecLike.run(AnyWordSpecLike.scala:1354)
	at org.scalatest.wordspec.AnyWordSpecLike.run$(AnyWordSpecLike.scala:1352)
	at org.knora.webapi.CoreSpec.org$scalatest$BeforeAndAfterAll$$super$run(CoreSpec.scala:32)
	at org.scalatest.BeforeAndAfterAll.liftedTree1$1(BeforeAndAfterAll.scala:213)
	at org.scalatest.BeforeAndAfterAll.run(BeforeAndAfterAll.scala:210)
	at org.scalatest.BeforeAndAfterAll.run$(BeforeAndAfterAll.scala:208)
	at org.knora.webapi.CoreSpec.run(CoreSpec.scala:32)
	at org.scalatest.tools.Framework.org$scalatest$tools$Framework$$runSuite(Framework.scala:321)
	at org.scalatest.tools.Framework$ScalaTestTask.execute(Framework.scala:517)
	at sbt.ForkMain$Run.lambda$runTest$1(ForkMain.java:414)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
	at java.base/java.lang.Thread.run(Thread.java:1583)

Check warning on line 890 in webapi/src/main/scala/org/knora/webapi/responders/v2/SearchResponderV2.scala

View check run for this annotation

Codecov / codecov/patch

webapi/src/main/scala/org/knora/webapi/responders/v2/SearchResponderV2.scala#L888-L890

Added lines #L888 - L890 were not covered by tests
}

private def ensureIsNotFullTextSearch(searchStr: String) =
private def ensureStandoffClass(standoffClassIri: SmartIri): Task[SmartIri] = {
val errMsg = s"Invalid standoff class IRI: $standoffClassIri"
if (standoffClassIri.isApiV2ComplexSchema) {
iriConverter.asInternalSmartIri(standoffClassIri).orElseFail(BadRequestException(errMsg))
} else { ZIO.fail(BadRequestException(errMsg)) }

Check warning on line 897 in webapi/src/main/scala/org/knora/webapi/responders/v2/SearchResponderV2.scala

View check run for this annotation

Codecov / codecov/patch

webapi/src/main/scala/org/knora/webapi/responders/v2/SearchResponderV2.scala#L895-L897

Added lines #L895 - L897 were not covered by tests
}

private def ensureIsFulltextSearch(searchStr: String) =
ZIO
.fail(BadRequestException("It looks like you are submitting a Gravsearch request to a full-text search route"))
.when(searchStr.contains(OntologyConstants.KnoraApi.ApiOntologyHostname))

Check warning on line 903 in webapi/src/main/scala/org/knora/webapi/responders/v2/SearchResponderV2.scala

View check run for this annotation

Codecov / codecov/patch

webapi/src/main/scala/org/knora/webapi/responders/v2/SearchResponderV2.scala#L902-L903

Added lines #L902 - L903 were not covered by tests
Expand Down Expand Up @@ -911,7 +926,7 @@ final case class SearchResponderV2Live(
val searchOffset = offset * appConfig.v2.resourcesSequence.resultsPerPage
for {
searchValue <- validateSearchString(searchValue)
_ <- ensureIsNotFullTextSearch(searchValue)
_ <- ensureIsFulltextSearch(searchValue)
limitToResourceClass <- ZIO.foreach(limitToResourceClass)(ensureResourceClassIri)
searchTerm = MatchStringWhileTyping(searchValue).generateLiteralForLuceneIndexWithoutExactSequence
searchResourceByLabelSparql = SearchQueries.constructSearchByLabel(

Check warning on line 932 in webapi/src/main/scala/org/knora/webapi/responders/v2/SearchResponderV2.scala

View check run for this annotation

Codecov / codecov/patch

webapi/src/main/scala/org/knora/webapi/responders/v2/SearchResponderV2.scala#L928-L932

Added lines #L928 - L932 were not covered by tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ private final case class ApiRoutesImpl(
PermissionsRouteADM(routeData, runtime).makeRoute ~
RejectingRoute(appConfig, runtime).makeRoute ~
ResourcesRouteV2(appConfig).makeRoute ~
SearchRouteV2(appConfig.v2.fulltextSearch.searchValueMinLength).makeRoute ~
StandoffRouteV2().makeRoute ~
StoreRouteADM(routeData, runtime).makeRoute ~
UsersRouteADM().makeRoute ~
Expand Down
182 changes: 0 additions & 182 deletions webapi/src/main/scala/org/knora/webapi/routing/v2/SearchRouteV2.scala

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ package org.knora.webapi.slice.admin.domain.model

import sttp.tapir.Codec
import sttp.tapir.CodecFormat
import sttp.tapir.DecodeResult
import sttp.tapir.Schema
import zio.NonEmptyChunk
import zio.json.*
import zio.prelude.Validation

import scala.util.matching.Regex

import dsp.errors.BadRequestException
import dsp.errors.ValidationException
import dsp.valueobjects.Iri
import dsp.valueobjects.Iri.isProjectIri
Expand Down Expand Up @@ -47,11 +45,8 @@ object KnoraProject {
implicit val codec: JsonCodec[ProjectIri] =
JsonCodec[String].transformOrFail(ProjectIri.from(_).toEitherWith(e => e.head.getMessage), _.value)

implicit val tapirCodec: Codec[String, ProjectIri, CodecFormat.TextPlain] = Codec.string.mapDecode(str =>
ProjectIri
.from(str)
.fold(f => DecodeResult.Error(f.head.getMessage, BadRequestException(f.head.getMessage)), DecodeResult.Value(_))
)(_.value)
implicit val tapirCodec: Codec[String, ProjectIri, CodecFormat.TextPlain] =
Codec.string.mapEither(str => ProjectIri.from(str).toEitherWith(e => e.head.getMessage))(_.value)

def unsafeFrom(str: String): ProjectIri = from(str).fold(e => throw e.head, identity)

Expand Down
Loading

0 comments on commit 3f86148

Please sign in to comment.