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-4903 BKE - Error during selfcare information retrieve at the creation of agreement contract #263

Merged
merged 2 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -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()}"
)

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
nttdata-rtorsoli marked this conversation as resolved.
Show resolved Hide resolved
nttdata-rtorsoli marked this conversation as resolved.
Show resolved Hide resolved
.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)

Expand All @@ -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(),
Expand Down
Loading