Skip to content

Commit

Permalink
Merge branch '1.0.x' into PIN-4845
Browse files Browse the repository at this point in the history
  • Loading branch information
nttdata-rtorsoli authored May 16, 2024
2 parents 857cd0e + 0489ec0 commit 20ef478
Show file tree
Hide file tree
Showing 12 changed files with 1 addition and 270 deletions.
64 changes: 0 additions & 64 deletions src/main/resources/interface-specification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -660,57 +660,6 @@ paths:
tags:
- purpose
description: archives the purpose version by id
/purposes/{purposeId}/versions/{versionId}/update/waitingForApproval:
parameters:
- $ref: '#/components/parameters/CorrelationIdHeader'
- name: purposeId
in: path
required: true
schema:
type: string
format: uuid
- name: versionId
in: path
required: true
schema:
type: string
format: uuid
post:
tags:
- purpose
summary: Update a purpose version in waiting for approval
operationId: updateWaitingForApprovalPurposeVersion
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/WaitingForApprovalPurposeVersionUpdateContent'
required: true
responses:
'200':
description: Purpose Version updated
content:
application/json:
schema:
$ref: '#/components/schemas/PurposeVersion'
'400':
description: Invalid input
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
'403':
description: Purpose version not in waiting for approval state or the organization is not a producer
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
'404':
description: Not Found
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
/purposes/riskAnalysis/latest:
parameters:
- $ref: '#/components/parameters/CorrelationIdHeader'
Expand Down Expand Up @@ -1122,16 +1071,6 @@ components:
- description
- isFreeOfCharge
- dailyCalls
WaitingForApprovalPurposeVersionUpdateContent:
type: object
description: contains the expected payload for purpose version update.
properties:
expectedApprovalDate:
description: 'Estimated expected approval date for a purpose version'
type: string
format: date-time
required:
- expectedApprovalDate
PurposeVersion:
type: object
properties:
Expand All @@ -1152,9 +1091,6 @@ components:
firstActivationAt:
type: string
format: date-time
expectedApprovalDate:
type: string
format: date-time
dailyCalls:
description: 'maximum number of daily calls that this version can perform.'
type: integer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,13 +376,6 @@ object Adapters {
Management.PurposeVersionSeed(seed.dailyCalls, None)
}

implicit class WaitingForApprovalPurposeVersionUpdateContentWrapper(
private val updateContent: WaitingForApprovalPurposeVersionUpdateContent
) extends AnyVal {
def toManagement: Management.WaitingForApprovalPurposeVersionUpdateContent =
Management.WaitingForApprovalPurposeVersionUpdateContent(updateContent.expectedApprovalDate)
}

