Skip to content

Commit

Permalink
Fixes #120 - Applying GitHub comments
Browse files Browse the repository at this point in the history
  • Loading branch information
TebaleloS committed Apr 17, 2024
1 parent d75b5dd commit a6f09d3
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)};"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)};"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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._
Expand All @@ -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))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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!")))

Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit a6f09d3

Please sign in to comment.