Skip to content

Commit

Permalink
#1693 Future {throw x} replaced with Future.failed(x) in rest_api…
Browse files Browse the repository at this point in the history
…, cleanup
  • Loading branch information
dk1844 committed May 18, 2022
1 parent e593df1 commit 34292c4
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class DatasetController @Autowired()(datasetService: DatasetService)
case Some((ds, validation)) => ds // v2 disregarding validation
case _ => throw notFound()
}
case _ => throw notFound()
case _ => Future.failed(notFound())
}
} yield res
}
Expand Down Expand Up @@ -104,7 +104,7 @@ class DatasetController @Autowired()(datasetService: DatasetService)
} else {
datasetService.filterProperties(dsProperties, DatasetController.paramsToPropertyDefinitionFilter(scalaFilterMap))
}
case None => throw notFound()
case None => Future.failed(notFound())
}
}

Expand All @@ -126,7 +126,7 @@ class DatasetController @Autowired()(datasetService: DatasetService)
def getPropertiesValidation(@PathVariable datasetName: String, @PathVariable datasetVersion: Int): CompletableFuture[Validation] = {
datasetService.getVersion(datasetName, datasetVersion).flatMap {
case Some(entity) => datasetService.validateProperties(entity.propertiesAsMap, forRun = false)
case None => throw notFound()
case None => Future.failed(notFound())
}
}

Expand All @@ -135,7 +135,7 @@ class DatasetController @Autowired()(datasetService: DatasetService)
def getPropertiesValidationForRun(@PathVariable datasetName: String, @PathVariable datasetVersion: Int): CompletableFuture[Validation] = {
datasetService.getVersion(datasetName, datasetVersion).flatMap {
case Some(entity) => datasetService.validateProperties(entity.propertiesAsMap, forRun = true)
case None => throw notFound()
case None => Future.failed(notFound())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
package za.co.absa.enceladus.rest_api.controllers

import java.util.concurrent.CompletableFuture

import org.apache.hadoop.fs.Path
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.HttpStatus
import org.springframework.web.bind.annotation._
import za.co.absa.enceladus.model.menas.HDFSFolder
import za.co.absa.enceladus.rest_api.services.HDFSService

import scala.concurrent.Future

@RestController
@RequestMapping(Array("/api/hdfs"))
class HDFSController @Autowired() (hdfsService: HDFSService) extends BaseController {
Expand All @@ -41,7 +42,7 @@ class HDFSController @Autowired() (hdfsService: HDFSService) extends BaseControl
if (exists) {
hdfsService.getFolder(path)
} else {
throw notFound()
Future.failed(notFound())
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ 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
import scala.concurrent.Future

@RestController
@RequestMapping(path = Array("/api-v3/datasets"))
Expand Down Expand Up @@ -57,14 +58,12 @@ class DatasetControllerV3 @Autowired()(datasetService: DatasetServiceV3)
case Some((entity, validation)) =>
// stripping last 3 segments (/dsName/dsVersion/properties), instead of /api-v3/dastasets/dsName/dsVersion/properties we want /api-v3/dastasets/dsName/dsVersion/properties
createdWithNameVersionLocationBuilder(entity.name, entity.version, request, stripLastSegments = 3, suffix = "/properties")
.body(validation) // todo include in tests
.body(validation)
case None => throw notFound()
}
}
}

// todo putIntoInfoFile switch needed?

@GetMapping(Array("/{name}/{version}/rules"))
@ResponseStatus(HttpStatus.OK)
def getConformanceRules(@PathVariable name: String,
Expand All @@ -90,7 +89,7 @@ class DatasetControllerV3 @Autowired()(datasetService: DatasetServiceV3)
suffix = s"/rules/$addedRuleOrder").body(validation)
case _ => throw notFound()
}
case None => throw notFound()
case None => Future.failed(notFound())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ abstract class VersionedModelControllerV3[C <: VersionedModel with Product

import scala.concurrent.ExecutionContext.Implicits.global

// todo maybe offset/limit?
// todo maybe offset/limit -> Issue #2060
@GetMapping(Array(""))
@ResponseStatus(HttpStatus.OK)
def getList(@RequestParam searchQuery: Optional[String]): CompletableFuture[Seq[NamedVersion]] = {
Expand All @@ -59,7 +59,7 @@ abstract class VersionedModelControllerV3[C <: VersionedModel with Product
@GetMapping(Array("/{name}"))
@ResponseStatus(HttpStatus.OK)
def getVersionSummaryForEntity(@PathVariable name: String): CompletableFuture[NamedVersion] = {
versionedModelService.getLatestVersionSummary(name) map {
versionedModelService.getLatestVersionSummary(name).map {
case Some(entity) => entity.toNamedVersion
case None => throw notFound()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@

package za.co.absa.enceladus.rest_api.exceptions

// todo, there is no usage, remove?
case class EndpointDisabledException(message:String = "", cause: Throwable = None.orNull) extends Exception(message, cause)

0 comments on commit 34292c4

Please sign in to comment.