Skip to content

Commit

Permalink
#1693 API v3: VersionedModelControllerV3 - /{name}/{version}/used-in …
Browse files Browse the repository at this point in the history
…- supports latest for as version-expression, impl for datasets improved by actual existence checking + IT test cases for non-existing/non-latest queries
  • Loading branch information
dk1844 committed Mar 24, 2022
1 parent d62cd90 commit fc4c359
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ abstract class VersionedModelControllerV3[C <: VersionedModel with Product
}



@GetMapping(Array("/{name}/audit-trail"))
@ResponseStatus(HttpStatus.OK)
def getAuditTrail(@PathVariable name: String): CompletableFuture[AuditTrail] = {
Expand All @@ -80,8 +79,8 @@ abstract class VersionedModelControllerV3[C <: VersionedModel with Product
@GetMapping(Array("/{name}/{version}/used-in"))
@ResponseStatus(HttpStatus.OK)
def usedIn(@PathVariable name: String,
@PathVariable version: Int): CompletableFuture[UsedIn] = {
versionedModelService.getUsedIn(name, Some(version)) // todo use forVersionExpression, too
@PathVariable version: String): CompletableFuture[UsedIn] = {
forVersionExpression(name, version) { case (name, versionInt) => versionedModelService.getUsedIn(name, Some(versionInt)) }
}

@GetMapping(Array("/{name}/{version}/export"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import za.co.absa.enceladus.model.properties.essentiality.Mandatory
import za.co.absa.enceladus.model.{Dataset, Schema, UsedIn, Validation}
import za.co.absa.enceladus.utils.validation.ValidationLevel
import DatasetService._
import za.co.absa.enceladus.rest_api.exceptions.NotFoundException
import za.co.absa.enceladus.utils.validation.ValidationLevel.ValidationLevel

import scala.concurrent.Future
Expand Down Expand Up @@ -93,7 +94,15 @@ class DatasetService @Autowired()(datasetMongoRepository: DatasetMongoRepository
}

override def getUsedIn(name: String, version: Option[Int]): Future[UsedIn] = {
Future.successful(UsedIn())
val existingEntityF = version match {
case Some(version) => getVersion(name, version)
case None => getLatestVersion(name)
}

existingEntityF.flatMap {
case Some(_) => Future.successful(UsedIn()) // empty usedIn for existing datasets
case None => Future.failed(NotFoundException(s"Dataset '$name' in version ${version.getOrElse("any")}' nof found"))
}
}

override def create(newDataset: Dataset, username: String): Future[Option[Dataset]] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import za.co.absa.enceladus.model.properties.essentiality.Essentiality._
import za.co.absa.enceladus.model.properties.propertyType.{EnumPropertyType, PropertyType, StringPropertyType}
import za.co.absa.enceladus.model.test.factories.{DatasetFactory, PropertyDefinitionFactory, SchemaFactory}
import za.co.absa.enceladus.model.versionedModel.VersionsList
import za.co.absa.enceladus.model.{Dataset, Validation}
import za.co.absa.enceladus.model.{Dataset, UsedIn, Validation}
import za.co.absa.enceladus.rest_api.integration.fixtures._
import za.co.absa.enceladus.rest_api.integration.controllers.{BaseRestApiTest, BaseRestApiTestV3, toExpected}

Expand Down Expand Up @@ -466,7 +466,50 @@ class DatasetControllerV3IntegrationSuite extends BaseRestApiTestV3 with BeforeA
}
}
}
}

s"GET $apiUrl/{name}/{version}/export" should {
"return 404" when {
"when the dataset of latest version does not exist" in {
val response = sendGet[String](s"$apiUrl/notFoundDataset/latest/used-in")
assertNotFound(response)
}
}

"return 404" when {
"when the dataset of name/version does not exist" in {
val datasetA = DatasetFactory.getDummyDataset(name = "datasetA")
datasetFixture.add(datasetA)

val response = sendGet[String](s"$apiUrl/notFoundDataset/1/used-in")
assertNotFound(response)

val response2 = sendGet[String](s"$apiUrl/datasetA/7/used-in")
assertNotFound(response2)
}
}

"return 200" when {
"any exiting latest dataset" in {
val datasetA = DatasetFactory.getDummyDataset(name = "datasetA")
datasetFixture.add(datasetA)
val response = sendGet[UsedIn](s"$apiUrl/datasetA/latest/used-in")
assertOk(response)

response.getBody shouldBe UsedIn(None, None)
}
}

"return 200" when {
"for existing name+version for dataset" in {
val dataset2 = DatasetFactory.getDummyDataset(name = "dataset", version = 2)
datasetFixture.add(dataset2)
val response = sendGet[UsedIn](s"$apiUrl/dataset/2/used-in")

assertOk(response)
response.getBody shouldBe UsedIn(None, None)
}
}
}

// todo properties test for datasets or in general for any VersionedModel
Expand Down

0 comments on commit fc4c359

Please sign in to comment.