From 7ea9edec802fcc10773ffc35d6a7c6438af9d6c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Kleinbo=CC=88lting?= Date: Mon, 12 Dec 2022 21:27:04 +0100 Subject: [PATCH 01/33] mob next [ci-skip] [ci skip] [skip ci] lastFile:webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala --- .../knora/webapi/core/HttpServerWithZIOHttp.scala | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala index 3cf16f33e5..05c3082b95 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala @@ -5,16 +5,21 @@ 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.HealthRouteWithZIOHttp +import zhttp.http._ +import zhttp.service.Server +import zio.{ZLayer, _} +object HelloZio { + def apply(): HttpApp[State, Nothing] = + Http.collectZIO[Request] { case Method.GET -> !! / "hellozio" => + ZIO.succeed(Response.json("""{"hello":"zio"}""")) + } +} object HttpServerWithZIOHttp { - val routes = HealthRouteWithZIOHttp() + val routes = HealthRouteWithZIOHttp() ++ HelloZio() val layer: ZLayer[AppConfig & State, Nothing, Unit] = ZLayer { From e2603f2c5a7e3eaab11e870e9466c0128ddafd01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Kleinbo=CC=88lting?= Date: Mon, 12 Dec 2022 21:33:01 +0100 Subject: [PATCH 02/33] mob next [ci-skip] [ci skip] [skip ci] lastFile:webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala --- .../knora/webapi/core/HttpServerWithZIOHttp.scala | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala index 05c3082b95..c1316474a7 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala @@ -9,17 +9,25 @@ import org.knora.webapi.config.AppConfig import org.knora.webapi.routing.HealthRouteWithZIOHttp import zhttp.http._ import zhttp.service.Server +import zio.json.{DeriveJsonEncoder, EncoderOps} import zio.{ZLayer, _} +case class HelloZio(hello: String) + object HelloZio { + implicit val encoder = DeriveJsonEncoder.gen[HelloZio] +} + +object HelloZioApp { def apply(): HttpApp[State, Nothing] = Http.collectZIO[Request] { case Method.GET -> !! / "hellozio" => - ZIO.succeed(Response.json("""{"hello":"zio"}""")) + ZIO.succeed(Response.json(HelloZio("world").toJson)) } } + object HttpServerWithZIOHttp { - val routes = HealthRouteWithZIOHttp() ++ HelloZio() + val routes = HealthRouteWithZIOHttp() ++ HelloZioApp() val layer: ZLayer[AppConfig & State, Nothing, Unit] = ZLayer { @@ -30,5 +38,4 @@ object HttpServerWithZIOHttp { _ <- ZIO.logInfo(">>> Acquire ZIO HTTP Server <<<") } yield () } - } From e1a40d417697d4ed417a996d85e8b6484362fe4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Kleinbo=CC=88lting?= Date: Tue, 13 Dec 2022 13:09:48 +0100 Subject: [PATCH 03/33] mob next [ci-skip] [ci skip] [skip ci] lastFile:webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala --- .../scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala index c1316474a7..5ae5658649 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala @@ -21,7 +21,7 @@ object HelloZio { object HelloZioApp { def apply(): HttpApp[State, Nothing] = Http.collectZIO[Request] { case Method.GET -> !! / "hellozio" => - ZIO.succeed(Response.json(HelloZio("world").toJson)) + ZIO.succeed(Response.json(HelloZio("team").toJson)) } } From a4a1dbb6bc2ae07b5cf26ed5f6bd872cef3ec837 Mon Sep 17 00:00:00 2001 From: Balduin Landolt <33053745+BalduinLandolt@users.noreply.github.com> Date: Tue, 13 Dec 2022 13:10:39 +0100 Subject: [PATCH 04/33] mob next [ci-skip] [ci skip] [skip ci] lastFile:webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala --- .../scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala index 5ae5658649..4822a50951 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala @@ -21,7 +21,7 @@ object HelloZio { object HelloZioApp { def apply(): HttpApp[State, Nothing] = Http.collectZIO[Request] { case Method.GET -> !! / "hellozio" => - ZIO.succeed(Response.json(HelloZio("team").toJson)) + ZIO.succeed(Response.json(HelloZio("team!").toJson)) } } From 3d17801e306f35974c603e25476e968ed9f2c712 Mon Sep 17 00:00:00 2001 From: Marcin Procyk Date: Tue, 13 Dec 2022 13:12:28 +0100 Subject: [PATCH 05/33] mob next [ci-skip] [ci skip] [skip ci] lastFile:webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala --- .../scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala index 4822a50951..e92cf596a7 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala @@ -21,7 +21,7 @@ object HelloZio { object HelloZioApp { def apply(): HttpApp[State, Nothing] = Http.collectZIO[Request] { case Method.GET -> !! / "hellozio" => - ZIO.succeed(Response.json(HelloZio("team!").toJson)) + ZIO.succeed(Response.json(HelloZio("team!:)").toJson)) } } From b13e1c64b7f485ff6ac05f515a70567e2788dfb8 Mon Sep 17 00:00:00 2001 From: irinaschubert Date: Tue, 13 Dec 2022 13:13:14 +0100 Subject: [PATCH 06/33] mob next [ci-skip] [ci skip] [skip ci] lastFile:webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala --- .../scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala index e92cf596a7..14f13152c8 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala @@ -21,7 +21,7 @@ object HelloZio { object HelloZioApp { def apply(): HttpApp[State, Nothing] = Http.collectZIO[Request] { case Method.GET -> !! / "hellozio" => - ZIO.succeed(Response.json(HelloZio("team!:)").toJson)) + ZIO.succeed(Response.json(HelloZio("team!:D").toJson)) } } From 2a4f00dd128ed42665f51c5e7bf2d28a69a52463 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Kleinbo=CC=88lting?= Date: Tue, 13 Dec 2022 13:19:04 +0100 Subject: [PATCH 07/33] mob next [ci-skip] [ci skip] [skip ci] lastFile:webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala --- .../webapi/core/HttpServerWithZIOHttp.scala | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala index 14f13152c8..49ea8c2aa6 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala @@ -19,9 +19,41 @@ object HelloZio { } object HelloZioApp { + + /** + * Returns a single project identified through the IRI. + * // + */ +// private def getProjectByIri(): Route = +// path(projectsBasePath / "iri" / Segment) { value => +// get { requestContext => +// val requestMessage: Future[ProjectGetRequestADM] = for { +// requestingUser <- getUserADM( +// requestContext = requestContext, +// routeData.appConfig +// ) +// +// } yield ProjectGetRequestADM( +// identifier = IriIdentifier +// .fromString(value) +// .getOrElseWith(e => throw BadRequestException(e.head.getMessage)), +// requestingUser = requestingUser +// ) +// +// RouteUtilADM.runJsonRoute( +// requestMessageF = requestMessage, +// requestContext = requestContext, +// appActor = appActor, +// log = log +// ) +// } +// } def apply(): HttpApp[State, Nothing] = - Http.collectZIO[Request] { case Method.GET -> !! / "hellozio" => - ZIO.succeed(Response.json(HelloZio("team!:D").toJson)) + Http.collectZIO[Request] { + + // GET admin/projects/iri/{iri} + case Method.GET -> !! / "admin" / "projects" / "iri" / iri => + ZIO.succeed(Response.json(HelloZio("team!:D").toJson)) } } From f0329ee09978e220677777cd64c558bee9acaf87 Mon Sep 17 00:00:00 2001 From: Balduin Landolt <33053745+BalduinLandolt@users.noreply.github.com> Date: Tue, 13 Dec 2022 13:24:52 +0100 Subject: [PATCH 08/33] mob next [ci-skip] [ci skip] [skip ci] lastFile:webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala --- .../org/knora/webapi/core/HttpServerWithZIOHttp.scala | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala index 49ea8c2aa6..6fcb278565 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala @@ -53,7 +53,12 @@ object HelloZioApp { // GET admin/projects/iri/{iri} case Method.GET -> !! / "admin" / "projects" / "iri" / iri => - ZIO.succeed(Response.json(HelloZio("team!:D").toJson)) + for { + iriValue <- IriIdentifier + .fromString(value) + .toZIO + } yield () + // ZIO.succeed(Response.json(HelloZio("team!:D").toJson)) } } From 706c133f7ff39c66a86995a5b371cf72b43cd7fb Mon Sep 17 00:00:00 2001 From: Balduin Landolt <33053745+BalduinLandolt@users.noreply.github.com> Date: Tue, 13 Dec 2022 13:24:58 +0100 Subject: [PATCH 09/33] mob next [ci-skip] [ci skip] [skip ci] lastFile:webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala --- .../main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala | 1 + 1 file changed, 1 insertion(+) diff --git a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala index 6fcb278565..5f402c2c74 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala @@ -54,6 +54,7 @@ object HelloZioApp { // GET admin/projects/iri/{iri} case Method.GET -> !! / "admin" / "projects" / "iri" / iri => for { + user <- ZIO.succeed(SystemUser) iriValue <- IriIdentifier .fromString(value) .toZIO From 418e69d49df1970687756a24b48fa5ad1011093c Mon Sep 17 00:00:00 2001 From: Marcin Procyk Date: Tue, 13 Dec 2022 13:31:23 +0100 Subject: [PATCH 10/33] mob next [ci-skip] [ci skip] [skip ci] lastFile:webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala --- .../org/knora/webapi/core/HttpServerWithZIOHttp.scala | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala index 5f402c2c74..a8302f1c48 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala @@ -11,6 +11,8 @@ import zhttp.http._ import zhttp.service.Server import zio.json.{DeriveJsonEncoder, EncoderOps} import zio.{ZLayer, _} +import org.knora.webapi.messages.util.KnoraSystemInstances +import org.knora.webapi.messages.admin.responder.projectsmessages.ProjectIdentifierADM case class HelloZio(hello: String) @@ -54,11 +56,12 @@ object HelloZioApp { // GET admin/projects/iri/{iri} case Method.GET -> !! / "admin" / "projects" / "iri" / iri => for { - user <- ZIO.succeed(SystemUser) - iriValue <- IriIdentifier - .fromString(value) + user <- ZIO.succeed(KnoraSystemInstances.Users.SystemUser) + iriValue <- ProjectIdentifierADM.IriIdentifier + .fromString(iri) .toZIO - } yield () + .orDie + } yield Response.json(HelloZio(iri).toJson) // ZIO.succeed(Response.json(HelloZio("team!:D").toJson)) } } From a7c7b0ef535aae369e34351d4116757b3751e146 Mon Sep 17 00:00:00 2001 From: irinaschubert Date: Tue, 13 Dec 2022 13:36:47 +0100 Subject: [PATCH 11/33] mob next [ci-skip] [ci skip] [skip ci] lastFile:webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala --- .../org/knora/webapi/core/HttpServerWithZIOHttp.scala | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala index a8302f1c48..a925daab2a 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala @@ -13,6 +13,7 @@ import zio.json.{DeriveJsonEncoder, EncoderOps} import zio.{ZLayer, _} import org.knora.webapi.messages.util.KnoraSystemInstances import org.knora.webapi.messages.admin.responder.projectsmessages.ProjectIdentifierADM +import org.knora.webapi.messages.admin.responder.projectsmessages.ProjectGetRequestADM case class HelloZio(hello: String) @@ -61,8 +62,13 @@ object HelloZioApp { .fromString(iri) .toZIO .orDie + message = ProjectGetRequestADM( + identifier = iriValue, + requestingUser = user + ) + } yield Response.json(HelloZio(iri).toJson) - // ZIO.succeed(Response.json(HelloZio("team!:D").toJson)) + } } From 3ff37fad6c2b9e35acdfddad6d11bd9da52ecb7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Kleinbo=CC=88lting?= Date: Tue, 13 Dec 2022 13:42:18 +0100 Subject: [PATCH 12/33] mob next [ci-skip] [ci skip] [skip ci] lastFile:webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala --- .../knora/webapi/core/HttpServerWithZIOHttp.scala | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala index a925daab2a..daca5202a8 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala @@ -6,14 +6,13 @@ package org.knora.webapi.core import org.knora.webapi.config.AppConfig +import org.knora.webapi.messages.admin.responder.projectsmessages.{ProjectGetRequestADM, ProjectIdentifierADM} +import org.knora.webapi.messages.util.KnoraSystemInstances import org.knora.webapi.routing.HealthRouteWithZIOHttp import zhttp.http._ import zhttp.service.Server import zio.json.{DeriveJsonEncoder, EncoderOps} import zio.{ZLayer, _} -import org.knora.webapi.messages.util.KnoraSystemInstances -import org.knora.webapi.messages.admin.responder.projectsmessages.ProjectIdentifierADM -import org.knora.webapi.messages.admin.responder.projectsmessages.ProjectGetRequestADM case class HelloZio(hello: String) @@ -21,7 +20,7 @@ object HelloZio { implicit val encoder = DeriveJsonEncoder.gen[HelloZio] } -object HelloZioApp { +final case class HelloZioApp(appRouter: AppRouter) { /** * Returns a single project identified through the IRI. @@ -51,7 +50,7 @@ object HelloZioApp { // ) // } // } - def apply(): HttpApp[State, Nothing] = + def route(): HttpApp[Any, Nothing] = Http.collectZIO[Request] { // GET admin/projects/iri/{iri} @@ -71,15 +70,19 @@ object HelloZioApp { } } +object HelloZioApp { + val layer = ZLayer.fromFunction(HelloZioApp(_)) +} object HttpServerWithZIOHttp { - val routes = HealthRouteWithZIOHttp() ++ HelloZioApp() + val routes = HealthRouteWithZIOHttp() val layer: ZLayer[AppConfig & State, Nothing, Unit] = ZLayer { for { appConfig <- ZIO.service[AppConfig] + port = appConfig.knoraApi.externalZioPort _ <- Server.start(port, routes).forkDaemon _ <- ZIO.logInfo(">>> Acquire ZIO HTTP Server <<<") From bd315374962a3622227e1a98b4e9719d20ec6346 Mon Sep 17 00:00:00 2001 From: Balduin Landolt <33053745+BalduinLandolt@users.noreply.github.com> Date: Tue, 13 Dec 2022 13:48:02 +0100 Subject: [PATCH 13/33] mob next [ci-skip] [ci skip] [skip ci] lastFile:webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala --- .../knora/webapi/core/HttpServerWithZIOHttp.scala | 13 +++++++------ .../scala/org/knora/webapi/core/LayersLive.scala | 3 ++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala index daca5202a8..8a2ebfb3dc 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala @@ -78,14 +78,15 @@ object HttpServerWithZIOHttp { val routes = HealthRouteWithZIOHttp() - val layer: ZLayer[AppConfig & State, Nothing, Unit] = + val layer: ZLayer[AppConfig & HelloZioApp, Nothing, Unit] = ZLayer { for { - appConfig <- ZIO.service[AppConfig] - - port = appConfig.knoraApi.externalZioPort - _ <- Server.start(port, routes).forkDaemon - _ <- ZIO.logInfo(">>> Acquire ZIO HTTP Server <<<") + appConfig <- ZIO.service[AppConfig] + helloZioApp <- ZIO.service[HelloZioApp] + routes = + port = appConfig.knoraApi.externalZioPort + _ <- Server.start(port, routes ++ helloZioApp.route).forkDaemon + _ <- ZIO.logInfo(">>> Acquire ZIO HTTP Server <<<") } yield () } } diff --git a/webapi/src/main/scala/org/knora/webapi/core/LayersLive.scala b/webapi/src/main/scala/org/knora/webapi/core/LayersLive.scala index d45fb48dc0..57a2d9fc02 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/LayersLive.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/LayersLive.scala @@ -62,6 +62,7 @@ object LayersLive { RepositoryUpdater.layer, State.layer, TriplestoreServiceManager.layer, - TriplestoreServiceHttpConnectorImpl.layer + TriplestoreServiceHttpConnectorImpl.layer, + HelloZioApp.layer ) } From 8808b573a17cdee71aa2d548377e972c424e590a Mon Sep 17 00:00:00 2001 From: Marcin Procyk Date: Tue, 13 Dec 2022 13:53:38 +0100 Subject: [PATCH 14/33] mob next [ci-skip] [ci skip] [skip ci] lastFile:webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala --- .../knora/webapi/core/HttpServerWithZIOHttp.scala | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala index 8a2ebfb3dc..4989b14ed7 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala @@ -65,7 +65,7 @@ final case class HelloZioApp(appRouter: AppRouter) { identifier = iriValue, requestingUser = user ) - + something <- ZIO.fromFuture(_ => appRouter.receive) } yield Response.json(HelloZio(iri).toJson) } @@ -78,15 +78,15 @@ object HttpServerWithZIOHttp { val routes = HealthRouteWithZIOHttp() - val layer: ZLayer[AppConfig & HelloZioApp, Nothing, Unit] = + val layer: ZLayer[AppConfig & State & HelloZioApp, Nothing, Unit] = ZLayer { for { appConfig <- ZIO.service[AppConfig] helloZioApp <- ZIO.service[HelloZioApp] - routes = - port = appConfig.knoraApi.externalZioPort - _ <- Server.start(port, routes ++ helloZioApp.route).forkDaemon - _ <- ZIO.logInfo(">>> Acquire ZIO HTTP Server <<<") + r = routes ++ helloZioApp.route() + port = appConfig.knoraApi.externalZioPort + _ <- Server.start(port, r).forkDaemon + _ <- ZIO.logInfo(">>> Acquire ZIO HTTP Server <<<") } yield () } } From 520371462bd7dfa978d98fbe7e9c556a358ad62a Mon Sep 17 00:00:00 2001 From: irinaschubert Date: Tue, 13 Dec 2022 13:59:13 +0100 Subject: [PATCH 15/33] mob next [ci-skip] [ci skip] [skip ci] lastFile:webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala --- .../scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala index 4989b14ed7..52c4001294 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala @@ -13,6 +13,8 @@ import zhttp.http._ import zhttp.service.Server import zio.json.{DeriveJsonEncoder, EncoderOps} import zio.{ZLayer, _} +import org.knora.webapi.core.actors.RoutingActor +import akka.pattern.ask case class HelloZio(hello: String) @@ -20,7 +22,7 @@ object HelloZio { implicit val encoder = DeriveJsonEncoder.gen[HelloZio] } -final case class HelloZioApp(appRouter: AppRouter) { +final case class HelloZioApp(routingActor: RoutingActor) { /** * Returns a single project identified through the IRI. @@ -65,7 +67,7 @@ final case class HelloZioApp(appRouter: AppRouter) { identifier = iriValue, requestingUser = user ) - something <- ZIO.fromFuture(_ => appRouter.receive) + something <- ZIO.fromFuture(_ => routingActor.ref.ask) } yield Response.json(HelloZio(iri).toJson) } From b48544356bea11e34f49de365f4b87191d6c97d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Kleinbo=CC=88lting?= Date: Tue, 13 Dec 2022 14:07:58 +0100 Subject: [PATCH 16/33] mob next [ci-skip] [ci skip] [skip ci] lastFile:webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala --- .../org/knora/webapi/core/HttpServerWithZIOHttp.scala | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala index 52c4001294..fd1a3a3d88 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala @@ -4,8 +4,9 @@ */ package org.knora.webapi.core - +import akka.pattern.ask import org.knora.webapi.config.AppConfig +import org.knora.webapi.core.actors.RoutingActor import org.knora.webapi.messages.admin.responder.projectsmessages.{ProjectGetRequestADM, ProjectIdentifierADM} import org.knora.webapi.messages.util.KnoraSystemInstances import org.knora.webapi.routing.HealthRouteWithZIOHttp @@ -13,8 +14,6 @@ import zhttp.http._ import zhttp.service.Server import zio.json.{DeriveJsonEncoder, EncoderOps} import zio.{ZLayer, _} -import org.knora.webapi.core.actors.RoutingActor -import akka.pattern.ask case class HelloZio(hello: String) @@ -22,7 +21,7 @@ object HelloZio { implicit val encoder = DeriveJsonEncoder.gen[HelloZio] } -final case class HelloZioApp(routingActor: RoutingActor) { +final case class HelloZioApp(router: AppRouter) { /** * Returns a single project identified through the IRI. @@ -67,7 +66,8 @@ final case class HelloZioApp(routingActor: RoutingActor) { identifier = iriValue, requestingUser = user ) - something <- ZIO.fromFuture(_ => routingActor.ref.ask) + foo = routingActor.ask(message) +// something <- ZIO.fromFuture(_ => routingActor.ask(message)) } yield Response.json(HelloZio(iri).toJson) } From 9b92248245de5aa156ffc489067e66abeae7f9af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Kleinbo=CC=88lting?= Date: Tue, 13 Dec 2022 14:08:56 +0100 Subject: [PATCH 17/33] mob next [ci-skip] [ci skip] [skip ci] lastFile:webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala --- .../scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala index fd1a3a3d88..6da4592534 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala @@ -6,7 +6,6 @@ package org.knora.webapi.core import akka.pattern.ask import org.knora.webapi.config.AppConfig -import org.knora.webapi.core.actors.RoutingActor import org.knora.webapi.messages.admin.responder.projectsmessages.{ProjectGetRequestADM, ProjectIdentifierADM} import org.knora.webapi.messages.util.KnoraSystemInstances import org.knora.webapi.routing.HealthRouteWithZIOHttp @@ -66,8 +65,7 @@ final case class HelloZioApp(router: AppRouter) { identifier = iriValue, requestingUser = user ) - foo = routingActor.ask(message) -// something <- ZIO.fromFuture(_ => routingActor.ask(message)) + something <- ZIO.fromFuture(_ => router.ref.ask(message)) } yield Response.json(HelloZio(iri).toJson) } From b70aecfabb361fa5ade68da179a3b781d7c057b2 Mon Sep 17 00:00:00 2001 From: Balduin Landolt <33053745+BalduinLandolt@users.noreply.github.com> Date: Tue, 13 Dec 2022 14:24:12 +0100 Subject: [PATCH 18/33] mob next [ci-skip] [ci skip] [skip ci] lastFile:webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala --- .../scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala | 2 ++ 1 file changed, 2 insertions(+) diff --git a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala index 6da4592534..3939944a0b 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala @@ -13,6 +13,7 @@ import zhttp.http._ import zhttp.service.Server import zio.json.{DeriveJsonEncoder, EncoderOps} import zio.{ZLayer, _} +import akka.util.Timeout case class HelloZio(hello: String) @@ -21,6 +22,7 @@ object HelloZio { } final case class HelloZioApp(router: AppRouter) { + implicit val timeout = Timeout(10.second) /** * Returns a single project identified through the IRI. From efd0f3bfb6613565b56fc66ed0d4c1ba185189f8 Mon Sep 17 00:00:00 2001 From: Balduin Landolt <33053745+BalduinLandolt@users.noreply.github.com> Date: Tue, 13 Dec 2022 14:24:20 +0100 Subject: [PATCH 19/33] mob next [ci-skip] [ci skip] [skip ci] lastFile:webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala --- .../scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala index 3939944a0b..d6b91951bc 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala @@ -14,6 +14,7 @@ import zhttp.service.Server import zio.json.{DeriveJsonEncoder, EncoderOps} import zio.{ZLayer, _} import akka.util.Timeout +import dsp.config.AppConfig case class HelloZio(hello: String) @@ -21,8 +22,7 @@ object HelloZio { implicit val encoder = DeriveJsonEncoder.gen[HelloZio] } -final case class HelloZioApp(router: AppRouter) { - implicit val timeout = Timeout(10.second) +final case class HelloZioApp(router: AppRouter, appConfig: AppConfig) { /** * Returns a single project identified through the IRI. From 2848391c597eae0d73db6a5bda5117feac3ca410 Mon Sep 17 00:00:00 2001 From: Marcin Procyk Date: Tue, 13 Dec 2022 14:29:55 +0100 Subject: [PATCH 20/33] mob next [ci-skip] [ci skip] [skip ci] lastFile:webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala --- .../org/knora/webapi/core/HttpServerWithZIOHttp.scala | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala index d6b91951bc..0f36157cd7 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala @@ -14,7 +14,8 @@ import zhttp.service.Server import zio.json.{DeriveJsonEncoder, EncoderOps} import zio.{ZLayer, _} import akka.util.Timeout -import dsp.config.AppConfig +import akka.actor.ActorRef +// import dsp.config.AppConfig case class HelloZio(hello: String) @@ -23,6 +24,8 @@ object HelloZio { } final case class HelloZioApp(router: AppRouter, appConfig: AppConfig) { + implicit val sender: ActorRef = router.ref + implicit val timeout: Timeout = appConfig.defaultTimeoutAsDuration /** * Returns a single project identified through the IRI. @@ -67,7 +70,7 @@ final case class HelloZioApp(router: AppRouter, appConfig: AppConfig) { identifier = iriValue, requestingUser = user ) - something <- ZIO.fromFuture(_ => router.ref.ask(message)) + something <- ZIO.fromFuture(_ => router.ref.ask(message)).orDie } yield Response.json(HelloZio(iri).toJson) } From 95f3bee665fde089bc787f33b9a2bc1150e2e72f Mon Sep 17 00:00:00 2001 From: irinaschubert Date: Tue, 13 Dec 2022 14:35:18 +0100 Subject: [PATCH 21/33] mob next [ci-skip] [ci skip] [skip ci] lastFile:webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala --- .../scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala index 0f36157cd7..a0ed319b5e 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala @@ -15,6 +15,8 @@ import zio.json.{DeriveJsonEncoder, EncoderOps} import zio.{ZLayer, _} import akka.util.Timeout import akka.actor.ActorRef +import org.knora.webapi.messages.v2.responder.SuccessResponseV2 +import org.knora.webapi.messages.admin.responder.projectsmessages.ProjectsGetResponseADM // import dsp.config.AppConfig case class HelloZio(hello: String) @@ -70,8 +72,8 @@ final case class HelloZioApp(router: AppRouter, appConfig: AppConfig) { identifier = iriValue, requestingUser = user ) - something <- ZIO.fromFuture(_ => router.ref.ask(message)).orDie - } yield Response.json(HelloZio(iri).toJson) + response <- ZIO.fromFuture(_ => router.ref.ask(message)).map(_.asInstanceOf[ProjectsGetResponseADM]).orDie + } yield Response.json(response.toJsValue.toString()) } } From 8b48df22a0a2e95ec900a754c9461926c0d4b4cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Kleinbo=CC=88lting?= Date: Tue, 13 Dec 2022 14:42:41 +0100 Subject: [PATCH 22/33] mob next [ci-skip] [ci skip] [skip ci] lastFile:webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala --- .../webapi/core/HttpServerWithZIOHttp.scala | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala index a0ed319b5e..c3c74ff96a 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala @@ -4,19 +4,21 @@ */ package org.knora.webapi.core +import akka.actor.ActorRef import akka.pattern.ask +import akka.util.Timeout import org.knora.webapi.config.AppConfig -import org.knora.webapi.messages.admin.responder.projectsmessages.{ProjectGetRequestADM, ProjectIdentifierADM} +import org.knora.webapi.messages.admin.responder.projectsmessages.{ + ProjectGetRequestADM, + ProjectIdentifierADM, + ProjectsGetResponseADM +} import org.knora.webapi.messages.util.KnoraSystemInstances import org.knora.webapi.routing.HealthRouteWithZIOHttp import zhttp.http._ import zhttp.service.Server -import zio.json.{DeriveJsonEncoder, EncoderOps} +import zio.json.DeriveJsonEncoder import zio.{ZLayer, _} -import akka.util.Timeout -import akka.actor.ActorRef -import org.knora.webapi.messages.v2.responder.SuccessResponseV2 -import org.knora.webapi.messages.admin.responder.projectsmessages.ProjectsGetResponseADM // import dsp.config.AppConfig case class HelloZio(hello: String) @@ -78,14 +80,16 @@ final case class HelloZioApp(router: AppRouter, appConfig: AppConfig) { } } object HelloZioApp { - val layer = ZLayer.fromFunction(HelloZioApp(_)) + val layer: ZLayer[AppRouter with AppConfig, Nothing, HelloZioApp] = ZLayer.fromFunction { (router, config) => + HelloZioApp(router, config) + } } object HttpServerWithZIOHttp { val routes = HealthRouteWithZIOHttp() - val layer: ZLayer[AppConfig & State & HelloZioApp, Nothing, Unit] = + val layer: ZLayer[AppRouter & AppConfig & State & HelloZioApp, Nothing, Unit] = ZLayer { for { appConfig <- ZIO.service[AppConfig] From e726c3e744bb30928c78ce877d87dc41dd9a9b62 Mon Sep 17 00:00:00 2001 From: Marcin Procyk Date: Tue, 13 Dec 2022 14:56:12 +0100 Subject: [PATCH 23/33] mob next [ci-skip] [ci skip] [skip ci] lastFile:webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala --- .../scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala index c3c74ff96a..fc85d49995 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala @@ -19,6 +19,8 @@ import zhttp.http._ import zhttp.service.Server import zio.json.DeriveJsonEncoder import zio.{ZLayer, _} +import java.net.URLDecoder +// import java.net.URLDecoder // import dsp.config.AppConfig case class HelloZio(hello: String) @@ -65,7 +67,8 @@ final case class HelloZioApp(router: AppRouter, appConfig: AppConfig) { // GET admin/projects/iri/{iri} case Method.GET -> !! / "admin" / "projects" / "iri" / iri => for { - user <- ZIO.succeed(KnoraSystemInstances.Users.SystemUser) + user <- ZIO.succeed(KnoraSystemInstances.Users.SystemUser) + iriDecoded <- ZIO.attempt(URLDecoder.decode(iri, "utf-8")).orDie iriValue <- ProjectIdentifierADM.IriIdentifier .fromString(iri) .toZIO From c1bd8ffd4bd84ed1d878eba4b6824e65291871ef Mon Sep 17 00:00:00 2001 From: irinaschubert Date: Tue, 13 Dec 2022 15:03:28 +0100 Subject: [PATCH 24/33] mob next [ci-skip] [ci skip] [skip ci] lastFile:webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala --- .../scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala index fc85d49995..9a885e3bfe 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala @@ -70,7 +70,7 @@ final case class HelloZioApp(router: AppRouter, appConfig: AppConfig) { user <- ZIO.succeed(KnoraSystemInstances.Users.SystemUser) iriDecoded <- ZIO.attempt(URLDecoder.decode(iri, "utf-8")).orDie iriValue <- ProjectIdentifierADM.IriIdentifier - .fromString(iri) + .fromString(iriDecoded) .toZIO .orDie message = ProjectGetRequestADM( From 811b970a985e9aec2a4d1dae639b4b73e88b3402 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Kleinbo=CC=88lting?= Date: Tue, 13 Dec 2022 15:05:34 +0100 Subject: [PATCH 25/33] working --- .../org/knora/webapi/core/HttpServerWithZIOHttp.scala | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala index 9a885e3bfe..632128d536 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala @@ -10,8 +10,8 @@ import akka.util.Timeout import org.knora.webapi.config.AppConfig import org.knora.webapi.messages.admin.responder.projectsmessages.{ ProjectGetRequestADM, - ProjectIdentifierADM, - ProjectsGetResponseADM + ProjectGetResponseADM, + ProjectIdentifierADM } import org.knora.webapi.messages.util.KnoraSystemInstances import org.knora.webapi.routing.HealthRouteWithZIOHttp @@ -19,6 +19,7 @@ import zhttp.http._ import zhttp.service.Server import zio.json.DeriveJsonEncoder import zio.{ZLayer, _} + import java.net.URLDecoder // import java.net.URLDecoder // import dsp.config.AppConfig @@ -77,7 +78,7 @@ final case class HelloZioApp(router: AppRouter, appConfig: AppConfig) { identifier = iriValue, requestingUser = user ) - response <- ZIO.fromFuture(_ => router.ref.ask(message)).map(_.asInstanceOf[ProjectsGetResponseADM]).orDie + response <- ZIO.fromFuture(_ => router.ref.ask(message)).map(_.asInstanceOf[ProjectGetResponseADM]).orDie } yield Response.json(response.toJsValue.toString()) } From e99134abb2eaf7430e1713c450b9123ec49a0e08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Kleinbo=CC=88lting?= Date: Tue, 13 Dec 2022 15:13:07 +0100 Subject: [PATCH 26/33] mob next [ci-skip] [ci skip] [skip ci] lastFile:webapi/src/main/scala/org/knora/webapi/routing/admin/ProjectsRouteZ.scala --- .../webapi/core/HttpServerWithZIOHttp.scala | 91 ++----------------- .../org/knora/webapi/core/LayersLive.scala | 3 +- .../webapi/routing/admin/ProjectsRouteZ.scala | 49 ++++++++++ 3 files changed, 58 insertions(+), 85 deletions(-) create mode 100644 webapi/src/main/scala/org/knora/webapi/routing/admin/ProjectsRouteZ.scala diff --git a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala index 632128d536..2d6e318e45 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala @@ -4,100 +4,23 @@ */ package org.knora.webapi.core -import akka.actor.ActorRef -import akka.pattern.ask -import akka.util.Timeout -import org.knora.webapi.config.AppConfig -import org.knora.webapi.messages.admin.responder.projectsmessages.{ - ProjectGetRequestADM, - ProjectGetResponseADM, - ProjectIdentifierADM -} -import org.knora.webapi.messages.util.KnoraSystemInstances -import org.knora.webapi.routing.HealthRouteWithZIOHttp -import zhttp.http._ import zhttp.service.Server -import zio.json.DeriveJsonEncoder -import zio.{ZLayer, _} - -import java.net.URLDecoder -// import java.net.URLDecoder -// import dsp.config.AppConfig - -case class HelloZio(hello: String) - -object HelloZio { - implicit val encoder = DeriveJsonEncoder.gen[HelloZio] -} - -final case class HelloZioApp(router: AppRouter, appConfig: AppConfig) { - implicit val sender: ActorRef = router.ref - implicit val timeout: Timeout = appConfig.defaultTimeoutAsDuration +import zio.ZLayer +import zio._ - /** - * Returns a single project identified through the IRI. - * // - */ -// private def getProjectByIri(): Route = -// path(projectsBasePath / "iri" / Segment) { value => -// get { requestContext => -// val requestMessage: Future[ProjectGetRequestADM] = for { -// requestingUser <- getUserADM( -// requestContext = requestContext, -// routeData.appConfig -// ) -// -// } yield ProjectGetRequestADM( -// identifier = IriIdentifier -// .fromString(value) -// .getOrElseWith(e => throw BadRequestException(e.head.getMessage)), -// requestingUser = requestingUser -// ) -// -// RouteUtilADM.runJsonRoute( -// requestMessageF = requestMessage, -// requestContext = requestContext, -// appActor = appActor, -// log = log -// ) -// } -// } - def route(): HttpApp[Any, Nothing] = - Http.collectZIO[Request] { - - // GET admin/projects/iri/{iri} - case Method.GET -> !! / "admin" / "projects" / "iri" / iri => - for { - user <- ZIO.succeed(KnoraSystemInstances.Users.SystemUser) - iriDecoded <- ZIO.attempt(URLDecoder.decode(iri, "utf-8")).orDie - iriValue <- ProjectIdentifierADM.IriIdentifier - .fromString(iriDecoded) - .toZIO - .orDie - message = ProjectGetRequestADM( - identifier = iriValue, - requestingUser = user - ) - response <- ZIO.fromFuture(_ => router.ref.ask(message)).map(_.asInstanceOf[ProjectGetResponseADM]).orDie - } yield Response.json(response.toJsValue.toString()) - - } -} -object HelloZioApp { - val layer: ZLayer[AppRouter with AppConfig, Nothing, HelloZioApp] = ZLayer.fromFunction { (router, config) => - HelloZioApp(router, config) - } -} +import org.knora.webapi.config.AppConfig +import org.knora.webapi.routing.HealthRouteWithZIOHttp +import org.knora.webapi.routing.admin.ProjectsRouteZ object HttpServerWithZIOHttp { val routes = HealthRouteWithZIOHttp() - val layer: ZLayer[AppRouter & AppConfig & State & HelloZioApp, Nothing, Unit] = + val layer: ZLayer[AppRouter & AppConfig & State & ProjectsRouteZ, Nothing, Unit] = ZLayer { for { appConfig <- ZIO.service[AppConfig] - helloZioApp <- ZIO.service[HelloZioApp] + helloZioApp <- ZIO.service[ProjectsRouteZ] r = routes ++ helloZioApp.route() port = appConfig.knoraApi.externalZioPort _ <- Server.start(port, r).forkDaemon diff --git a/webapi/src/main/scala/org/knora/webapi/core/LayersLive.scala b/webapi/src/main/scala/org/knora/webapi/core/LayersLive.scala index 57a2d9fc02..c9996f0a47 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/LayersLive.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/LayersLive.scala @@ -11,6 +11,7 @@ import zio.ZLayer import org.knora.webapi.auth.JWTService import org.knora.webapi.config.AppConfig import org.knora.webapi.routing.ApiRoutes +import org.knora.webapi.routing.admin.ProjectsRouteZ import org.knora.webapi.store.cache.CacheServiceManager import org.knora.webapi.store.cache.api.CacheService import org.knora.webapi.store.cache.impl.CacheServiceInMemImpl @@ -63,6 +64,6 @@ object LayersLive { State.layer, TriplestoreServiceManager.layer, TriplestoreServiceHttpConnectorImpl.layer, - HelloZioApp.layer + ProjectsRouteZ.layer ) } diff --git a/webapi/src/main/scala/org/knora/webapi/routing/admin/ProjectsRouteZ.scala b/webapi/src/main/scala/org/knora/webapi/routing/admin/ProjectsRouteZ.scala new file mode 100644 index 0000000000..8092b9ee34 --- /dev/null +++ b/webapi/src/main/scala/org/knora/webapi/routing/admin/ProjectsRouteZ.scala @@ -0,0 +1,49 @@ +package org.knora.webapi.routing.admin + +import akka.actor.ActorRef +import akka.pattern.ask +import akka.util.Timeout +import zhttp.http._ +import zio.ZIO +import zio.ZLayer + +import java.net.URLDecoder + +import org.knora.webapi.config.AppConfig +import org.knora.webapi.core.AppRouter +import org.knora.webapi.messages.admin.responder.projectsmessages.ProjectGetRequestADM +import org.knora.webapi.messages.admin.responder.projectsmessages.ProjectGetResponseADM +import org.knora.webapi.messages.admin.responder.projectsmessages.ProjectIdentifierADM +import org.knora.webapi.messages.util.KnoraSystemInstances + +final case class ProjectsRouteZ(router: AppRouter, appConfig: AppConfig) { + implicit val sender: ActorRef = router.ref + implicit val timeout: Timeout = appConfig.defaultTimeoutAsDuration + + def route(): HttpApp[Any, Nothing] = + Http.collectZIO[Request] { + + // Returns a single project identified through the IRI. + case Method.GET -> !! / "admin" / "projects" / "iri" / iri => + for { + user <- ZIO.succeed(KnoraSystemInstances.Users.SystemUser) + iriDecoded <- ZIO.attempt(URLDecoder.decode(iri, "utf-8")).orDie + iriValue <- ProjectIdentifierADM.IriIdentifier + .fromString(iriDecoded) + .toZIO + .orDie + message = ProjectGetRequestADM( + identifier = iriValue, + requestingUser = user + ) + response <- ZIO.fromFuture(_ => router.ref.ask(message)).map(_.asInstanceOf[ProjectGetResponseADM]).orDie + } yield Response.json(response.toJsValue.toString()) + + } +} + +object ProjectsRouteZ { + val layer: ZLayer[AppRouter with AppConfig, Nothing, ProjectsRouteZ] = ZLayer.fromFunction { (router, config) => + ProjectsRouteZ(router, config) + } +} From a2c8b6fae5e96a2c29e2fd7b013a856ec39efd6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Kleinbo=CC=88lting?= Date: Tue, 13 Dec 2022 15:23:27 +0100 Subject: [PATCH 27/33] add todo --- .../webapi/routing/admin/ProjectsRouteZ.scala | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/webapi/src/main/scala/org/knora/webapi/routing/admin/ProjectsRouteZ.scala b/webapi/src/main/scala/org/knora/webapi/routing/admin/ProjectsRouteZ.scala index 8092b9ee34..8f782b7ea0 100644 --- a/webapi/src/main/scala/org/knora/webapi/routing/admin/ProjectsRouteZ.scala +++ b/webapi/src/main/scala/org/knora/webapi/routing/admin/ProjectsRouteZ.scala @@ -3,18 +3,18 @@ package org.knora.webapi.routing.admin import akka.actor.ActorRef import akka.pattern.ask import akka.util.Timeout -import zhttp.http._ -import zio.ZIO -import zio.ZLayer - -import java.net.URLDecoder - import org.knora.webapi.config.AppConfig import org.knora.webapi.core.AppRouter -import org.knora.webapi.messages.admin.responder.projectsmessages.ProjectGetRequestADM -import org.knora.webapi.messages.admin.responder.projectsmessages.ProjectGetResponseADM -import org.knora.webapi.messages.admin.responder.projectsmessages.ProjectIdentifierADM +import org.knora.webapi.messages.admin.responder.projectsmessages.{ + ProjectGetRequestADM, + ProjectGetResponseADM, + ProjectIdentifierADM +} import org.knora.webapi.messages.util.KnoraSystemInstances +import zhttp.http._ +import zio.{ZIO, ZLayer} + +import java.net.URLDecoder final case class ProjectsRouteZ(router: AppRouter, appConfig: AppConfig) { implicit val sender: ActorRef = router.ref @@ -23,6 +23,7 @@ final case class ProjectsRouteZ(router: AppRouter, appConfig: AppConfig) { def route(): HttpApp[Any, Nothing] = Http.collectZIO[Request] { + // TODO : Add user authentication and error handling // Returns a single project identified through the IRI. case Method.GET -> !! / "admin" / "projects" / "iri" / iri => for { From ac5dfe62faa503194ed24929ed9c72eb78639c7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Kleinbo=CC=88lting?= Date: Tue, 13 Dec 2022 15:25:53 +0100 Subject: [PATCH 28/33] rename variable --- .../webapi/core/HttpServerWithZIOHttp.scala | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala index 2d6e318e45..a784c207ae 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala @@ -4,13 +4,11 @@ */ 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.HealthRouteWithZIOHttp import org.knora.webapi.routing.admin.ProjectsRouteZ +import zhttp.service.Server +import zio.{ZLayer, _} object HttpServerWithZIOHttp { @@ -19,12 +17,12 @@ object HttpServerWithZIOHttp { val layer: ZLayer[AppRouter & AppConfig & State & ProjectsRouteZ, Nothing, Unit] = ZLayer { for { - appConfig <- ZIO.service[AppConfig] - helloZioApp <- ZIO.service[ProjectsRouteZ] - r = routes ++ helloZioApp.route() - port = appConfig.knoraApi.externalZioPort - _ <- Server.start(port, r).forkDaemon - _ <- ZIO.logInfo(">>> Acquire ZIO HTTP Server <<<") + appConfig <- ZIO.service[AppConfig] + projectsRoute <- ZIO.service[ProjectsRouteZ] + r = routes ++ projectsRoute.route() + port = appConfig.knoraApi.externalZioPort + _ <- Server.start(port, r).forkDaemon + _ <- ZIO.logInfo(">>> Acquire ZIO HTTP Server <<<") } yield () } } From 8b625426a09e66dad83d607316d1912ef9f83538 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Kleinbo=CC=88lting?= Date: Tue, 13 Dec 2022 15:29:43 +0100 Subject: [PATCH 29/33] rename variable and formatting --- .../webapi/core/HttpServerWithZIOHttp.scala | 6 ++++-- .../webapi/routing/admin/ProjectsRouteZ.scala | 18 +++++++++--------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala index a784c207ae..a548a7779c 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala @@ -4,11 +4,13 @@ */ 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.HealthRouteWithZIOHttp import org.knora.webapi.routing.admin.ProjectsRouteZ -import zhttp.service.Server -import zio.{ZLayer, _} object HttpServerWithZIOHttp { diff --git a/webapi/src/main/scala/org/knora/webapi/routing/admin/ProjectsRouteZ.scala b/webapi/src/main/scala/org/knora/webapi/routing/admin/ProjectsRouteZ.scala index 8f782b7ea0..479e4419c7 100644 --- a/webapi/src/main/scala/org/knora/webapi/routing/admin/ProjectsRouteZ.scala +++ b/webapi/src/main/scala/org/knora/webapi/routing/admin/ProjectsRouteZ.scala @@ -3,19 +3,19 @@ package org.knora.webapi.routing.admin import akka.actor.ActorRef import akka.pattern.ask import akka.util.Timeout -import org.knora.webapi.config.AppConfig -import org.knora.webapi.core.AppRouter -import org.knora.webapi.messages.admin.responder.projectsmessages.{ - ProjectGetRequestADM, - ProjectGetResponseADM, - ProjectIdentifierADM -} -import org.knora.webapi.messages.util.KnoraSystemInstances import zhttp.http._ -import zio.{ZIO, ZLayer} +import zio.ZIO +import zio.ZLayer import java.net.URLDecoder +import org.knora.webapi.config.AppConfig +import org.knora.webapi.core.AppRouter +import org.knora.webapi.messages.admin.responder.projectsmessages.ProjectGetRequestADM +import org.knora.webapi.messages.admin.responder.projectsmessages.ProjectGetResponseADM +import org.knora.webapi.messages.admin.responder.projectsmessages.ProjectIdentifierADM +import org.knora.webapi.messages.util.KnoraSystemInstances + final case class ProjectsRouteZ(router: AppRouter, appConfig: AppConfig) { implicit val sender: ActorRef = router.ref implicit val timeout: Timeout = appConfig.defaultTimeoutAsDuration From 89765d8d7b2669db422a03ef663eb99b418c0b9c Mon Sep 17 00:00:00 2001 From: Balduin Landolt <33053745+BalduinLandolt@users.noreply.github.com> Date: Tue, 13 Dec 2022 16:46:33 +0100 Subject: [PATCH 30/33] mob next [ci-skip] [ci skip] [skip ci] lastFile:webapi/src/main/scala/org/knora/webapi/http/status/ApiStatusCodesZ.scala --- .../webapi/core/HttpServerWithZIOHttp.scala | 2 +- .../http/handler/ExceptionHandlerZ.scala | 55 +++++++++++++++++++ .../webapi/http/status/ApiStatusCodesZ.scala | 48 ++++++++++++++++ .../webapi/routing/admin/ProjectsRouteZ.scala | 54 +++++++++++------- 4 files changed, 137 insertions(+), 22 deletions(-) create mode 100644 webapi/src/main/scala/org/knora/webapi/http/handler/ExceptionHandlerZ.scala create mode 100644 webapi/src/main/scala/org/knora/webapi/http/status/ApiStatusCodesZ.scala diff --git a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala index a548a7779c..287f47b8e0 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala @@ -21,7 +21,7 @@ object HttpServerWithZIOHttp { for { appConfig <- ZIO.service[AppConfig] projectsRoute <- ZIO.service[ProjectsRouteZ] - r = routes ++ projectsRoute.route() + r = routes ++ projectsRoute.route port = appConfig.knoraApi.externalZioPort _ <- Server.start(port, r).forkDaemon _ <- ZIO.logInfo(">>> Acquire ZIO HTTP Server <<<") diff --git a/webapi/src/main/scala/org/knora/webapi/http/handler/ExceptionHandlerZ.scala b/webapi/src/main/scala/org/knora/webapi/http/handler/ExceptionHandlerZ.scala new file mode 100644 index 0000000000..de2f3c0f72 --- /dev/null +++ b/webapi/src/main/scala/org/knora/webapi/http/handler/ExceptionHandlerZ.scala @@ -0,0 +1,55 @@ +/* + * 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.http.handler + +import spray.json._ +import zhttp.http.Http +import zhttp.http.Response + +import dsp.errors.RequestRejectedException +import org.knora.webapi.config.AppConfig +import org.knora.webapi.http.status.ApiStatusCodesZ + +object ExceptionHandlerZ { + private val GENERIC_INTERNAL_SERVER_ERROR_MESSAGE = + "The request could not be completed because of an internal server error." + + def exceptionToJsonHttpResponseZ(ex: Throwable, appConfig: AppConfig): Http[Any, Nothing, Any, Response] = { + + // Get the HTTP status code that corresponds to the exception. + val httpStatus = ApiStatusCodesZ.fromExceptionZ(ex) + + // Generate an HTTP response containing the error message ... + val responseFields: Map[String, JsValue] = Map( + "error" -> JsString(makeClientErrorMessage(ex, appConfig)) + ) + + val json = JsObject(responseFields).compactPrint + + // ... and the HTTP status code. + Http.response(Response.json(json).setStatus(httpStatus)) + + } + + /** + * Given an exception, returns an error message suitable for clients. + * + * @param ex the exception. + * @param appConfig the application's configuration. + * @return an error message suitable for clients. + */ + private def makeClientErrorMessage(ex: Throwable, appConfig: AppConfig): String = + ex match { + case rre: RequestRejectedException => rre.toString + + case other => + if (appConfig.showInternalErrors) { + other.toString + } else { + GENERIC_INTERNAL_SERVER_ERROR_MESSAGE + } + } +} diff --git a/webapi/src/main/scala/org/knora/webapi/http/status/ApiStatusCodesZ.scala b/webapi/src/main/scala/org/knora/webapi/http/status/ApiStatusCodesZ.scala new file mode 100644 index 0000000000..e1ffdbe8a2 --- /dev/null +++ b/webapi/src/main/scala/org/knora/webapi/http/status/ApiStatusCodesZ.scala @@ -0,0 +1,48 @@ +/* + * 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.http.status + +import zhttp.http.Status + +import dsp.errors._ +import org.knora.webapi.store.triplestore.errors.TriplestoreTimeoutException + +/** + * The possible values for the HTTP status code that is returned as part of each Knora API v2 response. + */ +object ApiStatusCodesZ { + + /** + * Converts an exception to a suitable HTTP status code. + * + * @param ex an exception. + * @return an HTTP status code. + */ + + def fromExceptionZ(ex: Throwable): Status = + ex match { + // Subclasses of RequestRejectedException + case NotFoundException(_) => Status.NotFound + case ForbiddenException(_) => Status.Forbidden + case BadCredentialsException(_) => Status.Unauthorized + case DuplicateValueException(_) => Status.BadRequest + case OntologyConstraintException(_) => Status.BadRequest + case EditConflictException(_) => Status.Conflict + case BadRequestException(_) => Status.BadRequest + case ValidationException(_, _) => Status.BadRequest + case RequestRejectedException(_) => Status.BadRequest + // RequestRejectedException must be the last one in this group + + // Subclasses of InternalServerException + case UpdateNotPerformedException(_) => Status.Conflict + case TriplestoreTimeoutException(_, _) => Status.GatewayTimeout + case InternalServerException(_) => Status.InternalServerError + // InternalServerException must be the last one in this group + + case _ => Status.InternalServerError + } + +} diff --git a/webapi/src/main/scala/org/knora/webapi/routing/admin/ProjectsRouteZ.scala b/webapi/src/main/scala/org/knora/webapi/routing/admin/ProjectsRouteZ.scala index 479e4419c7..89b4db1afa 100644 --- a/webapi/src/main/scala/org/knora/webapi/routing/admin/ProjectsRouteZ.scala +++ b/webapi/src/main/scala/org/knora/webapi/routing/admin/ProjectsRouteZ.scala @@ -9,8 +9,13 @@ import zio.ZLayer import java.net.URLDecoder +import dsp.errors.BadRequestException +import dsp.errors.InternalServerException +import dsp.errors.KnoraException +import dsp.errors.RequestRejectedException import org.knora.webapi.config.AppConfig import org.knora.webapi.core.AppRouter +import org.knora.webapi.http.handler.ExceptionHandlerZ import org.knora.webapi.messages.admin.responder.projectsmessages.ProjectGetRequestADM import org.knora.webapi.messages.admin.responder.projectsmessages.ProjectGetResponseADM import org.knora.webapi.messages.admin.responder.projectsmessages.ProjectIdentifierADM @@ -20,27 +25,34 @@ final case class ProjectsRouteZ(router: AppRouter, appConfig: AppConfig) { implicit val sender: ActorRef = router.ref implicit val timeout: Timeout = appConfig.defaultTimeoutAsDuration - def route(): HttpApp[Any, Nothing] = - Http.collectZIO[Request] { - - // TODO : Add user authentication and error handling - // Returns a single project identified through the IRI. - case Method.GET -> !! / "admin" / "projects" / "iri" / iri => - for { - user <- ZIO.succeed(KnoraSystemInstances.Users.SystemUser) - iriDecoded <- ZIO.attempt(URLDecoder.decode(iri, "utf-8")).orDie - iriValue <- ProjectIdentifierADM.IriIdentifier - .fromString(iriDecoded) - .toZIO - .orDie - message = ProjectGetRequestADM( - identifier = iriValue, - requestingUser = user - ) - response <- ZIO.fromFuture(_ => router.ref.ask(message)).map(_.asInstanceOf[ProjectGetResponseADM]).orDie - } yield Response.json(response.toJsValue.toString()) - - } + def getProjectByIri(iri: String): ZIO[Any, KnoraException, Response] = + for { + user <- ZIO.succeed(KnoraSystemInstances.Users.SystemUser) + iriDecoded <- + ZIO + .attempt(URLDecoder.decode(iri, "utf-8")) + .orElseFail(BadRequestException(s"Failed to decode IRI $iri")) + iriValue <- ProjectIdentifierADM.IriIdentifier + .fromString(iriDecoded) + .toZIO + message = ProjectGetRequestADM(identifier = iriValue, requestingUser = user) + response <- ZIO.fromFuture(_ => router.ref.ask(message)).map(_.asInstanceOf[ProjectGetResponseADM]).orDie + } yield Response.json(response.toJsValue.toString()) + + val route: HttpApp[Any, Nothing] = + (Http + .collectZIO[Request] { + // TODO : Add user authentication and error handling + // Returns a single project identified through the IRI. + case Method.GET -> !! / "admin" / "projects" / "iri" / iri => + getProjectByIri(iri) + }) + .catchAll { + case RequestRejectedException(e) => + ExceptionHandlerZ.exceptionToJsonHttpResponseZ(e, appConfig) + case InternalServerException(e) => + ExceptionHandlerZ.exceptionToJsonHttpResponseZ(e, appConfig) + } } object ProjectsRouteZ { From 768cff4c228c1e9b039ad95a8b15b5053136e08d Mon Sep 17 00:00:00 2001 From: irinaschubert Date: Wed, 14 Dec 2022 10:11:57 +0100 Subject: [PATCH 31/33] rename files --- .../core/{HttpServerWithZIOHttp.scala => HttpServerZ.scala} | 2 +- webapi/src/main/scala/org/knora/webapi/core/LayersLive.scala | 2 +- .../org/knora/webapi/http/handler/ExceptionHandlerZ.scala | 3 +++ .../scala/org/knora/webapi/http/status/ApiStatusCodesZ.scala | 2 ++ 4 files changed, 7 insertions(+), 2 deletions(-) rename webapi/src/main/scala/org/knora/webapi/core/{HttpServerWithZIOHttp.scala => HttpServerZ.scala} (96%) diff --git a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala b/webapi/src/main/scala/org/knora/webapi/core/HttpServerZ.scala similarity index 96% rename from webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala rename to webapi/src/main/scala/org/knora/webapi/core/HttpServerZ.scala index 287f47b8e0..c8b810a758 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/HttpServerWithZIOHttp.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/HttpServerZ.scala @@ -12,7 +12,7 @@ import org.knora.webapi.config.AppConfig import org.knora.webapi.routing.HealthRouteWithZIOHttp import org.knora.webapi.routing.admin.ProjectsRouteZ -object HttpServerWithZIOHttp { +object HttpServerZ { val routes = HealthRouteWithZIOHttp() diff --git a/webapi/src/main/scala/org/knora/webapi/core/LayersLive.scala b/webapi/src/main/scala/org/knora/webapi/core/LayersLive.scala index c9996f0a47..b094819d48 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/LayersLive.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/LayersLive.scala @@ -56,7 +56,7 @@ object LayersLive { CacheServiceManager.layer, CacheServiceInMemImpl.layer, HttpServer.layer, - HttpServerWithZIOHttp.layer, // this is the new ZIO HTTP server layer + HttpServerZ.layer, // this is the new ZIO HTTP server layer IIIFServiceManager.layer, IIIFServiceSipiImpl.layer, JWTService.layer, diff --git a/webapi/src/main/scala/org/knora/webapi/http/handler/ExceptionHandlerZ.scala b/webapi/src/main/scala/org/knora/webapi/http/handler/ExceptionHandlerZ.scala index de2f3c0f72..b7890917e5 100644 --- a/webapi/src/main/scala/org/knora/webapi/http/handler/ExceptionHandlerZ.scala +++ b/webapi/src/main/scala/org/knora/webapi/http/handler/ExceptionHandlerZ.scala @@ -13,6 +13,9 @@ import dsp.errors.RequestRejectedException import org.knora.webapi.config.AppConfig import org.knora.webapi.http.status.ApiStatusCodesZ +/** + * Migrated from [[org.knora.webapi.http.handler.KnoraExceptionHandler]] + */ object ExceptionHandlerZ { private val GENERIC_INTERNAL_SERVER_ERROR_MESSAGE = "The request could not be completed because of an internal server error." diff --git a/webapi/src/main/scala/org/knora/webapi/http/status/ApiStatusCodesZ.scala b/webapi/src/main/scala/org/knora/webapi/http/status/ApiStatusCodesZ.scala index e1ffdbe8a2..05da7c1095 100644 --- a/webapi/src/main/scala/org/knora/webapi/http/status/ApiStatusCodesZ.scala +++ b/webapi/src/main/scala/org/knora/webapi/http/status/ApiStatusCodesZ.scala @@ -11,6 +11,8 @@ import dsp.errors._ import org.knora.webapi.store.triplestore.errors.TriplestoreTimeoutException /** + * Migrated from [[org.knora.webapi.http.status.ApiStatusCodes]] + * * The possible values for the HTTP status code that is returned as part of each Knora API v2 response. */ object ApiStatusCodesZ { From 40f21ba4cdb05120f70393427088e5adf4c4d8e1 Mon Sep 17 00:00:00 2001 From: irinaschubert Date: Wed, 14 Dec 2022 10:13:51 +0100 Subject: [PATCH 32/33] rename health route --- webapi/src/main/scala/org/knora/webapi/core/HttpServerZ.scala | 4 ++-- .../{HealthRouteWithZIOHttp.scala => HealthRouteZ.scala} | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename webapi/src/main/scala/org/knora/webapi/routing/{HealthRouteWithZIOHttp.scala => HealthRouteZ.scala} (99%) diff --git a/webapi/src/main/scala/org/knora/webapi/core/HttpServerZ.scala b/webapi/src/main/scala/org/knora/webapi/core/HttpServerZ.scala index c8b810a758..e1503581e0 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/HttpServerZ.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/HttpServerZ.scala @@ -9,12 +9,12 @@ import zio.ZLayer import zio._ import org.knora.webapi.config.AppConfig -import org.knora.webapi.routing.HealthRouteWithZIOHttp +import org.knora.webapi.routing.HealthRouteZ import org.knora.webapi.routing.admin.ProjectsRouteZ object HttpServerZ { - val routes = HealthRouteWithZIOHttp() + val routes = HealthRouteZ() val layer: ZLayer[AppRouter & AppConfig & State & ProjectsRouteZ, Nothing, Unit] = ZLayer { diff --git a/webapi/src/main/scala/org/knora/webapi/routing/HealthRouteWithZIOHttp.scala b/webapi/src/main/scala/org/knora/webapi/routing/HealthRouteZ.scala similarity index 99% rename from webapi/src/main/scala/org/knora/webapi/routing/HealthRouteWithZIOHttp.scala rename to webapi/src/main/scala/org/knora/webapi/routing/HealthRouteZ.scala index aa7ac232e4..cd283b735b 100644 --- a/webapi/src/main/scala/org/knora/webapi/routing/HealthRouteWithZIOHttp.scala +++ b/webapi/src/main/scala/org/knora/webapi/routing/HealthRouteZ.scala @@ -16,7 +16,7 @@ import org.knora.webapi.core.domain.AppState /** * Provides the '/healthZ' endpoint serving the health status. */ -object HealthRouteWithZIOHttp { +object HealthRouteZ { def apply(): HttpApp[State, Nothing] = Http.collectZIO[Request] { case Method.GET -> !! / "healthZ" => From 2a0563db61beae2c7ee99bab26247d862db658f2 Mon Sep 17 00:00:00 2001 From: irinaschubert Date: Wed, 14 Dec 2022 10:17:30 +0100 Subject: [PATCH 33/33] add todo --- .../scala/org/knora/webapi/routing/admin/ProjectsRouteZ.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webapi/src/main/scala/org/knora/webapi/routing/admin/ProjectsRouteZ.scala b/webapi/src/main/scala/org/knora/webapi/routing/admin/ProjectsRouteZ.scala index 89b4db1afa..69b1ddc3bb 100644 --- a/webapi/src/main/scala/org/knora/webapi/routing/admin/ProjectsRouteZ.scala +++ b/webapi/src/main/scala/org/knora/webapi/routing/admin/ProjectsRouteZ.scala @@ -42,7 +42,7 @@ final case class ProjectsRouteZ(router: AppRouter, appConfig: AppConfig) { val route: HttpApp[Any, Nothing] = (Http .collectZIO[Request] { - // TODO : Add user authentication and error handling + // TODO : Add user authentication, make tests run with the new route // Returns a single project identified through the IRI. case Method.GET -> !! / "admin" / "projects" / "iri" / iri => getProjectByIri(iri)