implicit class ManagementPurposeVersionWrapper(private val version: Management.PurposeVersion) extends AnyVal {

def toApi: PurposeVersion =
Expand All @@ -392,7 +385,6 @@ object Adapters {
createdAt = version.createdAt,
updatedAt = version.updatedAt,
firstActivationAt = version.firstActivationAt,
expectedApprovalDate = version.expectedApprovalDate,
riskAnalysis = version.riskAnalysis.map(_.toApi),
dailyCalls = version.dailyCalls,
suspendedAt = version.suspendedAt,
Expand Down Expand Up @@ -422,7 +414,6 @@ object Adapters {
createdAt = version.createdAt,
updatedAt = version.updatedAt,
firstActivationAt = version.firstActivationAt,
expectedApprovalDate = version.expectedApprovalDate,
riskAnalysis = version.riskAnalysis.map(_.toApi),
dailyCalls = version.dailyCalls,
suspendedAt = version.suspendedAt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ object PurposeApiMarshallerImpl extends PurposeApiMarshaller with SprayJsonSuppo
override implicit def fromEntityUnmarshallerPurposeUpdateContent: FromEntityUnmarshaller[PurposeUpdateContent] =
sprayJsonUnmarshaller[PurposeUpdateContent]

override implicit def fromEntityUnmarshallerWaitingForApprovalPurposeVersionUpdateContent
: FromEntityUnmarshaller[WaitingForApprovalPurposeVersionUpdateContent] =
sprayJsonUnmarshaller[WaitingForApprovalPurposeVersionUpdateContent]

override implicit def toEntityMarshallerPurpose: ToEntityMarshaller[Purpose] = sprayJsonMarshaller[Purpose]

override implicit def toEntityMarshallerPurposeVersionDocument: ToEntityMarshaller[PurposeVersionDocument] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -570,39 +570,6 @@ final case class PurposeApiServiceImpl(
onComplete(result) { archivePurposeVersionResponse[PurposeVersion](operationLabel)(archivePurposeVersion200) }
}

override def updateWaitingForApprovalPurposeVersion(
purposeId: String,
versionId: String,
updateContent: WaitingForApprovalPurposeVersionUpdateContent
)(implicit
contexts: Seq[(String, String)],
toEntityMarshallerPurposeVersion: ToEntityMarshaller[PurposeVersion],
toEntityMarshallerProblem: ToEntityMarshaller[Problem]
): Route = authorize(ADMIN_ROLE) {
val operationLabel = s"Updating Waiting For Approval Version $versionId of Purpose $purposeId"
logger.info(operationLabel)

val result: Future[PurposeVersion] = for {
purposeUUID <- purposeId.toFutureUUID
versionUUID <- versionId.toFutureUUID
organizationId <- getOrganizationIdFutureUUID(contexts)
purpose <- purposeManagementService.getPurposeById(purposeUUID)
_ <- assertOrganizationIsAProducer(organizationId, purpose.eserviceId)
_ <- getVersion(purpose, versionUUID)
purposeVersion <- purposeManagementService.updateWaitingForApprovalPurposeVersion(
purposeUUID,
versionUUID,
updateContent.toManagement
)
} yield purposeVersion.toApi

onComplete(result) {
updateWaitingForApprovalPurposeVersionResponse[PurposeVersion](operationLabel)(
updateWaitingForApprovalPurposeVersion200
)
}
}

override def clonePurpose(purposeId: String, seed: PurposeCloneSeed)(implicit
contexts: Seq[(String, String)],
toEntityMarshallerPurpose: ToEntityMarshaller[Purpose],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,4 @@ object ResponseHandlers extends AkkaResponses {
case Failure(ex: PurposeVersionNotFound) => notFound(ex, logMessage)
case Failure(ex) => internalServerError(ex, logMessage)
}

def updateWaitingForApprovalPurposeVersionResponse[T](logMessage: String)(
success: T => Route
)(result: Try[T])(implicit contexts: Seq[(String, String)], logger: LoggerTakingImplicit[ContextFieldsToLog]): Route =
result match {
case Success(s) => success(s)
case Failure(ex: OrganizationIsNotTheProducer) => forbidden(ex, logMessage)
case Failure(ex: PurposeNotFound) => notFound(ex, logMessage)
case Failure(ex: PurposeVersionNotFound) => notFound(ex, logMessage)
case Failure(ex) => internalServerError(ex, logMessage)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package object impl extends SprayJsonSupport with DefaultJsonProtocol {
implicit def purposeVersionDocumentFormat: RootJsonFormat[PurposeVersionDocument] =
jsonFormat4(PurposeVersionDocument)
implicit def purposeFormat: RootJsonFormat[Purpose] = jsonFormat14(Purpose)
implicit def purposeVersionFormat: RootJsonFormat[PurposeVersion] = jsonFormat10(PurposeVersion)
implicit def purposeVersionFormat: RootJsonFormat[PurposeVersion] = jsonFormat9(PurposeVersion)
implicit def purposesFormat: RootJsonFormat[Purposes] = jsonFormat2(Purposes)
implicit def purposeSeedFormat: RootJsonFormat[PurposeSeed] = jsonFormat8(PurposeSeed)
implicit def purposeUpdateContentFormat: RootJsonFormat[PurposeUpdateContent] = jsonFormat6(PurposeUpdateContent)
Expand All @@ -28,9 +28,6 @@ package object impl extends SprayJsonSupport with DefaultJsonProtocol {
implicit def purposeVersionSeedFormat: RootJsonFormat[PurposeVersionSeed] = jsonFormat1(PurposeVersionSeed)
implicit def problemErrorFormat: RootJsonFormat[ProblemError] = jsonFormat2(ProblemError)
implicit def problemFormat: RootJsonFormat[Problem] = jsonFormat6(Problem)
implicit def waitingForApprovalPurposeVersionUpdateFormat
: RootJsonFormat[WaitingForApprovalPurposeVersionUpdateContent] =
jsonFormat1(WaitingForApprovalPurposeVersionUpdateContent)
implicit def rejectPurposeVersionPayloadFormat: RootJsonFormat[RejectPurposeVersionPayload] =
jsonFormat1(RejectPurposeVersionPayload)
implicit def dependencyResponseFormat: RootJsonFormat[DependencyResponse] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@ trait PurposeManagementService {
contexts: Seq[(String, String)]
): Future[PurposeVersion]

def updateWaitingForApprovalPurposeVersion(
purposeId: UUID,
versionId: UUID,
updateContent: WaitingForApprovalPurposeVersionUpdateContent
)(implicit contexts: Seq[(String, String)]): Future[PurposeVersion]

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

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 @@ -170,21 +170,6 @@ final case class PurposeManagementServiceImpl(invoker: PurposeManagementInvoker,
invoker.invoke(request, s"Archiving Version $versionId of Purpose $purposeId by ${stateChangeDetails.changedBy}")
}

override def updateWaitingForApprovalPurposeVersion(
purposeId: UUID,
versionId: UUID,
updateContent: WaitingForApprovalPurposeVersionUpdateContent
)(implicit contexts: Seq[(String, String)]): Future[PurposeVersion] = withHeaders { (bearerToken, correlationId) =>
val request =
api.updateWaitingForApprovalPurposeVersion(xCorrelationId = correlationId, purposeId, versionId, updateContent)(
BearerToken(bearerToken)
)
invoker.invoke(
request,
s"Updating waiting for approval version $versionId of Purpose $purposeId with $updateContent"
)
}

override def deletePurpose(purposeId: UUID)(implicit contexts: Seq[(String, String)]): Future[Unit] = withHeaders {
(bearerToken, correlationId) =>
val request =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2587,104 +2587,6 @@ class PurposeApiServiceSpec extends AnyWordSpecLike with SpecHelper with Scalate

}

"Purpose waiting for approval version update" should {

"succeed" in {

val producerId = UUID.randomUUID()
val purposeId = UUID.randomUUID()
val purposeVersionId = UUID.randomUUID()
val eserviceId = UUID.randomUUID()

implicit val context: Seq[(String, String)] =
Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> producerId.toString)

val version = SpecData.purposeVersion.copy(id = purposeVersionId)
val expected =
SpecData.dependencyPurposeVersion.copy(id = purposeVersionId, expectedApprovalDate = Some(SpecData.timestamp))

mockPurposeRetrieve(purposeId, SpecData.purpose.copy(eserviceId = eserviceId, versions = Seq(version)))
mockEServiceRetrieve(eserviceId, SpecData.eService.copy(id = eserviceId, producerId = producerId))

(
mockPurposeManagementService
.updateWaitingForApprovalPurposeVersion(
_: UUID,
_: UUID,
_: PurposeManagementDependency.WaitingForApprovalPurposeVersionUpdateContent
)(_: Seq[(String, String)])
)
.expects(
purposeId,
purposeVersionId,
PurposeManagementDependency.WaitingForApprovalPurposeVersionUpdateContent(SpecData.timestamp),
context
)
.once()
.returns(Future.successful[PurposeManagementDependency.PurposeVersion](expected))

Post() ~> service.updateWaitingForApprovalPurposeVersion(
purposeId.toString,
purposeVersionId.toString,
SpecData.waitingForApprovalUpdate
) ~> check {
status shouldEqual StatusCodes.OK
responseAs[PurposeVersion] shouldEqual expected.toApi
}
}

"fail if Purpose Version does not exist" in {

val purposeId = UUID.randomUUID()
val purposeVersionId = UUID.randomUUID()

implicit val context: Seq[(String, String)] =
Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> UUID.randomUUID().toString)

(mockPurposeManagementService
.getPurposeById(_: UUID)(_: ExecutionContext, _: ReadModelService))
.expects(purposeId, *, *)
.once()
.returns(Future.failed(PurposeNotFound(purposeId)))

Post() ~> service.updateWaitingForApprovalPurposeVersion(
purposeId.toString,
purposeVersionId.toString,
SpecData.waitingForApprovalUpdate
) ~> check {
status shouldEqual StatusCodes.NotFound
val problem = responseAs[Problem]
problem.status shouldBe StatusCodes.NotFound.intValue
problem.errors.head.code shouldBe "012-0012"
}
}

"fail if User is not a Producer" in {

val producerId = UUID.randomUUID()
val purposeId = UUID.randomUUID()
val purposeVersionId = UUID.randomUUID()
val eserviceId = UUID.randomUUID()

implicit val context: Seq[(String, String)] =
Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> UUID.randomUUID().toString)

mockPurposeRetrieve(purposeId, SpecData.purpose.copy(eserviceId = eserviceId))
mockEServiceRetrieve(eserviceId, SpecData.eService.copy(id = eserviceId, producerId = producerId))

Post() ~> service.updateWaitingForApprovalPurposeVersion(
purposeId.toString,
purposeVersionId.toString,
SpecData.waitingForApprovalUpdate
) ~> check {
status shouldEqual StatusCodes.Forbidden
val problem = responseAs[Problem]
problem.status shouldBe StatusCodes.Forbidden.intValue
problem.errors.head.code shouldBe "012-0002"
}
}
}

"Purpose Risk Analysis Configuration latest version retrieve" should {
"succeed when Tenant kind is PA" in {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,6 @@ object SpecData {
freeOfChargeReason = None
)

def waitingForApprovalUpdate: WaitingForApprovalPurposeVersionUpdateContent =
WaitingForApprovalPurposeVersionUpdateContent(timestamp)

val purposes: Seq[PersistentPurpose] = Seq(purpose)

val agreement: PersistentAgreement =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,6 @@ class PurposeApiAuthzSpec extends AnyWordSpecLike with BeforeAndAfterAll with Au
{ implicit c: Seq[(String, String)] => service.updateReversePurpose("fake", fakeContent) }
)
}
"accept authorized roles for updateWaitingForApprovalPurposeVersion" in {
val endpoint = AuthorizedRoutes.endpoints("updateWaitingForApprovalPurposeVersion")
val fakeContent = WaitingForApprovalPurposeVersionUpdateContent(OffsetDateTime.now())
validateAuthorization(
endpoint,
{ implicit c: Seq[(String, String)] =>
service.updateWaitingForApprovalPurposeVersion("fakeSeed", "fake", fakeContent)
}
)
}

"accept authorized roles for getRiskAnalysisDocument" in {
val endpoint = AuthorizedRoutes.endpoints("getRiskAnalysisDocument")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,19 +170,6 @@ object FakeDependencies {
)
)

override def updateWaitingForApprovalPurposeVersion(
purposeId: UUID,
versionId: UUID,
updateContent: Management.WaitingForApprovalPurposeVersionUpdateContent
)(implicit contexts: Seq[(String, String)]): Future[Management.PurposeVersion] = Future.successful(
Management.PurposeVersion(
id = UUID.randomUUID(),
state = Management.PurposeVersionState.DRAFT,
createdAt = OffsetDateTime.now(),
dailyCalls = 1
)
)

override def deletePurpose(purposeId: UUID)(implicit contexts: Seq[(String, String)]): Future[Unit] =
Future.successful(())

Expand Down

0 comments on commit 20ef478

Please sign in to comment.