Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PIN-4062 Adapted route for the purpose clone #235

Merged
merged 4 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/main/resources/interface-specification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5206,6 +5206,12 @@ paths:
description: clone purpose
summary: Clone Purpose
operationId: clonePurpose
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/PurposeCloneSeed'
required: true
responses:
'200':
description: Purpose Cloned
Expand Down Expand Up @@ -10218,6 +10224,14 @@ components:
- purposeId
- title
- eservice
PurposeCloneSeed:
type: object
properties:
eserviceId:
type: string
format: uuid
required:
- eserviceId
CatalogDescriptorEService:
type: object
required:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,7 @@ object PurposesApiMarshallerImpl extends PurposesApiMarshaller with SprayJsonSup
override implicit def fromEntityUnmarshallerReversePurposeUpdateContent
: FromEntityUnmarshaller[ReversePurposeUpdateContent] =
sprayJsonUnmarshaller[ReversePurposeUpdateContent]

override implicit def fromEntityUnmarshallerPurposeCloneSeed: FromEntityUnmarshaller[PurposeCloneSeed] =
sprayJsonUnmarshaller[PurposeCloneSeed]
}
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ final case class PurposesApiServiceImpl(
go(0)(Nil)
}

override def clonePurpose(purposeId: String)(implicit
override def clonePurpose(purposeId: String, seed: PurposeCloneSeed)(implicit
contexts: Seq[(String, String)],
toEntityMarshallerPurposeVersionResource: ToEntityMarshaller[PurposeVersionResource],
toEntityMarshallerProblem: ToEntityMarshaller[Problem]
Expand All @@ -366,7 +366,7 @@ final case class PurposesApiServiceImpl(

val result: Future[PurposeVersionResource] = for {
purposeUuid <- purposeId.toFutureUUID
purpose <- purposeProcessService.clonePurpose(purposeUuid)
purpose <- purposeProcessService.clonePurpose(purposeUuid, seed.toProcess)
draftVersion <- purpose.versions
.find(_.state == PurposeProcess.PurposeVersionState.DRAFT)
.toFuture(PurposeVersionDraftNotFound(purpose.id))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ package object impl extends SprayJsonSupport with DefaultJsonProtocol {
jsonFormat6(ProducerEServiceDetails)

implicit val purposeSeedFormat: RootJsonFormat[PurposeSeed] = jsonFormat8(PurposeSeed)
implicit val PurposeVersionDocumentFormat: RootJsonFormat[PurposeVersionDocument] = jsonFormat3(
implicit val purposeCloneSeedFormat: RootJsonFormat[PurposeCloneSeed] = jsonFormat1(PurposeCloneSeed)
implicit val purposeVersionDocumentFormat: RootJsonFormat[PurposeVersionDocument] = jsonFormat3(
PurposeVersionDocument
)
implicit val purposeVersionFormat: RootJsonFormat[PurposeVersion] = jsonFormat9(PurposeVersion)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ trait PurposeProcessService {
contexts: Seq[(String, String)]
): Future[PurposeVersion]

def clonePurpose(purposeUuid: UUID)(implicit contexts: Seq[(String, String)]): Future[Purpose]
def clonePurpose(purposeUuid: UUID, seed: PurposeCloneSeed)(implicit contexts: Seq[(String, String)]): Future[Purpose]

def deletePurposeVersion(purposeId: UUID, versionId: UUID)(implicit contexts: Seq[(String, String)]): Future[Unit]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,17 @@ class PurposeProcessServiceImpl(purposeProcessUrl: String, blockingEc: Execution
invoker.invoke(request, s"Archive Purpose $purposeId with version $versionId")
}

override def clonePurpose(purposeId: UUID)(implicit contexts: Seq[(String, String)]): Future[Purpose] =
override def clonePurpose(purposeId: UUID, seed: PurposeCloneSeed)(implicit
contexts: Seq[(String, String)]
): Future[Purpose] =
withHeaders[Purpose] { (bearerToken, correlationId, ip) =>
val request: ApiRequest[Purpose] =
api.clonePurpose(purposeId = purposeId, xCorrelationId = correlationId, xForwardedFor = ip)(
BearerToken(bearerToken)
)
api.clonePurpose(
purposeId = purposeId,
purposeCloneSeed = seed,
xCorrelationId = correlationId,
xForwardedFor = ip
)(BearerToken(bearerToken))
invoker.invoke(request, s"Cloning Purpose ${purposeId.toString}")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ object PurposeProcessServiceTypes {
)
}

implicit class PurposeCloneSeedConverter(private val seed: PurposeCloneSeed) extends AnyVal {
def toProcess: PurposeProcess.PurposeCloneSeed = PurposeProcess.PurposeCloneSeed(eserviceId = seed.eserviceId)
}

implicit class ProcessRiskAnalysisFormConverter(private val raf: PurposeProcess.RiskAnalysisForm) extends AnyVal {
def toApi: RiskAnalysisForm = RiskAnalysisForm(version = raf.version, answers = raf.answers)
}
Expand Down
Loading