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

Feature/1693 api v3 versioned model - Dataset v3 implementation #2046

Merged
merged 34 commits into from
May 9, 2022
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
f1798b2
#1693 API v3: VersionedModel v3 init - VersionedModelControllerV3 bas…
dk1844 Mar 7, 2022
0f62851
#1693 API v3: some basic VersionedModelControllerV3 integration test
dk1844 Mar 7, 2022
c01cfda
#1693 API v3: VersionedModelControllerV3 integration test cont'd - te…
dk1844 Mar 8, 2022
4fd08e2
#1693 API v3: VersionedModelControllerV3 - post to yield location hea…
dk1844 Mar 21, 2022
5c8e005
#1693 API v3: VersionedModelControllerV3 - put to yield no content ->…
dk1844 Mar 23, 2022
458bfed
#1693 API v3: VersionedModelControllerV3 - IT for /ds/export (latest …
dk1844 Mar 23, 2022
a7a6cf9
#1693 API v3: VersionedModelControllerV3 - location header for put/po…
dk1844 Mar 23, 2022
af489b1
#1693 API v3: VersionedModelControllerV3 - location header for post-i…
dk1844 Mar 24, 2022
21f8008
#1693 API v3: VersionedModelControllerV3 -IT for GET datasets/{name},…
dk1844 Mar 24, 2022
6f63117
#1693 API v3: VersionedModelControllerV3 - IT for GET datasets/{name}…
dk1844 Mar 24, 2022
76e87ce
#1693 API v3: VersionedModelControllerV3 - GET /datasets/{name}/{vers…
dk1844 Mar 24, 2022
d62cd90
#1693 API v3: VersionedModelControllerV3 - common implementation of /…
dk1844 Mar 24, 2022
fc4c359
#1693 API v3: VersionedModelControllerV3 - /{name}/{version}/used-in …
dk1844 Mar 24, 2022
e6c8d8c
#1693 API v3: VersionedModelControllerV3 - GET/PUT /{name}/{version}/…
dk1844 Mar 29, 2022
3566df5
#1693 API v3: VersionedModelControllerV3 - GET/PUT /{name}/{version}/…
dk1844 Mar 30, 2022
219360a
#1693 Fix: (v2) VersionedModelController.getLatestVersionNumber(): Fu…
dk1844 Mar 30, 2022
112ac1e
#1693 VersionedModelControllerV3: `/{name}/{version}/validation` impl…
dk1844 Mar 30, 2022
101b37a
#1693 VersionedModelControllerV3 - IT extended for `POST /{name}/{ver…
dk1844 Mar 31, 2022
b934958
#1693 VersionedModelControllerV3 - conformance rule mgmt GET+POST dat…
dk1844 Apr 1, 2022
51ad013
#1693 PR review update - typos etc
dk1844 Apr 6, 2022
ba5edce
#1693 Validation-warnings as payload to caller in V3
dk1844 Apr 6, 2022
662119b
#1693 Validation-warnings as payload to caller in V3 - IT covered
dk1844 Apr 7, 2022
d480445
#1693 import validation check added to IT.
dk1844 Apr 7, 2022
3542a43
Merge branch 'develop-ver-3.0' into feature/1693-api-v3-versioned-model
dk1844 Apr 7, 2022
d6ef401
#1693 schema validation for DSs + IntegTest update
dk1844 Apr 11, 2022
a75ab85
#1693 Mt existence check for DS rules + reflecting in integTest
dk1844 Apr 11, 2022
9241eb1
Merge branch 'develop-ver-3.0' into feature/1693-api-v3-versioned-model
dk1844 Apr 14, 2022
09c326e
#1693 PR review update 1
dk1844 Apr 28, 2022
1c241d1
#1693 DatasetService.updateProperties[V3] -> split between DatasetSer…
dk1844 May 3, 2022
5d24819
#1693 PR review update: VersionedModelControllerV3 - GET /{name}/expo…
dk1844 May 4, 2022
7040694
#1693 VersionedMongoRepository - unused method `getAllVersionsValues`…
dk1844 May 4, 2022
e0fda73
#1693 for V3 API: VersionedSummary -> NamedLatestVersion: impl + IT
dk1844 May 4, 2022
a80d9ac
#1693 Swagger differs in paths based on `spring.profiles.active` bein…
dk1844 May 6, 2022
562da60
#1693 Swagger API: dev-profile: full v2+v3 API, non-dev: full v3 API
dk1844 May 9, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@
package za.co.absa.enceladus.model.versionedModel

