Skip to content

Commit

Permalink
Merge branch 'main' into wip/markdownlint
Browse files Browse the repository at this point in the history
  • Loading branch information
jnussbaum authored Mar 19, 2024
2 parents 21d7187 + 30e4f06 commit 29b692c
Show file tree
Hide file tree
Showing 12 changed files with 171 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,27 @@

package org.knora.webapi.responders.v2

import zio.ZIO

import dsp.errors.BadRequestException
import org.knora.webapi.*
import org.knora.webapi.ApiV2Schema
import org.knora.webapi.SchemaRendering
import org.knora.webapi.SchemaRendering.apiV2SchemaWithOption
import org.knora.webapi.messages.IriConversions.*
import org.knora.webapi.messages.SmartIri
import org.knora.webapi.messages.StringFormatter
import org.knora.webapi.messages.store.triplestoremessages.RdfDataObject
import org.knora.webapi.messages.util.search.ConstructQuery
import org.knora.webapi.messages.v2.responder.resourcemessages.*
import org.knora.webapi.messages.v2.responder.valuemessages.ReadValueV2
import org.knora.webapi.messages.v2.responder.valuemessages.StillImageFileValueContentV2
import org.knora.webapi.responders.v2.ResourcesResponseCheckerV2.compareReadResourcesSequenceV2Response
import org.knora.webapi.routing.UnsafeZioRun
import org.knora.webapi.sharedtestdata.SharedTestDataADM
import org.knora.webapi.sharedtestdata.SharedTestDataADM.anonymousUser
import org.knora.webapi.slice.admin.domain.model.KnoraProject.ProjectIri
import org.knora.webapi.slice.admin.domain.model.User
import org.knora.webapi.slice.resourceinfo.domain.IriConverter
import org.knora.webapi.util.ZioScalaTestUtil.assertFailsWithA

Expand All @@ -41,12 +49,75 @@ class SearchResponderV2Spec extends CoreSpec {
)
private val searchResponderV2SpecFullData = new SearchResponderV2SpecFullData

// accessor methods
private def fulltextSearchV2(
searchValue: IRI,
offset: Int,
limitToProject: Option[ProjectIri],
limitToResourceClass: Option[SmartIri],
limitToStandoffClass: Option[SmartIri],
returnFiles: Boolean,
schemaAndOptions: SchemaRendering,
requestingUser: User,
) = ZIO.serviceWithZIO[SearchResponderV2](
_.fulltextSearchV2(
searchValue,
offset,
limitToProject,
limitToResourceClass,
limitToStandoffClass,
returnFiles,
schemaAndOptions,
requestingUser,
),
)

private def searchResourcesByLabelV2(
searchValue: String,
offset: Int,
limitToProject: Option[ProjectIri],
limitToResourceClass: Option[SmartIri],
targetSchema: ApiV2Schema,
requestingUser: User,
) = ZIO.serviceWithZIO[SearchResponderV2](
_.searchResourcesByLabelV2(searchValue, offset, limitToProject, limitToResourceClass, targetSchema, requestingUser),
)

private def searchResourcesByLabelCountV2(
searchValue: String,
limitToProject: Option[ProjectIri],
limitToResourceClass: Option[SmartIri],
) = ZIO.serviceWithZIO[SearchResponderV2](
_.searchResourcesByLabelCountV2(searchValue, limitToProject, limitToResourceClass),
)

private def gravsearchV2(query: ConstructQuery, schemaAndOptions: SchemaRendering, user: User) =
ZIO.serviceWithZIO[SearchResponderV2](_.gravsearchV2(query, schemaAndOptions, user))

private def searchResourcesByProjectAndClassV2(
projectIri: SmartIri,
resourceClass: SmartIri,
orderByProperty: Option[SmartIri],
page: Int,
schemaAndOptions: SchemaRendering,
requestingUser: User,
) = ZIO.serviceWithZIO[SearchResponderV2](
_.searchResourcesByProjectAndClassV2(
projectIri,
resourceClass,
orderByProperty,
page,
schemaAndOptions,
requestingUser,
),
)

