Skip to content

Commit

Permalink
introduced classes for api v2 endpoints (#238)
Browse files Browse the repository at this point in the history
classes for api v2 endpoints
  • Loading branch information
salamonpavel authored Aug 5, 2024
1 parent 2b582d7 commit 202dab2
Show file tree
Hide file tree
Showing 19 changed files with 304 additions and 23 deletions.
6 changes: 3 additions & 3 deletions agent/src/main/scala/za/co/absa/atum/agent/AtumContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class AtumContext private[agent] (
*
* @return the current additional data
*/
def currentAdditionalData: AdditionalDataDTO = {
def currentAdditionalData: InitialAdditionalDataDTO = {
additionalData
}

Expand Down Expand Up @@ -196,7 +196,7 @@ class AtumContext private[agent] (
atumPartitions: AtumPartitions = atumPartitions,
agent: AtumAgent = agent,
measures: Set[AtumMeasure] = measures,
additionalData: AdditionalDataDTO = additionalData
additionalData: InitialAdditionalDataDTO = additionalData
): AtumContext = {
new AtumContext(atumPartitions, agent, measures, additionalData)
}
Expand All @@ -207,7 +207,7 @@ object AtumContext {
* Type alias for Atum partitions.
*/
type AtumPartitions = ListMap[String, String]
type AdditionalData = AdditionalDataDTO
type AdditionalData = InitialAdditionalDataDTO

/**
* Object contains helper methods to work with Atum partitions.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2021 ABSA Group Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package za.co.absa.atum.model.dto

import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder}
import io.circe.{Decoder, Encoder}

case class AdditionalDataDTO(
data: Map[String, Option[AdditionalDataItemDTO]]
)

object AdditionalDataDTO {
implicit val encodeAdditionalDataDTO: Encoder[AdditionalDataDTO] = deriveEncoder
implicit val decodeAdditionalDataDTO: Decoder[AdditionalDataDTO] = deriveDecoder
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2021 ABSA Group Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package za.co.absa.atum.model.dto

import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder}
import io.circe.{Decoder, Encoder}

case class AdditionalDataItemDTO(
value: String,
author: String
)

object AdditionalDataItemDTO {
implicit val encoderAdditionalDataItem: Encoder[AdditionalDataItemDTO] = deriveEncoder
implicit val decoderAdditionalDataItem: Decoder[AdditionalDataItemDTO] = deriveDecoder
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2021 ABSA Group Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package za.co.absa.atum.model.dto

import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder}
import io.circe.{Decoder, Encoder}

case class AdditionalDataPatchDTO(
data: Map[String, AdditionalDataItemDTO]
)

object AdditionalDataPatchDTO {
implicit val encoderAdditionalDataPatchDTO: Encoder[AdditionalDataPatchDTO] = deriveEncoder
implicit val decoderAdditionalDataPatchDTO: Decoder[AdditionalDataPatchDTO] = deriveDecoder
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@

package za.co.absa.atum.model.dto


import io.circe.generic.semiauto._
import io.circe._

case class AdditionalDataSubmitDTO (
case class AdditionalDataSubmitDTO(
partitioning: PartitioningDTO,
additionalData: AdditionalDataDTO,
additionalData: InitialAdditionalDataDTO,
author: String
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import io.circe._
case class AtumContextDTO(
partitioning: PartitioningDTO,
measures: Set[MeasureDTO] = Set.empty,
additionalData: AdditionalDataDTO = Map.empty
additionalData: InitialAdditionalDataDTO = Map.empty
)

object AtumContextDTO {
Expand Down
32 changes: 32 additions & 0 deletions model/src/main/scala/za/co/absa/atum/model/dto/FlowDTO.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2021 ABSA Group Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package za.co.absa.atum.model.dto

import io.circe.{Decoder, Encoder}
import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder}

case class FlowDTO(
id: Long,
name: String,
description: Option[String],
fromPattern: Boolean
)

object FlowDTO {
implicit val decoderFlowDTO: Decoder[FlowDTO] = deriveDecoder
implicit val encoderFlowDTO: Encoder[FlowDTO] = deriveEncoder
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2021 ABSA Group Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package za.co.absa.atum.model.dto

import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder}
import io.circe.{Decoder, Encoder}

case class PartitioningWithIdDTO(
id: Long,
partitioning: PartitioningDTO,
parentPartitioning: Option[PartitioningDTO],
author: String
)

object PartitioningWithIdDTO {
implicit def encoder: Encoder[PartitioningWithIdDTO] = deriveEncoder
implicit def decoder: Decoder[PartitioningWithIdDTO] = deriveDecoder
}
6 changes: 3 additions & 3 deletions model/src/main/scala/za/co/absa/atum/model/dto/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ import io.circe._

package object dto {
type PartitioningDTO = Seq[PartitionDTO]
type AdditionalDataDTO = Map[String, Option[String]]
type InitialAdditionalDataDTO = Map[String, Option[String]]

// Todo. This implicit definition should not be defined here, so it is to be addressed in Ticket #221
// Implicit encoders and decoders for AdditionalDataDTO
implicit val decodeAdditionalDataDTO: Decoder[AdditionalDataDTO] = Decoder.decodeMap[String, Option[String]]
implicit val encodeAdditionalDataDTO: Encoder[AdditionalDataDTO] = Encoder.encodeMap[String, Option[String]]
implicit val decodeAdditionalDataDTO: Decoder[InitialAdditionalDataDTO] = Decoder.decodeMap[String, Option[String]]
implicit val encodeAdditionalDataDTO: Encoder[InitialAdditionalDataDTO] = Encoder.encodeMap[String, Option[String]]

// Implicit encoders and decoders for PartitioningDTO
implicit val decodePartitioningDTO: Decoder[PartitioningDTO] = Decoder.decodeSeq[PartitionDTO]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2021 ABSA Group Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package za.co.absa.atum.server.api.http

object ApiPaths {

final val Api = "api"
final val V1 = "v1"
final val V2 = "v2"

final val Health = "health"
final val ZioMetrics = "zio-metrics"

object V1Paths {

final val CreateCheckpoint = "createCheckpoint"
final val CreatePartitioning = "createPartitioning"

}

object V2Paths {

final val Partitionings = "partitionings"
final val Checkpoints = "checkpoints"
final val AdditionalData = "additional-data"
final val Flows = "flows"
final val Measures = "measures"
final val MainFlow = "main-flow"

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package za.co.absa.atum.server.api.repository

import za.co.absa.atum.model.dto.{
AdditionalDataDTO,
InitialAdditionalDataDTO,
AdditionalDataSubmitDTO,
CheckpointQueryDTO,
MeasureDTO,
Expand All @@ -35,7 +35,7 @@ trait PartitioningRepository {

def getPartitioningMeasures(partitioning: PartitioningDTO): IO[DatabaseError, Seq[MeasureDTO]]

def getPartitioningAdditionalData(partitioning: PartitioningDTO): IO[DatabaseError, AdditionalDataDTO]
def getPartitioningAdditionalData(partitioning: PartitioningDTO): IO[DatabaseError, InitialAdditionalDataDTO]

def createOrUpdateAdditionalData(additionalData: AdditionalDataSubmitDTO): IO[DatabaseError, Unit]

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.repository

import za.co.absa.atum.model.dto.{
AdditionalDataDTO,
InitialAdditionalDataDTO,
AdditionalDataSubmitDTO,
CheckpointQueryDTO,
MeasureDTO,
Expand Down Expand Up @@ -65,7 +65,7 @@ class PartitioningRepositoryImpl(
})
}

override def getPartitioningAdditionalData(partitioning: PartitioningDTO): IO[DatabaseError, AdditionalDataDTO] = {
override def getPartitioningAdditionalData(partitioning: PartitioningDTO): IO[DatabaseError, InitialAdditionalDataDTO] = {
dbMultipleResultCallWithAggregatedStatus(
getPartitioningAdditionalDataFn(partitioning),
"getPartitioningAdditionalData"
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.service

import za.co.absa.atum.model.dto.{
AdditionalDataDTO,
InitialAdditionalDataDTO,
AdditionalDataSubmitDTO,
CheckpointDTO,
CheckpointQueryDTO,
Expand All @@ -35,7 +35,7 @@ trait PartitioningService {

def getPartitioningMeasures(partitioning: PartitioningDTO): IO[ServiceError, Seq[MeasureDTO]]

def getPartitioningAdditionalData(partitioning: PartitioningDTO): IO[ServiceError, AdditionalDataDTO]
def getPartitioningAdditionalData(partitioning: PartitioningDTO): IO[ServiceError, InitialAdditionalDataDTO]

def createOrUpdateAdditionalData(additionalData: AdditionalDataSubmitDTO): IO[ServiceError, Unit]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class PartitioningServiceImpl(partitioningRepository: PartitioningRepository)
)
}

override def getPartitioningAdditionalData(partitioning: PartitioningDTO): IO[ServiceError, AdditionalDataDTO] = {
override def getPartitioningAdditionalData(partitioning: PartitioningDTO): IO[ServiceError, InitialAdditionalDataDTO] = {
repositoryCall(
partitioningRepository.getPartitioningAdditionalData(partitioning),
"getPartitioningAdditionalData"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,22 @@ object BadRequestResponse {
implicit val encodeBadRequestResponse: Encoder[BadRequestResponse] = deriveEncoder
}

final case class ConflictErrorResponse(message: String, requestId: UUID = UUID.randomUUID())
extends ErrorResponse

object ConflictErrorResponse {
implicit val decoderConflictErrorResponse: Decoder[ConflictErrorResponse] = deriveDecoder
implicit val encoderConflictErrorResponse: Encoder[ConflictErrorResponse] = deriveEncoder
}

final case class NotFoundErrorResponse(message: String, requestId: UUID = UUID.randomUUID())
extends ErrorResponse

object NotFoundErrorResponse {
implicit val decoderNotFoundErrorResponse: Decoder[NotFoundErrorResponse] = deriveDecoder
implicit val encoderNotFoundErrorResponse: Encoder[NotFoundErrorResponse] = deriveEncoder
}

final case class GeneralErrorResponse(message: String, requestId: UUID = UUID.randomUUID()) extends ErrorResponse

object GeneralErrorResponse {
Expand All @@ -47,6 +63,6 @@ object GeneralErrorResponse {
final case class InternalServerErrorResponse(message: String, requestId: UUID = UUID.randomUUID()) extends ErrorResponse

object InternalServerErrorResponse {
implicit val decodeInternalServerErrorResponse: Decoder[InternalServerErrorResponse] = deriveDecoder
implicit val encodeInternalServerErrorResponse: Encoder[InternalServerErrorResponse] = deriveEncoder
implicit val decoderInternalServerErrorResponse: Decoder[InternalServerErrorResponse] = deriveDecoder
implicit val encoderInternalServerErrorResponse: Encoder[InternalServerErrorResponse] = deriveEncoder
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2021 ABSA Group Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package za.co.absa.atum.server.model

sealed trait PaginatedResult[R] {
def data: Seq[R]
}

object PaginatedResult {

case class ResultHasMore[R](data: Seq[R]) extends PaginatedResult[R]
case class ResultNoMore[R](data: Seq[R]) extends PaginatedResult[R]

}

Loading

0 comments on commit 202dab2

Please sign in to comment.