From daa1a16915181e249ae4f852bf69d4efb2935c77 Mon Sep 17 00:00:00 2001 From: AB019TC Date: Tue, 19 Mar 2024 10:54:26 +0200 Subject: [PATCH] Fixes #120 - Changed measures function definitions --- .../runs/V1.5.12_get_partitioning_additional_data.sql | 2 +- .../api/controller/PartitioningController.scala | 5 +++++ .../runs/functions/GetPartitioningMeasures.scala | 11 +++++------ .../api/repository/PartitioningRepository.scala | 6 +++--- .../atum/server/api/service/PartitioningService.scala | 5 +++-- 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/database/src/main/postgres/runs/V1.5.12_get_partitioning_additional_data.sql b/database/src/main/postgres/runs/V1.5.12_get_partitioning_additional_data.sql index 96de51b93..3a776a564 100644 --- a/database/src/main/postgres/runs/V1.5.12_get_partitioning_additional_data.sql +++ b/database/src/main/postgres/runs/V1.5.12_get_partitioning_additional_data.sql @@ -24,7 +24,7 @@ CREATE OR REPLACE FUNCTION runs.get_partitioning_additional_data( $$ ------------------------------------------------------------------------------- -- --- Function: runs.get_partitioning_additional_data(2) +-- Function: runs.get_partitioning_additional_data(1) -- Returns additional data for the given partitioning -- -- Parameters: diff --git a/server/src/main/scala/za/co/absa/atum/server/api/controller/PartitioningController.scala b/server/src/main/scala/za/co/absa/atum/server/api/controller/PartitioningController.scala index da1430404..ce4cf3398 100644 --- a/server/src/main/scala/za/co/absa/atum/server/api/controller/PartitioningController.scala +++ b/server/src/main/scala/za/co/absa/atum/server/api/controller/PartitioningController.scala @@ -22,6 +22,7 @@ import za.co.absa.atum.server.api.service.PartitioningService import za.co.absa.atum.server.model.{ErrorResponse, GeneralErrorResponse, InternalServerErrorResponse} import zio._ import zio.macros.accessible +import zio.prelude.data.Optional.AllValuesAreNullable @accessible trait PartitioningController { @@ -39,8 +40,12 @@ class PartitioningControllerImpl(partitioningService: PartitioningService) exten case Left(statusException) => ZIO.fail(GeneralErrorResponse(s"(${statusException.status.statusCode}) ${statusException.status.statusText}")) case Right(_) => +// partitioningService.getPartitioningMeasures(partitioning) +// .flatMap { measures => ZIO.succeed(AtumContextDTO) } + ZIO.succeed { val measures: Set[MeasureDTO] = partitioningService.getPartitioningMeasures(partitioning) + .flatMap(measures => ZIO.succeed(measures)).getOrElse(Set.empty[MeasureDTO]) val additionalData = AdditionalDataDTO(additionalData = Map.empty) AtumContextDTO(partitioning.partitioning, measures, additionalData) } diff --git a/server/src/main/scala/za/co/absa/atum/server/api/database/runs/functions/GetPartitioningMeasures.scala b/server/src/main/scala/za/co/absa/atum/server/api/database/runs/functions/GetPartitioningMeasures.scala index e06854866..2cbc7efcf 100644 --- a/server/src/main/scala/za/co/absa/atum/server/api/database/runs/functions/GetPartitioningMeasures.scala +++ b/server/src/main/scala/za/co/absa/atum/server/api/database/runs/functions/GetPartitioningMeasures.scala @@ -20,22 +20,22 @@ import doobie.Fragment import doobie.implicits.toSqlInterpolator import doobie.util.Read import play.api.libs.json.Json -import za.co.absa.atum.model.dto.PartitioningSubmitDTO -import za.co.absa.atum.server.api.database.PostgresDatabaseProvider +import za.co.absa.atum.model.dto.{MeasureDTO, PartitioningSubmitDTO} import za.co.absa.atum.server.model.PartitioningForDB import za.co.absa.fadb.DBSchema import za.co.absa.fadb.doobie.{DoobieEngine, StatusWithData} -import za.co.absa.fadb.doobie.DoobieFunction.DoobieMultipleResultFunction +import za.co.absa.fadb.doobie.DoobieFunction.DoobieSingleResultFunctionWithStatus import za.co.absa.fadb.status.handling.implementations.StandardStatusHandling +import za.co.absa.atum.server.api.database.PostgresDatabaseProvider import za.co.absa.atum.server.api.database.runs.Runs import zio._ import zio.interop.catz._ class GetPartitioningMeasures (implicit schema: DBSchema, dbEngine: DoobieEngine[Task]) - extends DoobieMultipleResultFunction[PartitioningSubmitDTO, Unit, Task] + extends DoobieSingleResultFunctionWithStatus[PartitioningSubmitDTO, Seq[MeasureDTO], Task] with StandardStatusHandling { - override def sql(values: PartitioningSubmitDTO)(implicit read: Read[StatusWithData[Unit]]): Fragment = { + override def sql(values: PartitioningSubmitDTO)(implicit read: Read[StatusWithData[Seq[MeasureDTO]]]): Fragment = { val partitioning = PartitioningForDB.fromSeqPartitionDTO(values.partitioning) val partitioningJsonString = Json.toJson(partitioning).toString @@ -45,7 +45,6 @@ class GetPartitioningMeasures (implicit schema: DBSchema, dbEngine: DoobieEngine partitioningJsonString } ) ${Fragment.const(alias)};""" - } } diff --git a/server/src/main/scala/za/co/absa/atum/server/api/repository/PartitioningRepository.scala b/server/src/main/scala/za/co/absa/atum/server/api/repository/PartitioningRepository.scala index 8395a2228..fcd1de245 100644 --- a/server/src/main/scala/za/co/absa/atum/server/api/repository/PartitioningRepository.scala +++ b/server/src/main/scala/za/co/absa/atum/server/api/repository/PartitioningRepository.scala @@ -16,7 +16,7 @@ package za.co.absa.atum.server.api.repository -import za.co.absa.atum.model.dto.PartitioningSubmitDTO +import za.co.absa.atum.model.dto.{MeasureDTO, PartitioningSubmitDTO} import za.co.absa.atum.server.api.database.runs.functions.{CreatePartitioningIfNotExists, GetPartitioningMeasures} import za.co.absa.atum.server.api.exception.DatabaseError import za.co.absa.fadb.exceptions.StatusException @@ -31,7 +31,7 @@ trait PartitioningRepository { def getPartitioningMeasures( partitioning: PartitioningSubmitDTO - ): IO[DatabaseError, Either[StatusException, Unit]] + ): IO[DatabaseError, Either[StatusException, Seq[MeasureDTO]]] } class PartitioningRepositoryImpl(createPartitioningIfNotExistsFn: CreatePartitioningIfNotExists, @@ -53,7 +53,7 @@ class PartitioningRepositoryImpl(createPartitioningIfNotExistsFn: CreatePartitio .tapError(error => ZIO.logError(s"Failed to create or retrieve partitioning in/from database: ${error.message}")) } - override def getPartitioningMeasures(partitioning: PartitioningSubmitDTO): IO[DatabaseError, Either[StatusException, Unit]] = { + override def getPartitioningMeasures(partitioning: PartitioningSubmitDTO): IO[DatabaseError, Either[StatusException, Seq[MeasureDTO]]] = { getPartitioningMeasuresFn(partitioning) .tap { case Left(statusException) => diff --git a/server/src/main/scala/za/co/absa/atum/server/api/service/PartitioningService.scala b/server/src/main/scala/za/co/absa/atum/server/api/service/PartitioningService.scala index d950a7789..6f0f6d0c3 100644 --- a/server/src/main/scala/za/co/absa/atum/server/api/service/PartitioningService.scala +++ b/server/src/main/scala/za/co/absa/atum/server/api/service/PartitioningService.scala @@ -31,7 +31,7 @@ trait PartitioningService { def getPartitioningMeasures( partitioning: PartitioningSubmitDTO - ): IO[ServiceError, Either[StatusException, Unit]] + ): IO[ServiceError, Either[StatusException, Seq[MeasureDTO]]] } class PartitioningServiceImpl(partitioningRepository: PartitioningRepository) extends PartitioningService { @@ -45,13 +45,14 @@ class PartitioningServiceImpl(partitioningRepository: PartitioningRepository) ex } } - override def getPartitioningMeasures(partitioning: PartitioningSubmitDTO): Seq[MeasureDTO] = { + override def getPartitioningMeasures(partitioning: PartitioningSubmitDTO): IO[ServiceError, Either[StatusException, Seq[MeasureDTO]]] = { partitioningRepository .getPartitioningMeasures(partitioning) .mapError { case DatabaseError(message) => ServiceError(s"Failed to retrieve partitioning measures: $message") } } + } object PartitioningServiceImpl {