case class VersionedSummary(_id: String, latestVersion: Int)
Zejnilovic marked this conversation as resolved.
Show resolved Hide resolved

benedeki marked this conversation as resolved.
Show resolved Hide resolved
case class VersionsList(_id: String, versions: Seq[Int])
AdrianOlosutean marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,17 @@ class SpringFoxConfig extends ProjectMetadata {
}

private def filteredPaths: Predicate[String] =
or[String](regex("/api/dataset.*"), regex("/api/schema.*"),
or[String](
// api v2
regex("/api/dataset.*"), regex("/api/schema.*"),
regex("/api/mappingTable.*"), regex("/api/properties.*"),
regex("/api/monitoring.*"),regex("/api/runs.*"),
regex("/api/user.*"), regex("/api/spark.*"),
regex("/api/configuration.*")
regex("/api/configuration.*"),

// api v3
regex("/api-v3/datasets.*")
dk1844 marked this conversation as resolved.
Show resolved Hide resolved

)

private def apiInfo =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class DatasetController @Autowired()(datasetService: DatasetService)
def replaceProperties(@AuthenticationPrincipal principal: UserDetails,
@PathVariable datasetName: String,
@RequestBody newProperties: Optional[Map[String, String]]): CompletableFuture[ResponseEntity[Option[Dataset]]] = {
datasetService.replaceProperties(principal.getUsername, datasetName, newProperties.toScalaOption).map {
datasetService.updatePropertiesV2(principal.getUsername, datasetName, newProperties.toScalaOption).map {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess the V2 and V3 suffixes are because of Spring autowiring?
(Looks ugly to me, to be honest 😄 )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, this has nothing to do with spring autowiring. This is just a way to have V2 and V3 implementation in some services so that the v2 version can be removed easily when only v3 is to stay.

If we want to keep v2 and v3 long-term, this would require to create separate services, e.g. datasetService and datasetServiceV3. One of these solutions is, I believe, necessary if you want to keep the original implementation working.

It then begs the question - what is the intended lifetime of V2 API? Knowing this better, it could help to design better: copy-paste-and-change-a-few-things knowing that the V2 impl will be gone soon vs. keeping v3 extending v2 (no code duplication, but harder removal)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The v3 method moved to DatasetServiceV3, so now it is tidier. Thanks for the tip, @benedeki.

case None => throw notFound()
case Some(dataset) =>
val location: URI = new URI(s"/api/dataset/${dataset.name}/${dataset.version}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ class RestExceptionHandler {

private val logger = LoggerFactory.getLogger(this.getClass)

@ExceptionHandler(value = Array(classOf[IllegalArgumentException]))
def handleIllegalArgumentException(exception: IllegalArgumentException): ResponseEntity[Any] = {
ResponseEntity.badRequest().body(exception.getMessage)
}

@ExceptionHandler(value = Array(classOf[AsyncRequestTimeoutException]))
def handleAsyncRequestTimeoutException(exception: AsyncRequestTimeoutException): ResponseEntity[Any] = {
val message = Option(exception.getMessage).getOrElse("Request timeout expired.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package za.co.absa.enceladus.rest_api.controllers

import java.util.Optional
import java.util.concurrent.CompletableFuture

import com.mongodb.client.result.UpdateResult
import org.springframework.http.HttpStatus
import org.springframework.security.core.annotation.AuthenticationPrincipal
Expand All @@ -29,6 +28,8 @@ import za.co.absa.enceladus.rest_api.exceptions.NotFoundException
import za.co.absa.enceladus.rest_api.services.VersionedModelService
import za.co.absa.enceladus.model.menas.audit._

import scala.concurrent.Future

abstract class VersionedModelController[C <: VersionedModel with Product with Auditable[C]](versionedModelService: VersionedModelService[C])
extends BaseController {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* Copyright 2018 ABSA Group Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package za.co.absa.enceladus.rest_api.controllers.v3

import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.{HttpStatus, ResponseEntity}
import org.springframework.security.core.annotation.AuthenticationPrincipal
import org.springframework.security.core.userdetails.UserDetails
import org.springframework.web.bind.annotation._
import za.co.absa.enceladus.model.Dataset
import za.co.absa.enceladus.model.conformanceRule.ConformanceRule
import za.co.absa.enceladus.rest_api.services.v3.DatasetServiceV3
import za.co.absa.enceladus.rest_api.utils.implicits._

import java.util.concurrent.CompletableFuture
import javax.servlet.http.HttpServletRequest
import scala.concurrent.ExecutionContext.Implicits.global

@RestController
@RequestMapping(path = Array("/api-v3/datasets"))
class DatasetControllerV3 @Autowired()(datasetService: DatasetServiceV3)
extends VersionedModelControllerV3(datasetService) {

@GetMapping(Array("/{name}/{version}/properties"))
@ResponseStatus(HttpStatus.OK)
def getAllPropertiesForVersion(@PathVariable name: String,
@PathVariable version: String): CompletableFuture[Map[String, String]] = {
forVersionExpression(name, version)(datasetService.getVersion).map {
case Some(entity) => entity.propertiesAsMap
case None => throw notFound()
}
}

@PutMapping(Array("/{name}/{version}/properties"))
@ResponseStatus(HttpStatus.OK)
def updateProperties(@AuthenticationPrincipal principal: UserDetails,
@PathVariable name: String,
@PathVariable version: String,
@RequestBody newProperties: java.util.Map[String, String],
request: HttpServletRequest): CompletableFuture[ResponseEntity[Nothing]] = {
forVersionExpression(name, version) { case (dsName, dsVersion) =>
datasetService.updateProperties(principal.getUsername, dsName, dsVersion, newProperties.toScalaMap).map {

case Some(entity) =>
// stripping last 3 segments (/dsName/dsVersion/properties), instead of /api-v3/dastasets/dsName/dsVersion/properties we want /api-v3/dastasets/dsName/dsVersion/properties
createdWithNameVersionLocation(entity.name, entity.version, request, stripLastSegments = 3, suffix = "/properties")
case None => throw notFound()
}
}
}

// todo putIntoInfoFile switch needed?

@GetMapping(Array("/{name}/{version}/rules"))
@ResponseStatus(HttpStatus.OK)
def getConformanceRules(@PathVariable name: String,
@PathVariable version: String): CompletableFuture[Seq[ConformanceRule]] = {
forVersionExpression(name, version)(datasetService.getVersion).map {
case Some(entity) => entity.conformance
case None => throw notFound()
}
}

@PostMapping(Array("/{name}/{version}/rules"))
@ResponseStatus(HttpStatus.CREATED)
def addConformanceRule(@AuthenticationPrincipal user: UserDetails,
@PathVariable name: String,
@PathVariable version: String,
@RequestBody rule: ConformanceRule,
request: HttpServletRequest): CompletableFuture[ResponseEntity[Nothing]] = {
forVersionExpression(name, version)(datasetService.getVersion).flatMap {
case Some(entity) => datasetService.addConformanceRule(user.getUsername, name, entity.version, rule).map {
case Some(updatedDs) =>
val addedRuleOrder = updatedDs.conformance.last.order
createdWithNameVersionLocation(name, updatedDs.version, request, stripLastSegments = 3, // strip: /{name}/{version}/rules
suffix = s"/rules/$addedRuleOrder")
case _ => throw notFound()
}
case None => throw notFound()
}
}

@GetMapping(Array("/{name}/{version}/rules/{order}"))
@ResponseStatus(HttpStatus.OK)
def getConformanceRuleByOrder(@PathVariable name: String,
@PathVariable version: String,
@PathVariable order: Int): CompletableFuture[ConformanceRule] = {
for {
optDs <- forVersionExpression(name, version)(datasetService.getVersion)
ds = optDs.getOrElse(throw notFound())
rule = ds.conformance.find(_.order == order).getOrElse(throw notFound())
} yield rule
}

}


Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
/*
* Copyright 2018 ABSA Group Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package za.co.absa.enceladus.rest_api.controllers.v3

import com.mongodb.client.result.UpdateResult
import org.springframework.http.{HttpStatus, ResponseEntity}
import org.springframework.security.core.annotation.AuthenticationPrincipal
import org.springframework.security.core.userdetails.UserDetails
import org.springframework.web.bind.annotation._
import org.springframework.web.servlet.support.ServletUriComponentsBuilder
import za.co.absa.enceladus.model.menas.audit._
import za.co.absa.enceladus.model.versionedModel._
import za.co.absa.enceladus.model.{ExportableObject, UsedIn, Validation}
import za.co.absa.enceladus.rest_api.controllers.BaseController
import za.co.absa.enceladus.rest_api.controllers.v3.VersionedModelControllerV3.LatestVersionKey
import za.co.absa.enceladus.rest_api.services.VersionedModelService

import java.net.URI
import java.util
import java.util.Optional
import java.util.concurrent.CompletableFuture
import javax.servlet.http.HttpServletRequest
import scala.concurrent.Future
import scala.util.{Failure, Success, Try}

abstract class VersionedModelControllerV3[C <: VersionedModel with Product
with Auditable[C]](versionedModelService: VersionedModelService[C]) extends BaseController {

import za.co.absa.enceladus.rest_api.utils.implicits._

import scala.concurrent.ExecutionContext.Implicits.global

// todo maybe offset/limit?
@GetMapping(Array(""))
@ResponseStatus(HttpStatus.OK)
def getList(@RequestParam searchQuery: Optional[String]): CompletableFuture[Seq[VersionedSummary]] = {
versionedModelService.getLatestVersionsSummary(searchQuery.toScalaOption)
}

@GetMapping(Array("/{name}"))
@ResponseStatus(HttpStatus.OK)
def getVersionsList(@PathVariable name: String): CompletableFuture[VersionsList] = {
versionedModelService.getAllVersionsValues(name) map {
case Some(entity) => entity
case None => throw notFound()
}
}

@GetMapping(Array("/{name}/{version}"))
@ResponseStatus(HttpStatus.OK)
def getVersionDetail(@PathVariable name: String,
@PathVariable version: String): CompletableFuture[C] = {
forVersionExpression(name, version)(versionedModelService.getVersion).map {
case Some(entity) => entity
case None => throw notFound()
}
}


@GetMapping(Array("/{name}/audit-trail"))
@ResponseStatus(HttpStatus.OK)
def getAuditTrail(@PathVariable name: String): CompletableFuture[AuditTrail] = {
versionedModelService.getAuditTrail(name)
}

@GetMapping(Array("/{name}/{version}/used-in"))
Copy link
Contributor

Choose a reason for hiding this comment

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

Does a global used-in make sense since Dataset does not need it? I think this should be specific for the entity.

Copy link
Contributor Author

@dk1844 dk1844 May 4, 2022

Choose a reason for hiding this comment

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

Here, I think it makes sense to keep it.

Since the disable is available for all entity types, so should used-in. The nice thing about it is that there can be a common approach to entities:

  1. making sure that there is anything preventing from disabling (used-in)
  2. dealing with linked references returned by used-in if any
  3. disabling the entity knowing that it should succeed (without surprises)

It is quite reassuring for the API user to be able to call used-in even if currently for a certain type there cannot be any entity linked, it perhaps may be in the future?

All in all, I am a fan of having used-ins everywhere (where disable is).

@ResponseStatus(HttpStatus.OK)
def usedIn(@PathVariable name: String,
@PathVariable version: String): CompletableFuture[UsedIn] = {
forVersionExpression(name, version) { case (name, versionInt) => versionedModelService.getUsedIn(name, Some(versionInt)) }
}

@GetMapping(Array("/{name}/{version}/export"))
@ResponseStatus(HttpStatus.OK)
def exportSingleEntity(@PathVariable name: String, @PathVariable version: String): CompletableFuture[String] = {
forVersionExpression(name, version)(versionedModelService.exportSingleItem)
}

@GetMapping(Array("/{name}/export"))
@ResponseStatus(HttpStatus.OK)
def exportLatestEntity(@PathVariable name: String): CompletableFuture[String] = {
versionedModelService.exportLatestItem(name) // todo: remove in favor of the above? (that supports /{name}/latest/export)
Copy link
Contributor

Choose a reason for hiding this comment

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

From my point of view, this can stay

Copy link
Contributor Author

@dk1844 dk1844 Apr 6, 2022

Choose a reason for hiding this comment

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

Well, this is part of the v3 API outline. I consider this misleading, because since you have the option to export specific versions already ( at .../{model}/{name}/{versionEitherNumberOrLatestKeyword}/export, having the option for export here would have to have another meaning - e.g. export the whole entity with all the versions. But since this is designed as the latest export as well, I consider this unnecessary, and as I said, even misleading.

That is why I am proposing to omit this endpoint entirely.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that if we gave the "latest" version we can omit this.

Another point to think about can be - export/import being on the entity itself. Export having parameters of name and version.

Copy link
Contributor Author

@dk1844 dk1844 May 4, 2022

Choose a reason for hiding this comment

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

After even further discussion, I have decided to remove the endpoint based on the following logic:

The structure of API endpoints representing a collection should, in general, behave in the following fashion:

  • GET /entityNameInPlural -> list items or provide information about all/more items
  • GET /entityNameInPlural/individualEntityKeyEgId -> give information about a specific entity

By that logic, GET /{name}/export would be appropriate if all entities or information about all/more was returned -- perhaps all versions, while GET /{name}/{version}/export would export just a single version.

But since we mapped just the single version (the latest one) export to a collection's endpoint, the logic does not fit. Moreover, given the fact that we also accept latest as a valid version identifier, it seem much more appropriate to use GET /{name}/{version}/export here (specifically GET /{name}/latest/export)

}

@PostMapping(Array("/{name}/import"))
@ResponseStatus(HttpStatus.CREATED)
def importSingleEntity(@AuthenticationPrincipal principal: UserDetails,
@PathVariable name: String,
@RequestBody importObject: ExportableObject[C],
request: HttpServletRequest): CompletableFuture[ResponseEntity[Nothing]] = {
if (name != importObject.item.name) {
Future.failed(new IllegalArgumentException(s"URL and payload entity name mismatch: '$name' != '${importObject.item.name}'"))
Zejnilovic marked this conversation as resolved.
Show resolved Hide resolved
} else {
versionedModelService.importSingleItem(importObject.item, principal.getUsername, importObject.metadata).map {
case Some(entity) =>
// stripping two last segments, instead of /api-v3/dastasets/dsName/import + /dsName/dsVersion we want /api-v3/dastasets + /dsName/dsVersion
createdWithNameVersionLocation(entity.name, entity.version, request, stripLastSegments = 2)
case None => throw notFound()
}
}
}

@GetMapping(Array("/{name}/{version}/validation"))
@ResponseStatus(HttpStatus.OK)
def validation(@PathVariable name: String,
@PathVariable version: String): CompletableFuture[Validation] = {
forVersionExpression(name, version)(versionedModelService.validate)
}

@PostMapping(Array(""))
@ResponseStatus(HttpStatus.CREATED)
def create(@AuthenticationPrincipal principal: UserDetails,
@RequestBody item: C,
request: HttpServletRequest): CompletableFuture[ResponseEntity[Nothing]] = {
versionedModelService.isDisabled(item.name).flatMap { isDisabled =>
if (isDisabled) {
versionedModelService.recreate(principal.getUsername, item)
} else {
versionedModelService.create(item, principal.getUsername)
}
}.map {
case Some(entity) => createdWithNameVersionLocation(entity.name, entity.version, request)
case None => throw notFound()
}
}

@PutMapping(Array("/{name}/{version}"))
@ResponseStatus(HttpStatus.NO_CONTENT)
def edit(@AuthenticationPrincipal user: UserDetails,
@PathVariable name: String,
@PathVariable version: Int,
@RequestBody item: C,
request: HttpServletRequest): CompletableFuture[ResponseEntity[Nothing]] = {

if (name != item.name) {
Future.failed(new IllegalArgumentException(s"URL and payload entity name mismatch: '$name' != '${item.name}'"))
} else if (version != item.version) {
Future.failed(new IllegalArgumentException(s"URL and payload version mismatch: ${version} != ${item.version}"))
} else {
versionedModelService.update(user.getUsername, item).map {
case Some(entity) => createdWithNameVersionLocation(entity.name, entity.version, request, stripLastSegments = 2)
case None => throw notFound()
}
}
}

@DeleteMapping(Array("/{name}", "/{name}/{version}"))
@ResponseStatus(HttpStatus.OK)
def disable(@PathVariable name: String,
@PathVariable version: Optional[String]): CompletableFuture[UpdateResult] = {
val v = if (version.isPresent) {
// For some reason Spring reads the Optional[Int] param as a Optional[String] and then throws ClassCastException
Some(version.get.toInt)
} else {
None
}
versionedModelService.disableVersion(name, v)
}

/**
* For entity's name and version expression (either a number or 'latest'), the forVersionFn is called.
*
* @param name
* @param versionStr
* @param forVersionFn
* @return
*/
protected def forVersionExpression[T](name: String, versionStr: String)
(forVersionFn: (String, Int) => Future[T]): Future[T] = {
versionStr.toLowerCase match {
case LatestVersionKey =>
versionedModelService.getLatestVersionValue(name).flatMap {
case None => Future.failed(notFound())
case Some(actualLatestVersion) => forVersionFn(name, actualLatestVersion)
}
case nonLatestVersionString => Try(nonLatestVersionString.toInt) match {
case Success(actualVersion) => forVersionFn(name, actualVersion)
case Failure(exception) =>
Future.failed(new IllegalArgumentException(s"Cannot convert '$versionStr' to a valid version expression. " +
s"Either use 'latest' or an actual version number. Underlying problem: ${exception.getMessage}"))
}
}
}

protected def createdWithNameVersionLocation(name: String, version: Int, request: HttpServletRequest,
stripLastSegments: Int = 0, suffix: String = ""): ResponseEntity[Nothing] = {
val strippingPrefix = Range(0, stripLastSegments).map(_ => "/..").mkString

val location: URI = ServletUriComponentsBuilder.fromRequest(request)
.path(s"$strippingPrefix/{name}/{version}$suffix")
.buildAndExpand(name, version.toString)
.normalize() // will normalize `/one/two/../three` into `/one/tree`
.toUri() // will create location e.g. http:/domain.ext/api-v3/dataset/MyExampleDataset/1
Zejnilovic marked this conversation as resolved.
Show resolved Hide resolved

// hint on "/.." + normalize https://github.com/spring-projects/spring-framework/issues/14905#issuecomment-453400918

ResponseEntity.created(location).build()
}

}

object VersionedModelControllerV3 {
Zejnilovic marked this conversation as resolved.
Show resolved Hide resolved
val LatestVersionKey = "latest"
}
Loading