From d94af2261ed0f8c7ca9da79bc09a458d788d893f Mon Sep 17 00:00:00 2001 From: nttdata-rtorsoli Date: Thu, 16 May 2024 15:02:55 +0200 Subject: [PATCH 1/2] PIN-4903 BKE - Error during selfcare information retrieve at the creation of agreement contract --- .../error/AgreementProcessErrors.scala | 7 ++++ .../service/AgreementContractCreator.scala | 35 ++++++++++++++----- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/main/scala/it/pagopa/interop/agreementprocess/error/AgreementProcessErrors.scala b/src/main/scala/it/pagopa/interop/agreementprocess/error/AgreementProcessErrors.scala index 420938d0..7fd008ee 100644 --- a/src/main/scala/it/pagopa/interop/agreementprocess/error/AgreementProcessErrors.scala +++ b/src/main/scala/it/pagopa/interop/agreementprocess/error/AgreementProcessErrors.scala @@ -115,4 +115,11 @@ object AgreementProcessErrors { final case class SelfcareEntityNotFilled(className: String, field: String) extends ComponentError("0026", s"Selfcare entity $className with field $field not filled") + + final case class MissingUsersInfo(consumerId: UUID, producerId: UUID) + extends ComponentError( + "0027", + s"Some mandatory info are missing for consumer ${consumerId.toString()} and producer ${producerId.toString()}" + ) + } diff --git a/src/main/scala/it/pagopa/interop/agreementprocess/service/AgreementContractCreator.scala b/src/main/scala/it/pagopa/interop/agreementprocess/service/AgreementContractCreator.scala index 62f24471..63f7fbc7 100644 --- a/src/main/scala/it/pagopa/interop/agreementprocess/service/AgreementContractCreator.scala +++ b/src/main/scala/it/pagopa/interop/agreementprocess/service/AgreementContractCreator.scala @@ -4,7 +4,12 @@ import akka.http.scaladsl.model.MediaTypes import it.pagopa.interop.agreementprocess.common.Adapters._ import it.pagopa.interop.agreementmanagement.client.model.{DocumentSeed, UpdateAgreementSeed} import it.pagopa.interop.agreementprocess.common.system.ApplicationConfiguration -import it.pagopa.interop.agreementprocess.error.AgreementProcessErrors.{MissingUserInfo, StampNotFound} +import it.pagopa.interop.agreementprocess.error.AgreementProcessErrors.{ + MissingUserInfo, + StampNotFound, + MissingUsersInfo, + SelfcareIdNotFound +} import it.pagopa.interop.agreementprocess.service.util.PDFPayload import it.pagopa.interop.commons.cqrs.service.ReadModelService import it.pagopa.interop.commons.files.service.FileManager @@ -119,14 +124,26 @@ final class AgreementContractCreator( } - def getSubmissionInfo( - seed: UpdateAgreementSeed - )(implicit contexts: Seq[(String, String)], ec: ExecutionContext): Future[(String, OffsetDateTime)] = + def getSubmissionInfo(seed: UpdateAgreementSeed, consumer: PersistentTenant, producer: PersistentTenant)(implicit + contexts: Seq[(String, String)], + ec: ExecutionContext + ): Future[(String, OffsetDateTime)] = for { - selfcareUuidd <- getSelfcareIdFutureUUID(contexts) - submission <- seed.stamps.submission.toFuture(StampNotFound("submission")) - userResponse <- selfcareV2ClientService.getUserById(selfcareUuidd, submission.who).map(_.toApi) - userResponseApi <- userResponse.toFuture.recoverWith { case _ => Future.failed(MissingUserInfo(submission.who)) } + submission <- seed.stamps.submission.toFuture(StampNotFound("submission")) + consumerSelfcareId <- consumer.selfcareId.toFuture(SelfcareIdNotFound(consumer.id)) + producerSelfcareId <- producer.selfcareId.toFuture(SelfcareIdNotFound(producer.id)) + consumerSelfcareUuid <- consumerSelfcareId.toFutureUUID + producerSelfcareUuid <- producerSelfcareId.toFutureUUID + consumerSelfcare <- selfcareV2ClientService.getInstitution(consumerSelfcareUuid).map(_.toApi) + producerSelfcare <- selfcareV2ClientService.getInstitution(producerSelfcareUuid).map(_.toApi) + (consumerApi, producerApi) <- consumerSelfcare.toFuture.zip(producerSelfcare.toFuture) + userResponse <- selfcareV2ClientService + .getUserById(consumerSelfcareUuid, consumerApi.id) + .recoverWith { case _ => selfcareV2ClientService.getUserById(producerSelfcareUuid, producerApi.id) } + .map(_.toApi) + userResponseApi <- userResponse.toFuture.recoverWith { case _ => + Future.failed(MissingUsersInfo(consumerApi.id, producerApi.id)) + } submitter = getUserText(userResponseApi) } yield (submitter, submission.when) @@ -152,7 +169,7 @@ final class AgreementContractCreator( )(implicit contexts: Seq[(String, String)], ec: ExecutionContext): Future[PDFPayload] = { for { (certified, declared, verified) <- getAttributeInvolved(consumer, seed) - (submitter, submissionTimestamp) <- getSubmissionInfo(seed) + (submitter, submissionTimestamp) <- getSubmissionInfo(seed, consumer, producer) (activator, activationTimestamp) <- getActivationInfo(seed) } yield PDFPayload( today = offsetDateTimeSupplier.get(), From 35f0e28047ca59e7bbc5d79e31aa1ce7d74af3ff Mon Sep 17 00:00:00 2001 From: nttdata-rtorsoli Date: Thu, 30 May 2024 09:32:40 +0200 Subject: [PATCH 2/2] PIN-4903 Resolved PR issues --- .../error/AgreementProcessErrors.scala | 7 ------ .../service/AgreementContractCreator.scala | 25 +++++++------------ 2 files changed, 9 insertions(+), 23 deletions(-) diff --git a/src/main/scala/it/pagopa/interop/agreementprocess/error/AgreementProcessErrors.scala b/src/main/scala/it/pagopa/interop/agreementprocess/error/AgreementProcessErrors.scala index 7fd008ee..420938d0 100644 --- a/src/main/scala/it/pagopa/interop/agreementprocess/error/AgreementProcessErrors.scala +++ b/src/main/scala/it/pagopa/interop/agreementprocess/error/AgreementProcessErrors.scala @@ -115,11 +115,4 @@ object AgreementProcessErrors { final case class SelfcareEntityNotFilled(className: String, field: String) extends ComponentError("0026", s"Selfcare entity $className with field $field not filled") - - final case class MissingUsersInfo(consumerId: UUID, producerId: UUID) - extends ComponentError( - "0027", - s"Some mandatory info are missing for consumer ${consumerId.toString()} and producer ${producerId.toString()}" - ) - } diff --git a/src/main/scala/it/pagopa/interop/agreementprocess/service/AgreementContractCreator.scala b/src/main/scala/it/pagopa/interop/agreementprocess/service/AgreementContractCreator.scala index 63f7fbc7..5a139983 100644 --- a/src/main/scala/it/pagopa/interop/agreementprocess/service/AgreementContractCreator.scala +++ b/src/main/scala/it/pagopa/interop/agreementprocess/service/AgreementContractCreator.scala @@ -7,7 +7,6 @@ import it.pagopa.interop.agreementprocess.common.system.ApplicationConfiguration import it.pagopa.interop.agreementprocess.error.AgreementProcessErrors.{ MissingUserInfo, StampNotFound, - MissingUsersInfo, SelfcareIdNotFound } import it.pagopa.interop.agreementprocess.service.util.PDFPayload @@ -124,25 +123,19 @@ final class AgreementContractCreator( } - def getSubmissionInfo(seed: UpdateAgreementSeed, consumer: PersistentTenant, producer: PersistentTenant)(implicit + def getSubmissionInfo(seed: UpdateAgreementSeed, consumer: PersistentTenant)(implicit contexts: Seq[(String, String)], ec: ExecutionContext ): Future[(String, OffsetDateTime)] = for { - submission <- seed.stamps.submission.toFuture(StampNotFound("submission")) - consumerSelfcareId <- consumer.selfcareId.toFuture(SelfcareIdNotFound(consumer.id)) - producerSelfcareId <- producer.selfcareId.toFuture(SelfcareIdNotFound(producer.id)) - consumerSelfcareUuid <- consumerSelfcareId.toFutureUUID - producerSelfcareUuid <- producerSelfcareId.toFutureUUID - consumerSelfcare <- selfcareV2ClientService.getInstitution(consumerSelfcareUuid).map(_.toApi) - producerSelfcare <- selfcareV2ClientService.getInstitution(producerSelfcareUuid).map(_.toApi) - (consumerApi, producerApi) <- consumerSelfcare.toFuture.zip(producerSelfcare.toFuture) - userResponse <- selfcareV2ClientService - .getUserById(consumerSelfcareUuid, consumerApi.id) - .recoverWith { case _ => selfcareV2ClientService.getUserById(producerSelfcareUuid, producerApi.id) } + submission <- seed.stamps.submission.toFuture(StampNotFound("submission")) + consumerSelfcareId <- consumer.selfcareId.toFuture(SelfcareIdNotFound(consumer.id)) + consumerSelfcareUuid <- consumerSelfcareId.toFutureUUID + userResponse <- selfcareV2ClientService + .getUserById(consumerSelfcareUuid, submission.who) .map(_.toApi) - userResponseApi <- userResponse.toFuture.recoverWith { case _ => - Future.failed(MissingUsersInfo(consumerApi.id, producerApi.id)) + userResponseApi <- userResponse.toFuture.recoverWith { case _ => + Future.failed(MissingUserInfo(consumer.id)) } submitter = getUserText(userResponseApi) } yield (submitter, submission.when) @@ -169,7 +162,7 @@ final class AgreementContractCreator( )(implicit contexts: Seq[(String, String)], ec: ExecutionContext): Future[PDFPayload] = { for { (certified, declared, verified) <- getAttributeInvolved(consumer, seed) - (submitter, submissionTimestamp) <- getSubmissionInfo(seed, consumer, producer) + (submitter, submissionTimestamp) <- getSubmissionInfo(seed, consumer) (activator, activationTimestamp) <- getActivationInfo(seed) } yield PDFPayload( today = offsetDateTimeSupplier.get(),