From d1b6f7ce5a4dbc08554dac17d8018af46e0810de Mon Sep 17 00:00:00 2001 From: AB019TC Date: Fri, 26 Apr 2024 09:21:35 +0200 Subject: [PATCH] Closes #120 - Cleaning unwanted code lines --- .../api/controller/PartitioningControllerImpl.scala | 3 --- .../functions/GetPartitioningAdditionalData.scala | 3 +++ .../runs/functions/GetPartitioningMeasures.scala | 12 ++++++------ .../api/repository/PartitioningRepositoryImpl.scala | 5 ++++- .../GetPartitioningAdditionalDataSpec.scala | 13 ++++++++++--- .../functions/GetPartitioningMeasuresSpec.scala | 7 ++----- 6 files changed, 25 insertions(+), 18 deletions(-) diff --git a/server/src/main/scala/za/co/absa/atum/server/api/controller/PartitioningControllerImpl.scala b/server/src/main/scala/za/co/absa/atum/server/api/controller/PartitioningControllerImpl.scala index 288eea85c..8be58cb19 100644 --- a/server/src/main/scala/za/co/absa/atum/server/api/controller/PartitioningControllerImpl.scala +++ b/server/src/main/scala/za/co/absa/atum/server/api/controller/PartitioningControllerImpl.scala @@ -32,17 +32,14 @@ class PartitioningControllerImpl(partitioningService: PartitioningService) for { _ <- partitioningService.createPartitioningIfNotExists(partitioningSubmitDTO) .mapError(serviceError => InternalServerErrorResponse(serviceError.message)) -// _ <- ZIO.logInfo(s"Partitioning ${partitioningSubmitDTO} created") measures <- partitioningService.getPartitioningMeasures(partitioningSubmitDTO.partitioning) .mapError { serviceError: ServiceError => InternalServerErrorResponse(serviceError.message) } -// _ <- ZIO.logInfo(s"Measures for partitioning ${partitioningSubmitDTO} retrievedM") additionalData <- partitioningService.getPartitioningAdditionalData(partitioningSubmitDTO.partitioning) .mapError { serviceError: ServiceError => InternalServerErrorResponse(serviceError.message) } -// _ <- ZIO.logInfo(s"Additional data for partitioning ${partitioningSubmitDTO} retrievedA") } yield AtumContextDTO(partitioningSubmitDTO.partitioning, measures.toSet, additionalData) } diff --git a/server/src/main/scala/za/co/absa/atum/server/api/database/runs/functions/GetPartitioningAdditionalData.scala b/server/src/main/scala/za/co/absa/atum/server/api/database/runs/functions/GetPartitioningAdditionalData.scala index b6142f2d0..29f0b450b 100644 --- a/server/src/main/scala/za/co/absa/atum/server/api/database/runs/functions/GetPartitioningAdditionalData.scala +++ b/server/src/main/scala/za/co/absa/atum/server/api/database/runs/functions/GetPartitioningAdditionalData.scala @@ -35,6 +35,9 @@ class GetPartitioningAdditionalData (implicit schema: DBSchema, dbEngine: Doobie extends DoobieMultipleResultFunction[PartitioningDTO, (String, Option[String]), Task] { import za.co.absa.atum.server.api.database.DoobieImplicits.Jsonb.jsonbPutUsingString + + override val fieldsToSelect: Seq[String] = Seq("ad_name", "ad_value") + override def sql(values: PartitioningDTO)(implicit read: Read[(String, Option[String])]): Fragment = { val partitioning: PartitioningForDB = PartitioningForDB.fromSeqPartitionDTO(values) val partitioningJsonString = Json.toJson(partitioning).toString 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 9842f54b6..26274eac0 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 @@ -34,19 +34,19 @@ import za.co.absa.atum.server.api.database.DoobieImplicits.Sequence.get class GetPartitioningMeasures (implicit schema: DBSchema, dbEngine: DoobieEngine[Task]) extends DoobieMultipleResultFunction[PartitioningDTO, MeasureDTO, Task] { + import za.co.absa.atum.server.api.database.DoobieImplicits.Jsonb.jsonbPutUsingString + + override val fieldsToSelect: Seq[String] = Seq("measure_name", "measured_columns") + override def sql(values: PartitioningDTO)(implicit read: Read[MeasureDTO]): Fragment = { val partitioning = PartitioningForDB.fromSeqPartitionDTO(values) val partitioningJsonString = Json.toJson(partitioning).toString -// println(partitioning) - println(partitioningJsonString) - val sqlResults = sql"""SELECT ${Fragment.const(selectEntry)} FROM ${Fragment.const(functionName)}( + + sql"""SELECT ${Fragment.const(selectEntry)} FROM ${Fragment.const(functionName)}( ${ - import za.co.absa.atum.server.api.database.DoobieImplicits.Jsonb.jsonbPutUsingString partitioningJsonString } ) ${Fragment.const(alias)};""" - println(sqlResults) - sqlResults } } diff --git a/server/src/main/scala/za/co/absa/atum/server/api/repository/PartitioningRepositoryImpl.scala b/server/src/main/scala/za/co/absa/atum/server/api/repository/PartitioningRepositoryImpl.scala index a382973f9..e5a3168a2 100644 --- a/server/src/main/scala/za/co/absa/atum/server/api/repository/PartitioningRepositoryImpl.scala +++ b/server/src/main/scala/za/co/absa/atum/server/api/repository/PartitioningRepositoryImpl.scala @@ -16,7 +16,10 @@ package za.co.absa.atum.server.api.repository -import za.co.absa.atum.model.dto.{AdditionalDataDTO, AdditionalDataSubmitDTO, MeasureDTO, PartitioningDTO, PartitioningSubmitDTO} +import za.co.absa.atum.model.dto.{ + AdditionalDataDTO, AdditionalDataSubmitDTO, + MeasureDTO, PartitioningDTO, PartitioningSubmitDTO +} import za.co.absa.atum.server.api.database.runs.functions.{ CreateOrUpdateAdditionalData, CreatePartitioningIfNotExists, diff --git a/server/src/test/scala/za/co/absa/atum/server/api/database/runs/functions/GetPartitioningAdditionalDataSpec.scala b/server/src/test/scala/za/co/absa/atum/server/api/database/runs/functions/GetPartitioningAdditionalDataSpec.scala index 8e2155221..5f7a8d276 100644 --- a/server/src/test/scala/za/co/absa/atum/server/api/database/runs/functions/GetPartitioningAdditionalDataSpec.scala +++ b/server/src/test/scala/za/co/absa/atum/server/api/database/runs/functions/GetPartitioningAdditionalDataSpec.scala @@ -31,12 +31,19 @@ class GetPartitioningAdditionalDataSpec extends ConfigProviderSpec { override def spec: Spec[TestEnvironment with Scope, Any] = { suite("GetPartitioningAdditionalDataSpec")( - test("Returns expected sequence of (String, Option[String])") { + test("Returns expected left results for a partitioing that doesn't exist") { val partitioningDTO: PartitioningDTO = Seq(PartitionDTO("key1", "val1"), PartitionDTO("key2", "val2")) for { getPartitioningAdditionalData <- ZIO.service[GetPartitioningAdditionalData] - result <- getPartitioningAdditionalData(partitioningDTO) - } yield assertTrue(result.nonEmpty && result.isInstanceOf[Seq[(String, Option[String])]]) + result <- getPartitioningAdditionalData(partitioningDTO).either + } yield assertTrue (result.isLeft) + }, + test("Returns expected sequence of Additional data with provided partitioning") { + val partitioningDTO: PartitioningDTO = Seq(PartitionDTO("string1", "string1"), PartitionDTO("string2", "string2")) + for { + getPartitioningAdditionalData <- ZIO.service[GetPartitioningAdditionalData] + result <- getPartitioningAdditionalData(partitioningDTO).either + } yield assertTrue(result.isInstanceOf[Right[_, _]]) } ).provide( GetPartitioningAdditionalData.layer, diff --git a/server/src/test/scala/za/co/absa/atum/server/api/database/runs/functions/GetPartitioningMeasuresSpec.scala b/server/src/test/scala/za/co/absa/atum/server/api/database/runs/functions/GetPartitioningMeasuresSpec.scala index d74c4e8fa..2b809dd2c 100644 --- a/server/src/test/scala/za/co/absa/atum/server/api/database/runs/functions/GetPartitioningMeasuresSpec.scala +++ b/server/src/test/scala/za/co/absa/atum/server/api/database/runs/functions/GetPartitioningMeasuresSpec.scala @@ -31,7 +31,7 @@ class GetPartitioningMeasuresSpec extends ConfigProviderSpec { override def spec: Spec[TestEnvironment with Scope, Any] = { suite("GetPartitioningMeasuresSpec")( - test("Returns expected sequence of Measures") { + test("Returns expected Left for non-existing partitioning") { val partitioningDTO: PartitioningDTO = Seq(PartitionDTO("key1", "val1"), PartitionDTO("key2", "val2")) for { @@ -45,10 +45,7 @@ class GetPartitioningMeasuresSpec extends ConfigProviderSpec { for { getPartitioningMeasures <- ZIO.service[GetPartitioningMeasures] result <- getPartitioningMeasures(partitioningDTO).either - } yield assertTrue{ - println("Returned results: " + result) - result.isInstanceOf[Right[_, _]] - } + } yield assertTrue (result.isInstanceOf[Right[_, _]]) } ).provide(