From 0489ec0c93e0a3d74806738da6f73b70d1425fb8 Mon Sep 17 00:00:00 2001 From: Riccardo Torsoli <122275960+nttdata-rtorsoli@users.noreply.github.com> Date: Thu, 16 May 2024 11:28:36 +0200 Subject: [PATCH] PIN-4879: Remove expectedApprovalDate attribute (#206) Co-authored-by: nttdata-rtorsoli --- .../resources/interface-specification.yml | 64 ------------ .../interop/purposeprocess/api/Adapters.scala | 9 -- .../api/impl/PurposeApiMarshallerImpl.scala | 4 - .../api/impl/PurposeApiServiceImpl.scala | 33 ------- .../api/impl/ResponseHandlers.scala | 11 --- .../purposeprocess/api/impl/package.scala | 5 +- .../service/PurposeManagementService.scala | 6 -- .../impl/PurposeManagementServiceImpl.scala | 15 --- .../PurposeApiServiceSpec.scala | 98 ------------------- .../interop/purposeprocess/SpecData.scala | 3 - .../authz/PurposeApiAuthzSpec.scala | 10 -- .../util/FakeDependencies.scala | 13 --- 12 files changed, 1 insertion(+), 270 deletions(-) diff --git a/src/main/resources/interface-specification.yml b/src/main/resources/interface-specification.yml index bce802f1..4a28be36 100644 --- a/src/main/resources/interface-specification.yml +++ b/src/main/resources/interface-specification.yml @@ -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' @@ -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: @@ -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 diff --git a/src/main/scala/it/pagopa/interop/purposeprocess/api/Adapters.scala b/src/main/scala/it/pagopa/interop/purposeprocess/api/Adapters.scala index d0ecdb3e..c4075e6e 100644 --- a/src/main/scala/it/pagopa/interop/purposeprocess/api/Adapters.scala +++ b/src/main/scala/it/pagopa/interop/purposeprocess/api/Adapters.scala @@ -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 = @@ -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, @@ -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, diff --git a/src/main/scala/it/pagopa/interop/purposeprocess/api/impl/PurposeApiMarshallerImpl.scala b/src/main/scala/it/pagopa/interop/purposeprocess/api/impl/PurposeApiMarshallerImpl.scala index 1a435f88..5c2741df 100644 --- a/src/main/scala/it/pagopa/interop/purposeprocess/api/impl/PurposeApiMarshallerImpl.scala +++ b/src/main/scala/it/pagopa/interop/purposeprocess/api/impl/PurposeApiMarshallerImpl.scala @@ -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] = diff --git a/src/main/scala/it/pagopa/interop/purposeprocess/api/impl/PurposeApiServiceImpl.scala b/src/main/scala/it/pagopa/interop/purposeprocess/api/impl/PurposeApiServiceImpl.scala index 2f33cd8b..758caf6e 100644 --- a/src/main/scala/it/pagopa/interop/purposeprocess/api/impl/PurposeApiServiceImpl.scala +++ b/src/main/scala/it/pagopa/interop/purposeprocess/api/impl/PurposeApiServiceImpl.scala @@ -562,39 +562,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], diff --git a/src/main/scala/it/pagopa/interop/purposeprocess/api/impl/ResponseHandlers.scala b/src/main/scala/it/pagopa/interop/purposeprocess/api/impl/ResponseHandlers.scala index 4bf34db6..edb5ccd7 100644 --- a/src/main/scala/it/pagopa/interop/purposeprocess/api/impl/ResponseHandlers.scala +++ b/src/main/scala/it/pagopa/interop/purposeprocess/api/impl/ResponseHandlers.scala @@ -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) - } } diff --git a/src/main/scala/it/pagopa/interop/purposeprocess/api/impl/package.scala b/src/main/scala/it/pagopa/interop/purposeprocess/api/impl/package.scala index 61bf86b2..129bf48d 100644 --- a/src/main/scala/it/pagopa/interop/purposeprocess/api/impl/package.scala +++ b/src/main/scala/it/pagopa/interop/purposeprocess/api/impl/package.scala @@ -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) @@ -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] = diff --git a/src/main/scala/it/pagopa/interop/purposeprocess/service/PurposeManagementService.scala b/src/main/scala/it/pagopa/interop/purposeprocess/service/PurposeManagementService.scala index c1fd8545..cd9c0715 100644 --- a/src/main/scala/it/pagopa/interop/purposeprocess/service/PurposeManagementService.scala +++ b/src/main/scala/it/pagopa/interop/purposeprocess/service/PurposeManagementService.scala @@ -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] diff --git a/src/main/scala/it/pagopa/interop/purposeprocess/service/impl/PurposeManagementServiceImpl.scala b/src/main/scala/it/pagopa/interop/purposeprocess/service/impl/PurposeManagementServiceImpl.scala index 434f195b..c414b3fc 100644 --- a/src/main/scala/it/pagopa/interop/purposeprocess/service/impl/PurposeManagementServiceImpl.scala +++ b/src/main/scala/it/pagopa/interop/purposeprocess/service/impl/PurposeManagementServiceImpl.scala @@ -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 = diff --git a/src/test/scala/it/pagopa/interop/purposeprocess/PurposeApiServiceSpec.scala b/src/test/scala/it/pagopa/interop/purposeprocess/PurposeApiServiceSpec.scala index f156663b..792543a0 100644 --- a/src/test/scala/it/pagopa/interop/purposeprocess/PurposeApiServiceSpec.scala +++ b/src/test/scala/it/pagopa/interop/purposeprocess/PurposeApiServiceSpec.scala @@ -2425,104 +2425,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 { diff --git a/src/test/scala/it/pagopa/interop/purposeprocess/SpecData.scala b/src/test/scala/it/pagopa/interop/purposeprocess/SpecData.scala index b6e234f8..d0c656a5 100644 --- a/src/test/scala/it/pagopa/interop/purposeprocess/SpecData.scala +++ b/src/test/scala/it/pagopa/interop/purposeprocess/SpecData.scala @@ -410,9 +410,6 @@ object SpecData { freeOfChargeReason = None ) - def waitingForApprovalUpdate: WaitingForApprovalPurposeVersionUpdateContent = - WaitingForApprovalPurposeVersionUpdateContent(timestamp) - val purposes: Seq[PersistentPurpose] = Seq(purpose) val agreement: PersistentAgreement = diff --git a/src/test/scala/it/pagopa/interop/purposeprocess/authz/PurposeApiAuthzSpec.scala b/src/test/scala/it/pagopa/interop/purposeprocess/authz/PurposeApiAuthzSpec.scala index cc823687..0180a387 100644 --- a/src/test/scala/it/pagopa/interop/purposeprocess/authz/PurposeApiAuthzSpec.scala +++ b/src/test/scala/it/pagopa/interop/purposeprocess/authz/PurposeApiAuthzSpec.scala @@ -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") diff --git a/src/test/scala/it/pagopa/interop/purposeprocess/util/FakeDependencies.scala b/src/test/scala/it/pagopa/interop/purposeprocess/util/FakeDependencies.scala index 67f6b86c..4aeec25c 100644 --- a/src/test/scala/it/pagopa/interop/purposeprocess/util/FakeDependencies.scala +++ b/src/test/scala/it/pagopa/interop/purposeprocess/util/FakeDependencies.scala @@ -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(())