Skip to content

feat: Expose GET /admin/projects/iri/{iriUrlEncoded} as zio-http route - #2355

Merged
seakayone merged 30 commits into
mainfrom
wip/projectroute-zio
Jan 2, 2023
Merged

seakayone merged 30 commits into
mainfrom
wip/projectroute-zio

Conversation

@seakayone

@seakayone seakayone commented Dec 27, 2022 •

Copy link
Copy Markdown
Contributor

Pull Request Checklist

Task Description/Number

Picking up from the last mob/main session I have finalised the changes from that branch.

Changes include:

  • Expose GET /admin/projects/iri/{iriUrlEncoded} as zio-http route.
  • Remove unused requestingUser field from ProjectGetRequestADM.
  • Add AuthenticatorService - a zio service for interaction with Authenticator as a preparation for other routes.

Basic Requirements

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix: represents bug fixes
  • Refactor: represents production code refactoring
  • Feature: represents a new feature
  • Documentation: documentation changes (no production code change)
  • Chore: maintenance tasks (no production code change)
  • Style: styles updates (no production code change)
  • Test: all about tests: adding, refactoring tests (no production code change)
  • Other... Please describe:

Does this PR introduce a breaking change?

  • Yes
  • No

Does this PR change client-test-data?

  • Yes (don't forget to update the JS-LIB team about the change)
  • No

Christian Kleinbölting added 6 commits December 24, 2022 00:07
@codecov

codecov Bot commented Dec 27, 2022 •

Copy link
Copy Markdown

Codecov Report

Base: 86.68% // Head: 86.45% // Decreases project coverage by -0.22% ⚠️

Coverage data is based on head (aaf8429) compared to base (26e9596).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2355      +/-   ##
==========================================
- Coverage   86.68%   86.45%   -0.23%     
==========================================
  Files         250      271      +21     
  Lines       28252    28270      +18     
==========================================
- Hits        24490    24441      -49     
- Misses       3762     3829      +67     
Impacted Files Coverage Δ
...p-shared/src/main/scala/dsp/valueobjects/Iri.scala 93.93% <100.00%> (+0.12%) ⬆️
...sp-shared/src/main/scala/dsp/valueobjects/V2.scala 90.27% <100.00%> (+0.27%) ⬆️
.../scala/org/knora/webapi/responders/Responder.scala 75.00% <0.00%> (-16.43%) ⬇️
...org/knora/webapi/routing/v2/ResourcesRouteV2.scala 88.27% <0.00%> (-5.79%) ⬇️
.../webapi/messages/util/rdf/jenaimpl/JenaModel.scala 86.42% <0.00%> (-2.86%) ⬇️
...n/scala/org/knora/webapi/routing/RouteUtilV2.scala 64.93% <0.00%> (-1.74%) ⬇️
...la/org/knora/webapi/messages/StringFormatter.scala 88.72% <0.00%> (-0.80%) ⬇️
...api/responders/admin/PermissionsResponderADM.scala 90.16% <0.00%> (-0.04%) ⬇️
...knora/webapi/responders/v1/ValuesResponderV1.scala 92.73% <0.00%> (-0.01%) ⬇️
...ra/webapi/responders/v2/ResourcesResponderV2.scala 93.43% <0.00%> (-0.01%) ⬇️
... and 65 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@seakayone
seakayone force-pushed the wip/projectroute-zio branch 2 times, most recently from b16f9cc to 5600a18 Compare December 27, 2022 14:35
@seakayone
seakayone force-pushed the wip/projectroute-zio branch from 5600a18 to ba8ca55 Compare December 27, 2022 14:43
@seakayone
seakayone force-pushed the wip/projectroute-zio branch from 55a5348 to ad5b367 Compare December 28, 2022 10:12
@seakayone seakayone changed the title Wip/projectroute zio feature: Expose GET /admin/projects/iri/{iriUrlEncoded} as zio-http route Dec 28, 2022
@seakayone
seakayone marked this pull request as ready for review December 28, 2022 11:21
@seakayone seakayone self-assigned this Jan 2, 2023

@BalduinLandolt BalduinLandolt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice to have the authenticator separated out like this!

Some questions/remarks:

  • Why did you rename ProjectsService to RestProjectsService? What are our naming conventions in this regard?
  • Maybe I'm overlooking something... but I think the addition of HealthRouteZ is not reflected in the PR title/description.
  • Otherwise, some comments in the files directly.

Comment thread webapi/src/main/scala/org/knora/webapi/http/status/ApiStatusCodesZ.scala Outdated
Comment thread webapi/src/main/scala/org/knora/webapi/routing/HealthRouteZ.scala
Comment thread webapi/src/main/scala/org/knora/webapi/routing/RouteUtilZ.scala
Comment thread webapi/src/main/scala/org/knora/webapi/routing/RouteUtilZ.scala Outdated
Comment thread webapi/src/main/scala/org/knora/webapi/routing/admin/ProjectsRouteZ.scala Outdated
Comment on lines +55 to +38
val layer: URLayer[ProjectsService with AppConfig, ProjectsRouteZ] = ZLayer.fromFunction(ProjectsRouteZ.apply _)
val layer: ZLayer[AppConfig with RestProjectsService, Nothing, ProjectsRouteZ] =
ZLayer.fromFunction(ProjectsRouteZ.apply _)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not keep URLayer?

@mpro7 mpro7 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to apply my suggestions - mainly Docstrings improvements.

* 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.
* migrated from [[org.knora.webapi.http.status.ApiStatusCodes]]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* migrated from [[org.knora.webapi.http.status.ApiStatusCodes]]
* Migrated from [[org.knora.webapi.http.status.ApiStatusCodes]]

Comment thread webapi/src/main/scala/org/knora/webapi/routing/HealthRouteZ.scala Outdated
Comment thread webapi/src/main/scala/org/knora/webapi/routing/HealthRouteZ.scala Outdated
Comment thread webapi/src/main/scala/org/knora/webapi/routing/HealthRouteZ.scala Outdated
Comment on lines +93 to +94
* @param name ???
* @param severity ???

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

???

@irinaschubert irinaschubert left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just some minor remarks

Comment thread webapi/src/main/scala/org/knora/webapi/routing/RouteUtilZ.scala Outdated
*
* ```failure``` A [[BadRequestException]] with the `errorMsg`
*/
def urlDecode(value: String, errorMsg: String = ""): Task[String] =

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we actually need the second parameter errorMsg?

@seakayone seakayone Jan 2, 2023 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, different Routes might want create their own error messages in the BadRequestException. In this PR it is "Failed to url decode IRI parameter." in the route. I did not want to hardcode that particular message into the RouteUtil as it should not assume that all encoded params are IRIs.

// Returns a single project identified by an urlencoded IRI
case Method.GET -> !! / "admin" / "projects" / "iri" / iriUrlEncoded =>
RouteUtilZ
.urlDecode(iriUrlEncoded, "Failed to url decode IRI parameter.")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.urlDecode(iriUrlEncoded, "Failed to url decode IRI parameter.")
.urlDecode(iriUrlEncoded, s"Failed to URL decode IRI from parameter: ${iriUrlEncoded}.")

.apply(Assertion.equalTo(expectedRequest), Expectation.value(expectedResponse))

private val expectNoInteraction = ActorToZioBridgeMock.empty
private val systemUnderTest = ZIO.service[RestProjectsService]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private val systemUnderTest = ZIO.service[RestProjectsService]
private val serviceUnderTest = ZIO.service[RestProjectsService]

Comment thread webapi/src/test/scala/org/knora/webapi/routing/RouteUtilZSpec.scala Outdated
actual <- RouteUtilZ.urlDecode("http%3A%2F%2Frdfh.ch%2Fprojects%2FLw3FC39BSzCwvmdOaTyLqQ")
} yield assertTrue(actual == "http://rdfh.ch/projects/Lw3FC39BSzCwvmdOaTyLqQ")
},
test("given an empty value should return BadRequestException") {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
test("given an empty value should return BadRequestException") {
test("given an empty valu, return BadRequestException") {

Comment thread webapi/src/test/scala/org/knora/webapi/routing/RouteUtilZSpec.scala Outdated
final case class RestProjectsService(bridge: ActorToZioBridge) {

/**
* Finds the project by its [[ProjectIdentifierADM]] and returns the information as a [[ProjectGetResponseADM]].

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Finds the project by its [[ProjectIdentifierADM]] and returns the information as a [[ProjectGetResponseADM]].
* Finds the project by its [[IRI]] and returns the information as a [[ProjectGetResponseADM]].

@mpro7 mpro7 changed the title feature: Expose GET /admin/projects/iri/{iriUrlEncoded} as zio-http route feat: Expose GET /admin/projects/iri/{iriUrlEncoded} as zio-http route Jan 2, 2023
seakayone and others added 13 commits January 2, 2023 16:30
…desZ.scala

Co-authored-by: Balduin Landolt <33053745+BalduinLandolt@users.noreply.github.com>
Co-authored-by: irinaschubert <irina.schubert@dasch.swiss>
Co-authored-by: Marcin Procyk <marcin.procyk@dasch.swiss>
Co-authored-by: Marcin Procyk <marcin.procyk@dasch.swiss>
Co-authored-by: Marcin Procyk <marcin.procyk@dasch.swiss>
…scala

Co-authored-by: irinaschubert <irina.schubert@dasch.swiss>
…scala

Co-authored-by: irinaschubert <irina.schubert@dasch.swiss>
@seakayone
seakayone merged commit 2f42906 into main Jan 2, 2023
@seakayone
seakayone deleted the wip/projectroute-zio branch January 2, 2023 22:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants