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 9c34c9f1b..b6142f2d0 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 @@ -34,14 +34,13 @@ import za.co.absa.atum.server.api.database.DoobieImplicits.getMapWithOptionStrin class GetPartitioningAdditionalData (implicit schema: DBSchema, dbEngine: DoobieEngine[Task]) extends DoobieMultipleResultFunction[PartitioningDTO, (String, Option[String]), Task] { - + import za.co.absa.atum.server.api.database.DoobieImplicits.Jsonb.jsonbPutUsingString override def sql(values: PartitioningDTO)(implicit read: Read[(String, Option[String])]): Fragment = { val partitioning: PartitioningForDB = PartitioningForDB.fromSeqPartitionDTO(values) val partitioningJsonString = Json.toJson(partitioning).toString sql"""SELECT ${Fragment.const(selectEntry)} FROM ${Fragment.const(functionName)}( ${ - import za.co.absa.atum.server.api.database.DoobieImplicits.Jsonb.jsonbPutUsingString partitioningJsonString } ) ${Fragment.const(alias)};""" 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 082f8b1b8..0410d20f5 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 @@ -32,16 +32,16 @@ import zio.interop.catz._ import za.co.absa.atum.server.api.database.DoobieImplicits.Sequence.get class GetPartitioningMeasures (implicit schema: DBSchema, dbEngine: DoobieEngine[Task]) - extends DoobieMultipleResultFunction[PartitioningDTO, MeasureDTO, Task] + extends DoobieMultipleResultFunction[PartitioningDTO, Option[MeasureDTO], Task] { + import za.co.absa.atum.server.api.database.DoobieImplicits.Jsonb.jsonbPutUsingString - override def sql(values: PartitioningDTO)(implicit read: Read[MeasureDTO]): Fragment = { + override def sql(values: PartitioningDTO)(implicit read: Read[Option[MeasureDTO]]): Fragment = { val partitioning = PartitioningForDB.fromSeqPartitionDTO(values) val partitioningJsonString = Json.toJson(partitioning).toString sql"""SELECT ${Fragment.const(selectEntry)} FROM ${Fragment.const(functionName)}( ${ - import za.co.absa.atum.server.api.database.DoobieImplicits.Jsonb.jsonbPutUsingString partitioningJsonString } ) ${Fragment.const(alias)};""" 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 a0eeda5d3..d69ca1c90 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 @@ -17,7 +17,12 @@ 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.server.api.database.runs.functions.{CreateOrUpdateAdditionalData, CreatePartitioningIfNotExists, GetPartitioningAdditionalData, GetPartitioningMeasures} +import za.co.absa.atum.server.api.database.runs.functions.{ + CreateOrUpdateAdditionalData, + CreatePartitioningIfNotExists, + GetPartitioningAdditionalData, + GetPartitioningMeasures +} import za.co.absa.atum.server.api.exception.DatabaseError import za.co.absa.fadb.exceptions.StatusException import zio._ @@ -43,7 +48,7 @@ class PartitioningRepositoryImpl( } override def getPartitioningMeasures(partitioning: PartitioningDTO): - IO[DatabaseError, Seq[MeasureDTO]] = { + IO[DatabaseError, Either[Error, Seq[MeasureDTO]]] = { getPartitioningMeasuresFn(partitioning).mapLeft(err => DatabaseError(err.getMessage)) } diff --git a/server/src/test/scala/za/co/absa/atum/server/api/controller/PartitioningControllerSpec.scala b/server/src/test/scala/za/co/absa/atum/server/api/controller/PartitioningControllerSpec.scala index fd21105c1..f7a448e69 100644 --- a/server/src/test/scala/za/co/absa/atum/server/api/controller/PartitioningControllerSpec.scala +++ b/server/src/test/scala/za/co/absa/atum/server/api/controller/PartitioningControllerSpec.scala @@ -47,7 +47,7 @@ class PartitioningControllerSpec extends ZIOSpecDefault with TestData { override def spec: Spec[TestEnvironment with Scope, Any] = { - suite("PartitioningControllerSuite")( + suite("PartitioningControllerSpec")( suite("CreatePartitioningIfNotExistsSuite")( test("Returns expected AtumContextDTO") { val expectedAtumContextDTO = AtumContextDTO( 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 b6c9b8514..72d62cb52 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 @@ -17,7 +17,7 @@ package za.co.absa.atum.server.api.database.runs.functions import org.junit.runner.RunWith -import za.co.absa.atum.model.dto.{PartitionDTO, PartitioningSubmitDTO} +import za.co.absa.atum.model.dto.{PartitionDTO, PartitioningDTO} import za.co.absa.atum.server.ConfigProviderSpec import za.co.absa.atum.server.api.TestTransactorProvider import za.co.absa.atum.server.api.database.PostgresDatabaseProvider @@ -32,11 +32,11 @@ class GetPartitioningAdditionalDataSpec extends ConfigProviderSpec { suite("GetPartitioningAdditionalDataSuite")( test("Returns expected sequence of (String, Option[String])") { - val partitioningDTO = Seq(PartitionDTO("key1", "val1"), PartitionDTO("key2", "val2")) + val partitioningDTO: PartitioningDTO = Seq(PartitionDTO("key1", "val1"), PartitionDTO("key2", "val2")) for { getPartitioningAdditionalData <- ZIO.service[GetPartitioningAdditionalData] result <- getPartitioningAdditionalData(partitioningDTO) - } yield assertTrue(result.nonEmpty) + } yield assertTrue(result.nonEmpty && result.isInstanceOf[Seq[(String, Option[String])]]) } ).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 1453e4419..67d0a59cc 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 @@ -17,7 +17,7 @@ package za.co.absa.atum.server.api.database.runs.functions import org.junit.runner.RunWith -import za.co.absa.atum.model.dto.{PartitionDTO, PartitioningDTO, PartitioningSubmitDTO} +import za.co.absa.atum.model.dto.{PartitionDTO, PartitioningDTO} import za.co.absa.atum.server.ConfigProviderSpec import za.co.absa.atum.server.api.TestTransactorProvider import za.co.absa.atum.server.api.database.PostgresDatabaseProvider @@ -32,7 +32,7 @@ class GetPartitioningMeasuresSpec extends ConfigProviderSpec { suite("GetPartitioningMeasuresSuite")( test("Returns expected sequence of Measures") { - val partitioningDTO = Seq(PartitionDTO("key1", "val1"), PartitionDTO("key2", "val2")) + val partitioningDTO: PartitioningDTO = Seq(PartitionDTO("key1", "val1"), PartitionDTO("key2", "val2")) for { getPartitioningMeasures <- ZIO.service[GetPartitioningMeasures] diff --git a/server/src/test/scala/za/co/absa/atum/server/api/repository/PartitioningRepositorySpec.scala b/server/src/test/scala/za/co/absa/atum/server/api/repository/PartitioningRepositorySpec.scala index e13d8b64a..2bbc7b5ab 100644 --- a/server/src/test/scala/za/co/absa/atum/server/api/repository/PartitioningRepositorySpec.scala +++ b/server/src/test/scala/za/co/absa/atum/server/api/repository/PartitioningRepositorySpec.scala @@ -62,7 +62,7 @@ class PartitioningRepositorySpec extends ZIOSpecDefault with TestData { // Get Partitioning Measures Mocks private val getPartitioningMeasuresMock = mock(classOf[GetPartitioningMeasures]) - when(getPartitioningMeasuresMock.apply(partitioningDTO1)).thenReturn(ZIO.succeed(Seq())) + when(getPartitioningMeasuresMock.apply(partitioningDTO1)).thenReturn(ZIO.succeed(Seq().empty)) when(getPartitioningMeasuresMock.apply(partitioningDTO2)).thenReturn(ZIO.fail(new Exception("boom!"))) when(getPartitioningMeasuresMock.apply(partitioningDTO3)).thenReturn(ZIO.fail(new Exception("boom!"))) @@ -79,7 +79,7 @@ class PartitioningRepositorySpec extends ZIOSpecDefault with TestData { override def spec: Spec[TestEnvironment with Scope, Any] = { - suite("PartitioningRepositorySuite")( + suite("PartitioningRepositorySpec")( suite("CreatePartitioningIfNotExistsSuite")( test("Returns expected Right with Unit") { for { diff --git a/server/src/test/scala/za/co/absa/atum/server/api/service/PartitioningServiceSpec.scala b/server/src/test/scala/za/co/absa/atum/server/api/service/PartitioningServiceSpec.scala index fb13304e2..9e20d6e1e 100644 --- a/server/src/test/scala/za/co/absa/atum/server/api/service/PartitioningServiceSpec.scala +++ b/server/src/test/scala/za/co/absa/atum/server/api/service/PartitioningServiceSpec.scala @@ -63,7 +63,7 @@ class PartitioningServiceSpec extends ZIOSpecDefault with TestData { override def spec: Spec[TestEnvironment with Scope, Any] = { - suite("PartitioningServiceSuite")( + suite("PartitioningServiceSpec")( suite("CreatePartitioningIfNotExistsSuite")( test("Returns expected Right with Unit") { for {