"The search responder v2" should {

"perform a fulltext search for 'Narr'" in {

val result = UnsafeZioRun.runOrThrow(
SearchResponderV2.fulltextSearchV2(
fulltextSearchV2(
searchValue = "Narr",
offset = 0,
limitToProject = None,
Expand All @@ -63,7 +134,7 @@ class SearchResponderV2Spec extends CoreSpec {

"perform a fulltext search for 'Dinge'" in {
val result = UnsafeZioRun.runOrThrow(
SearchResponderV2.fulltextSearchV2(
fulltextSearchV2(
searchValue = "Dinge",
offset = 0,
limitToProject = None,
Expand All @@ -80,7 +151,7 @@ class SearchResponderV2Spec extends CoreSpec {

"return a Bad Request error if fulltext search input is invalid" in {
val result = UnsafeZioRun.run(
SearchResponderV2.fulltextSearchV2(
fulltextSearchV2(
searchValue = "qin(",
offset = 0,
limitToProject = None,
Expand All @@ -97,7 +168,7 @@ class SearchResponderV2Spec extends CoreSpec {
"return files attached to full-text search results" in {

val result: ReadResourcesSequenceV2 = UnsafeZioRun.runOrThrow(
SearchResponderV2.fulltextSearchV2(
fulltextSearchV2(
searchValue = "p7v",
offset = 0,
limitToProject = None,
Expand All @@ -124,7 +195,7 @@ class SearchResponderV2Spec extends CoreSpec {
"perform an extended search for books that have the title 'Zeitglöcklein des Lebens'" in {

val searchResult = UnsafeZioRun.runOrThrow(
SearchResponderV2.gravsearchV2(
gravsearchV2(
searchResponderV2SpecFullData.constructQueryForBooksWithTitleZeitgloecklein,
apiV2SchemaWithOption(MarkupRendering.Xml),
anonymousUser,
Expand All @@ -140,7 +211,7 @@ class SearchResponderV2Spec extends CoreSpec {

"perform an extended search for books that do not have the title 'Zeitglöcklein des Lebens'" in {
val searchResult = UnsafeZioRun.runOrThrow(
SearchResponderV2.gravsearchV2(
gravsearchV2(
searchResponderV2SpecFullData.constructQueryForBooksWithoutTitleZeitgloecklein,
apiV2SchemaWithOption(MarkupRendering.Xml),
anonymousUser,
Expand All @@ -158,7 +229,7 @@ class SearchResponderV2Spec extends CoreSpec {
.asSmartIri("http://www.knora.org/ontology/0803/incunabula#book")
.mapAttempt(_.toOntologySchema(ApiV2Complex))
.map(Some(_))
result <- SearchResponderV2.searchResourcesByLabelV2(
result <- searchResourcesByLabelV2(
searchValue = "Narrenschiff",
offset = 0,
limitToProject = None,
Expand All @@ -179,7 +250,7 @@ class SearchResponderV2Spec extends CoreSpec {
.asSmartIri("http://www.knora.org/ontology/0803/incunabula#book")
.mapAttempt(_.toOntologySchema(ApiV2Complex))
.map(Some(_))
result <- SearchResponderV2.searchResourcesByLabelV2(
result <- searchResourcesByLabelV2(
searchValue = "Narrenschiff",
offset = 0,
limitToProject = None,
Expand All @@ -201,7 +272,7 @@ class SearchResponderV2Spec extends CoreSpec {
.asSmartIri("http://www.knora.org/ontology/0803/incunabula#book")
.mapAttempt(_.toOntologySchema(ApiV2Complex))
.map(Some(_))
result <- SearchResponderV2.searchResourcesByLabelCountV2(
result <- searchResourcesByLabelCountV2(
searchValue = "Narrenschiff",
limitToProject = None,
limitToResourceClass,
Expand All @@ -221,7 +292,7 @@ class SearchResponderV2Spec extends CoreSpec {
.asSmartIri("http://www.knora.org/ontology/0803/incunabula#book")
.mapAttempt(_.toOntologySchema(ApiV2Complex))
.map(Some(_))
result <- SearchResponderV2.searchResourcesByLabelCountV2(
result <- searchResourcesByLabelCountV2(
searchValue = "Passio sancti Meynrhadi martyris et heremite",
limitToProject = None,
limitToResourceClass,
Expand All @@ -234,7 +305,7 @@ class SearchResponderV2Spec extends CoreSpec {

"search by project and resource class" in {
val result = UnsafeZioRun.runOrThrow(
SearchResponderV2.searchResourcesByProjectAndClassV2(
searchResourcesByProjectAndClassV2(
projectIri = SharedTestDataADM.incunabulaProject.id.toSmartIri,
resourceClass = "http://0.0.0.0:3333/ontology/0803/incunabula/v2#book".toSmartIri,
orderByProperty = Some("http://0.0.0.0:3333/ontology/0803/incunabula/v2#title".toSmartIri),
Expand All @@ -249,7 +320,7 @@ class SearchResponderV2Spec extends CoreSpec {
"search for list label" in {

val result = UnsafeZioRun.runOrThrow(
SearchResponderV2.fulltextSearchV2(
fulltextSearchV2(
searchValue = "non fiction",
offset = 0,
limitToProject = None,
Expand All @@ -269,7 +340,7 @@ class SearchResponderV2Spec extends CoreSpec {

"search for list label and find sub-nodes" in {
val result = UnsafeZioRun.runOrThrow(
SearchResponderV2.fulltextSearchV2(
fulltextSearchV2(
searchValue = "novel",
offset = 0,
limitToProject = None,
Expand All @@ -289,7 +360,7 @@ class SearchResponderV2Spec extends CoreSpec {

"perform an extended search for a particular compound object (book)" in {
val searchResult = UnsafeZioRun.runOrThrow(
SearchResponderV2.gravsearchV2(
gravsearchV2(
searchResponderV2SpecFullData.constructQueryForIncunabulaCompundObject,
apiV2SchemaWithOption(MarkupRendering.Xml),
anonymousUser,
Expand All @@ -300,17 +371,15 @@ class SearchResponderV2Spec extends CoreSpec {

"perform an extended search ordered asc by label" in {
val queryAsc = searchResponderV2SpecFullData.constructQuerySortByLabel
val ascResult = UnsafeZioRun.runOrThrow(
SearchResponderV2.gravsearchV2(queryAsc, apiV2SchemaWithOption(MarkupRendering.Xml), anonymousUser),
)
val ascResult =
UnsafeZioRun.runOrThrow(gravsearchV2(queryAsc, apiV2SchemaWithOption(MarkupRendering.Xml), anonymousUser))
assert(ascResult.resources.head.label == "A blue thing")
}

"perform an extended search ordered desc by label" in {
val queryDesc = searchResponderV2SpecFullData.constructQuerySortByLabelDesc
val descResult = UnsafeZioRun.runOrThrow(
SearchResponderV2.gravsearchV2(queryDesc, apiV2SchemaWithOption(MarkupRendering.Xml), anonymousUser),
)
val descResult =
UnsafeZioRun.runOrThrow(gravsearchV2(queryDesc, apiV2SchemaWithOption(MarkupRendering.Xml), anonymousUser))
assert(descResult.resources.head.label == "visible thing with hidden int values")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package org.knora.webapi.responders.v2

import org.apache.pekko.testkit.ImplicitSender
import org.scalatest.compatible.Assertion
import zio.ZIO

import java.time.Instant
import java.util.UUID
Expand Down Expand Up @@ -198,10 +199,12 @@ class ValuesResponderV2Spec extends CoreSpec with ImplicitSender {

// Run the query.
val result = UnsafeZioRun.runOrThrow(
SearchResponderV2.gravsearchV2(
GravsearchParser.parseQuery(gravsearchQuery),
SchemaRendering.apiV2SchemaWithOption(MarkupRendering.Xml),
requestingUser,
ZIO.serviceWithZIO[SearchResponderV2](
_.gravsearchV2(
GravsearchParser.parseQuery(gravsearchQuery),
SchemaRendering.apiV2SchemaWithOption(MarkupRendering.Xml),
requestingUser,
),
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package org.knora.webapi.responders.v2

import com.typesafe.scalalogging.LazyLogging
import zio.*
import zio.macros.accessible

import dsp.errors.AssertionException
import dsp.errors.BadRequestException
Expand Down Expand Up @@ -82,7 +81,7 @@ case class ResourceCountV2(numberOfResources: Int) extends KnoraJsonLDResponseV2
),
)
}
@accessible

trait SearchResponderV2 {

/**
Expand Down Expand Up @@ -151,7 +150,7 @@ trait SearchResponderV2 {
*/
def fulltextSearchV2(
searchValue: IRI,
offset: RuntimeFlags,
offset: Int,
limitToProject: Option[ProjectIri],
limitToResourceClass: Option[SmartIri],
limitToStandoffClass: Option[SmartIri],
Expand Down Expand Up @@ -187,7 +186,7 @@ trait SearchResponderV2 {
*/
def searchResourcesByLabelV2(
searchValue: String,
offset: RuntimeFlags,
offset: Int,
limitToProject: Option[ProjectIri],
limitToResourceClass: Option[SmartIri],
targetSchema: ApiV2Schema,
Expand All @@ -209,7 +208,7 @@ trait SearchResponderV2 {
projectIri: SmartIri,
resourceClass: SmartIri,
orderByProperty: Option[SmartIri],
page: RuntimeFlags,
page: Int,
schemaAndOptions: SchemaRendering,
requestingUser: User,
): Task[ReadResourcesSequenceV2]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.apache.pekko.http.scaladsl.server.Directives.*
import org.apache.pekko.http.scaladsl.server.PathMatcher
import org.apache.pekko.http.scaladsl.server.Route
import zio.*
import zio.ZIO

import java.time.Instant

Expand Down Expand Up @@ -181,13 +182,15 @@ final case class ResourcesRouteV2(appConfig: AppConfig)(
case (schema, options) => SchemaRendering(schema, options)
}
requestingUser <- Authenticator.getUserADM(requestContext)
response <- SearchResponderV2.searchResourcesByProjectAndClassV2(
projectIri,
resourceClass,
maybeOrderByProperty,
page,
targetSchema,
requestingUser,
response <- ZIO.serviceWithZIO[SearchResponderV2](
_.searchResourcesByProjectAndClassV2(
projectIri,
resourceClass,
maybeOrderByProperty,
page,
targetSchema,
requestingUser,
),
)
} yield response

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package org.knora.webapi.slice.ontology.domain.service

import zio.Task
import zio.macros.accessible

import org.knora.webapi.messages.v2.responder.ontologymessages.ReadClassInfoV2
import org.knora.webapi.messages.v2.responder.ontologymessages.ReadOntologyV2
Expand All @@ -15,7 +14,6 @@ import org.knora.webapi.slice.admin.domain.model.KnoraProject.ProjectIri
import org.knora.webapi.slice.common.repo.service.Repository
import org.knora.webapi.slice.resourceinfo.domain.InternalIri

@accessible
trait OntologyRepo extends Repository[ReadOntologyV2, InternalIri] {

override def findById(id: InternalIri): Task[Option[ReadOntologyV2]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import org.knora.webapi.slice.common.api.TapirToPekkoInterpreter
import org.knora.webapi.slice.resourceinfo.api.ResourceInfoEndpoints
import org.knora.webapi.slice.resourceinfo.api.ResourceInfoRoutes
import org.knora.webapi.slice.resourceinfo.api.service.RestResourceInfoService
import org.knora.webapi.slice.resourceinfo.api.service.RestResourceInfoServiceLive
import org.knora.webapi.slice.resourceinfo.domain.IriConverter
import org.knora.webapi.slice.resourceinfo.repo.ResourceInfoRepoLive
import org.knora.webapi.store.triplestore.api.TriplestoreService
Expand All @@ -25,6 +24,6 @@ object ResourceInfoLayers {
Nothing,
RestResourceInfoService & ResourceInfoEndpoints & ResourceInfoRoutes,
] =
ResourceInfoRepoLive.layer >>> RestResourceInfoServiceLive.layer >+> ResourceInfoEndpoints.layer >+> ResourceInfoRoutes.layer
ResourceInfoRepoLive.layer >>> RestResourceInfoService.layer >+> ResourceInfoEndpoints.layer >+> ResourceInfoRoutes.layer

}
Loading

0 comments on commit 29b692c

Please sign in to comment.