Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 30 commits into from Jan 2, 2023

Conversation

seakayone
Copy link
Collaborator

@seakayone seakayone commented Dec 27, 2022

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

@codecov
Copy link

codecov bot commented Dec 27, 2022

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 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
Copy link
Collaborator

@BalduinLandolt BalduinLandolt left a comment

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 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
Collaborator

Choose a reason for hiding this comment

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

Why not keep URLayer?

Copy link
Collaborator

@mpro7 mpro7 left a comment

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.

* 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
Collaborator

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 on lines +93 to +94
* @param name ???
* @param severity ???
Copy link
Collaborator

Choose a reason for hiding this comment

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

???

Copy link

@irinaschubert irinaschubert left a comment

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

*
* ```failure``` A [[BadRequestException]] with the `errorMsg`
*/
def urlDecode(value: String, errorMsg: String = ""): Task[String] =

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?

Copy link
Collaborator Author

@seakayone seakayone Jan 2, 2023

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.")

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}.")

.of[ProjectGetResponseADM]
.apply(Assertion.equalTo(expectedRequest), Expectation.value(expectedResponse))

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

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]

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") {

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") {

final case class RestProjectsService(bridge: ActorToZioBridge) {

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

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.

None yet

4 participants