Skip to content

Commit

Permalink
Add route for getting information for resources /v2/resources/info
Browse files Browse the repository at this point in the history
includes orderBy [creationDate|lastmodficationDate], and order [ASC|DESC].

Http Example request:

GET /v2/resources/info?resourceClass=http%3A%2F%2F0.0.0.0%3A3333%2Fontology%2F0001%2Fanything%2Fv2%23Thing&order=DESC&orderBy=creationDate HTTP/1.1
X-Knora-Accept-Project: http://rdfh.ch/projects/Lw3FC39BSzCwvmdOaTyLqQ

Http Example response:
{
	"resources": [
		{
			"resourceIri": "http://rdfh.ch/0001/thing-with-pages",
			"creationDate": "2021-05-11T10:00:00Z",
			"lastModificationDate": "2021-05-11T10:00:00Z",
			"isDeleted": false
		},
		{
			"resourceIri": "http://rdfh.ch/0001/0JhgKcqoRIeRRG6ownArSw",
			"creationDate": "2020-04-07T09:12:56.710717Z",
			"lastModificationDate": "2020-04-07T09:12:56.710717Z",
			"isDeleted": false
		},
		...
	]
}
  • Loading branch information
seakayone committed Dec 15, 2022
1 parent b06f5b4 commit c59ce47
Show file tree
Hide file tree
Showing 34 changed files with 1,068 additions and 75 deletions.
32 changes: 27 additions & 5 deletions webapi/src/it/scala/org/knora/webapi/core/LayersTest.scala
@@ -1,20 +1,22 @@
package org.knora.webapi.core

import zio.ZLayer
import org.knora.webapi.auth.JWTService
import org.knora.webapi.config.AppConfigForTestContainers
import org.knora.webapi.messages.StringFormatter
import org.knora.webapi.routing.ApiRoutes
import org.knora.webapi.slice.resourceinfo.api.LiveRestResourceInfoService
import org.knora.webapi.slice.resourceinfo.domain.IriConverter
import org.knora.webapi.slice.resourceinfo.repo.LiveResourceInfoRepo
import org.knora.webapi.store.cache.CacheServiceManager
import org.knora.webapi.store.cache.impl.CacheServiceInMemImpl
import org.knora.webapi.store.iiif.IIIFServiceManager
import org.knora.webapi.store.iiif.impl.IIIFServiceMockImpl
import org.knora.webapi.store.iiif.impl.IIIFServiceSipiImpl
import org.knora.webapi.store.iiif.impl.{IIIFServiceMockImpl, IIIFServiceSipiImpl}
import org.knora.webapi.store.triplestore.TriplestoreServiceManager
import org.knora.webapi.store.triplestore.impl.TriplestoreServiceHttpConnectorImpl
import org.knora.webapi.store.triplestore.upgrade.RepositoryUpdater
import org.knora.webapi.testcontainers.FusekiTestContainer
import org.knora.webapi.testcontainers.SipiTestContainer
import org.knora.webapi.testcontainers.{FusekiTestContainer, SipiTestContainer}
import org.knora.webapi.testservices.TestClientService
import zio.ZLayer

object LayersTest {

Expand Down Expand Up @@ -43,6 +45,10 @@ object LayersTest {
State.layer,
TriplestoreServiceManager.layer,
TriplestoreServiceHttpConnectorImpl.layer,
LiveRestResourceInfoService.layer,
LiveResourceInfoRepo.layer,
IriConverter.layer,
StringFormatter.testLayer,
// testcontainers
SipiTestContainer.layer,
FusekiTestContainer.layer,
Expand All @@ -69,6 +75,10 @@ object LayersTest {
State.layer,
TriplestoreServiceManager.layer,
TriplestoreServiceHttpConnectorImpl.layer,
LiveRestResourceInfoService.layer,
LiveResourceInfoRepo.layer,
IriConverter.layer,
StringFormatter.testLayer,
// testcontainers
FusekiTestContainer.layer,
// Test services
Expand All @@ -94,6 +104,10 @@ object LayersTest {
State.layer,
TriplestoreServiceManager.layer,
TriplestoreServiceHttpConnectorImpl.layer,
LiveRestResourceInfoService.layer,
LiveResourceInfoRepo.layer,
IriConverter.layer,
StringFormatter.testLayer,
// testcontainers
FusekiTestContainer.layer,
// Test services
Expand All @@ -119,6 +133,10 @@ object LayersTest {
State.layer,
TriplestoreServiceManager.layer,
TriplestoreServiceHttpConnectorImpl.layer,
LiveRestResourceInfoService.layer,
LiveResourceInfoRepo.layer,
IriConverter.layer,
StringFormatter.testLayer,
// testcontainers
FusekiTestContainer.layer,
// Test services
Expand All @@ -144,6 +162,10 @@ object LayersTest {
State.layer,
TriplestoreServiceManager.layer,
TriplestoreServiceHttpConnectorImpl.layer,
LiveRestResourceInfoService.layer,
LiveResourceInfoRepo.layer,
IriConverter.layer,
StringFormatter.testLayer,
// testcontainers
FusekiTestContainer.layer,
// Test services
Expand Down
Expand Up @@ -58,7 +58,7 @@ class ResourcesV1R2RSpec extends R2RSpec {
private val resourcesPathV1 =
DSPApiDirectives.handleErrors(system, appConfig)(new ResourcesRouteV1(routeData).makeRoute)
private val resourcesPathV2 =
DSPApiDirectives.handleErrors(system, appConfig)(new ResourcesRouteV2(routeData).makeRoute)
DSPApiDirectives.handleErrors(system, appConfig)(new ResourcesRouteV2(routeData, null).makeRoute)
private val valuesPathV1 =
DSPApiDirectives.handleErrors(system, appConfig)(new ValuesRouteV1(routeData).makeRoute)

Expand Down
Expand Up @@ -25,7 +25,7 @@ import org.knora.webapi.routing.v2.ResourcesRouteV2
*/
class JSONLDHandlingV2R2RSpec extends R2RSpec {

private val resourcesPath = new ResourcesRouteV2(routeData).makeRoute
private val resourcesPath = new ResourcesRouteV2(routeData, null).makeRoute

implicit def default(implicit system: ActorSystem): RouteTestTimeout = RouteTestTimeout(
appConfig.defaultTimeoutAsDuration
Expand Down
Expand Up @@ -66,7 +66,7 @@ class OntologyV2R2RSpec extends R2RSpec {
private val ontologiesPath =
DSPApiDirectives.handleErrors(system, appConfig)(new OntologiesRouteV2(routeData).makeRoute)
private val resourcesPath =
DSPApiDirectives.handleErrors(system, appConfig)(new ResourcesRouteV2(routeData).makeRoute)
DSPApiDirectives.handleErrors(system, appConfig)(new ResourcesRouteV2(routeData, null).makeRoute)

implicit def default(implicit system: ActorSystem): RouteTestTimeout = RouteTestTimeout(
appConfig.defaultTimeoutAsDuration
Expand Down
Expand Up @@ -54,7 +54,7 @@ class SearchRouteV2R2RSpec extends R2RSpec {
private val searchPath =
DSPApiDirectives.handleErrors(system, appConfig)(new SearchRouteV2(routeData).makeRoute)
private val resourcePath =
DSPApiDirectives.handleErrors(system, appConfig)(new ResourcesRouteV2(routeData).makeRoute)
DSPApiDirectives.handleErrors(system, appConfig)(new ResourcesRouteV2(routeData, null).makeRoute)
private val standoffPath =
DSPApiDirectives.handleErrors(system, appConfig)(new StandoffRouteV2(routeData).makeRoute)
private val valuesPath =
Expand Down
@@ -0,0 +1,22 @@
package org.knora.webapi.slice.resourceinfo.api

import org.knora.webapi.messages.StringFormatter
import org.knora.webapi.slice.resourceinfo.domain
import org.knora.webapi.slice.resourceinfo.domain.{InternalIri, IriConverter}
import zio.test._

object LiveIriConverterSpec extends ZIOSpecDefault {

def spec = suite("IriConverter")(
test("should not convert the projectIri") {
for {
internal <- IriConverter.asInternalIri("http://project-iri")
} yield assertTrue(internal == domain.InternalIri("http://project-iri"))
},
test("should convert a resourceClassIri") {
for {
internal <- IriConverter.asInternalIri("http://0.0.0.0:3333/ontology/0001/anything/v2#Thing")
} yield assertTrue(internal == InternalIri("http://www.knora.org/ontology/0001/anything#Thing"))
}
).provide(IriConverter.layer, StringFormatter.testLayer)
}
Expand Up @@ -10,7 +10,9 @@ import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpecLike

import java.io.BufferedInputStream
import java.io.ByteArrayInputStream
import java.io.FileInputStream
import scala.util.Using

import org.knora.webapi.messages.util.ErrorHandlingMap
import org.knora.webapi.messages.util.rdf._
Expand All @@ -37,6 +39,15 @@ abstract class UpgradePluginSpec extends AnyWordSpecLike with Matchers {
rdfModel
}

/**
* Parses a TriG String and returns it as an [[RdfModel]].
*
* @param s the [[String]] content of a "TriG file".
* @return an [[RdfModel]].
*/
def stringToModel(s: String): RdfModel =
Using(new ByteArrayInputStream(s.getBytes))(rdfFormatUtil.inputStreamToRdfModel(_, TriG)).get

/**
* Wraps expected SPARQL SELECT results in a [[SparqlSelectResultBody]].
*
Expand Down
10 changes: 3 additions & 7 deletions webapi/src/main/scala/org/knora/webapi/config/AppConfig.scala
Expand Up @@ -8,6 +8,8 @@ package org.knora.webapi.config
import com.typesafe.config.ConfigFactory
import zio._
import zio.config._
import zio.config.magnolia._
import zio.config.typesafe._

import java.nio.file.Files
import java.nio.file.Path
Expand All @@ -19,13 +21,9 @@ import scala.util.Success
import scala.util.Try

import dsp.errors.FileWriteException
import org.knora.webapi.messages.StringFormatter
import org.knora.webapi.messages.util.rdf.RdfFeatureFactory
import org.knora.webapi.util.cache.CacheUtil

import typesafe._
import magnolia._

/**
* Represents the configuration as defined in application.conf.
*/
Expand Down Expand Up @@ -272,7 +270,6 @@ object AppConfig {
for {
c <- configFromSource.orDie
_ <- ZIO.attempt(RdfFeatureFactory.init(c)).orDie // needs early init before first usage
_ <- ZIO.attempt(StringFormatter.init(c)).orDie // needs early init before first usage
} yield c
}.tap(_ => ZIO.logInfo(">>> AppConfig Live Initialized <<<"))

Expand All @@ -283,8 +280,7 @@ object AppConfig {
ZLayer {
for {
c <- configFromSource.orDie
_ <- ZIO.attempt(RdfFeatureFactory.init(c)).orDie // needs early init before first usage
_ <- ZIO.attempt(StringFormatter.initForTest()).orDie // needs early init before first usage
_ <- ZIO.attempt(RdfFeatureFactory.init(c)).orDie // needs early init before first usage
} yield c
}.tap(_ => ZIO.logInfo(">>> AppConfig Test Initialized <<<"))

Expand Down
Expand Up @@ -5,25 +5,23 @@

package org.knora.webapi.core

import zhttp.service.Server
import zio.ZLayer
import zio._

import org.knora.webapi.config.AppConfig
import org.knora.webapi.routing.IndexApp
import org.knora.webapi.slice.resourceinfo.api.ResourceInfoRoute
import zhttp.service.Server
import zio.{ZIO, ZLayer}

object HttpServerWithZIOHttp {

val routes = IndexApp()

val layer: ZLayer[AppConfig & State, Nothing, Unit] =
val layer: ZLayer[ResourceInfoRoute with AppConfig, Nothing, Unit] =
ZLayer {
for {
appConfig <- ZIO.service[AppConfig]
riRoute <- ZIO.service[ResourceInfoRoute].map(_.route)
port = appConfig.knoraApi.externalZioPort
routes = IndexApp() ++ riRoute
_ <- Server.start(port, routes).forkDaemon
_ <- ZIO.logInfo(">>> Acquire ZIO HTTP Server <<<")
_ <- ZIO.logInfo(s">>> Acquire ZIO HTTP Server on port $port<<<")
} yield ()
}

}
@@ -1,3 +1,8 @@
/*
* 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 org.knora.webapi.core

import zhttp.service.Server
Expand Down
10 changes: 10 additions & 0 deletions webapi/src/main/scala/org/knora/webapi/core/LayersLive.scala
Expand Up @@ -10,7 +10,12 @@ import zio.ZLayer

import org.knora.webapi.auth.JWTService
import org.knora.webapi.config.AppConfig
import org.knora.webapi.messages.StringFormatter
import org.knora.webapi.routing.ApiRoutes
import org.knora.webapi.slice.resourceinfo.api.LiveRestResourceInfoService
import org.knora.webapi.slice.resourceinfo.api.ResourceInfoRoute
import org.knora.webapi.slice.resourceinfo.domain.IriConverter
import org.knora.webapi.slice.resourceinfo.repo.LiveResourceInfoRepo
import org.knora.webapi.store.cache.CacheServiceManager
import org.knora.webapi.store.cache.api.CacheService
import org.knora.webapi.store.cache.impl.CacheServiceInMemImpl
Expand Down Expand Up @@ -58,9 +63,14 @@ object LayersLive {
HttpServerWithZIOHttp.layer, // this is the new ZIO HTTP server layer
IIIFServiceManager.layer,
IIIFServiceSipiImpl.layer,
IriConverter.layer,
JWTService.layer,
LiveResourceInfoRepo.layer,
LiveRestResourceInfoService.layer,
RepositoryUpdater.layer,
ResourceInfoRoute.layer,
State.layer,
StringFormatter.liveLayer,
TriplestoreServiceManager.layer,
TriplestoreServiceHttpConnectorImpl.layer
)
Expand Down
@@ -1,3 +1,8 @@
/*
* 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 org.knora.webapi.instrumentation.index

import zhttp.html.Html
Expand Down
@@ -1,3 +1,8 @@
/*
* 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 org.knora.webapi.instrumentation.prometheus

import zhttp.http._
Expand Down
Expand Up @@ -13,6 +13,7 @@ import com.google.gwt.safehtml.shared.UriUtils._
import com.typesafe.scalalogging.Logger
import org.apache.commons.lang3.StringUtils
import spray.json._
import zio.ZLayer

import java.nio.ByteBuffer
import java.time._
Expand Down Expand Up @@ -311,6 +312,16 @@ object StringFormatter {
creationFun()
})
)

val liveLayer: ZLayer[AppConfig, Nothing, StringFormatter] = ZLayer.fromFunction { appConfig: AppConfig =>
StringFormatter.init(appConfig)
StringFormatter.getGeneralInstance
}

val testLayer: ZLayer[Any, Nothing, StringFormatter] = ZLayer.fromFunction { () =>
StringFormatter.initForTest()
StringFormatter.getGeneralInstance
}
}

/**
Expand Down Expand Up @@ -345,6 +356,8 @@ sealed trait SmartIri extends Ordered[SmartIri] with KnoraContentV2[SmartIri] {
*/
def toSparql: String

def toIri: IRI = toString

/**
* Returns `true` if this is a Knora data or definition IRI.
*/
Expand Down Expand Up @@ -485,6 +498,8 @@ sealed trait SmartIri extends Ordered[SmartIri] with KnoraContentV2[SmartIri] {
*/
override def toOntologySchema(targetSchema: OntologySchema): SmartIri

def internalIri: IRI = toOntologySchema(InternalSchema).toIri

/**
* Constructs a short prefix label for the ontology that the IRI belongs to.
*/
Expand Down

0 comments on commit c59ce47

Please sign in to comment.