From 19470a2f425d1ea0855081771696daeefec95a93 Mon Sep 17 00:00:00 2001 From: Riccardo Torsoli <122275960+nttdata-rtorsoli@users.noreply.github.com> Date: Thu, 9 Nov 2023 12:30:01 +0100 Subject: [PATCH] PIN-3518 Alignment to Selfcare API v.2 (#252) Co-authored-by: nttdata-rtorsoli --- project/Dependencies.scala | 10 ++- project/Versions.scala | 3 +- .../resources/application-standalone.conf | 5 +- src/main/resources/application.conf | 6 +- .../api/impl/AgreementApiServiceImpl.scala | 28 +++++---- .../agreementprocess/common/Adapters.scala | 24 ++++++- .../system/ApplicationConfiguration.scala | 14 ++--- .../error/AgreementProcessErrors.scala | 9 +++ .../server/impl/Dependencies.scala | 23 +++---- .../service/AgreementContractCreator.scala | 28 +++++---- .../service/PartyProcessService.scala | 12 ---- .../service/SelfcareV2ClientService.scala | 17 +++++ .../service/UserRegistryService.scala | 11 ---- .../impl/PartyProcessServiceImpl.scala | 54 ---------------- .../impl/SelfcareV2ClientServiceImpl.scala | 52 ++++++++++++++++ .../impl/UserRegistryServiceImpl.scala | 25 -------- .../service/model/Institution.scala | 5 ++ .../service/model/UserResponse.scala | 5 ++ .../agreementprocess/service/package.scala | 24 +++---- src/test/resources/application-test.conf | 6 +- .../AgreementApiAuthzSpec.scala | 6 +- .../interop/agreementprocess/SpecData.scala | 15 +++-- .../interop/agreementprocess/SpecHelper.scala | 62 +++++++++---------- .../util/FakeDependencies.scala | 48 ++++---------- 24 files changed, 225 insertions(+), 267 deletions(-) delete mode 100644 src/main/scala/it/pagopa/interop/agreementprocess/service/PartyProcessService.scala create mode 100644 src/main/scala/it/pagopa/interop/agreementprocess/service/SelfcareV2ClientService.scala delete mode 100644 src/main/scala/it/pagopa/interop/agreementprocess/service/UserRegistryService.scala delete mode 100644 src/main/scala/it/pagopa/interop/agreementprocess/service/impl/PartyProcessServiceImpl.scala create mode 100644 src/main/scala/it/pagopa/interop/agreementprocess/service/impl/SelfcareV2ClientServiceImpl.scala delete mode 100644 src/main/scala/it/pagopa/interop/agreementprocess/service/impl/UserRegistryServiceImpl.scala create mode 100644 src/main/scala/it/pagopa/interop/agreementprocess/service/model/Institution.scala create mode 100644 src/main/scala/it/pagopa/interop/agreementprocess/service/model/UserResponse.scala diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 6aafb369..0844f7f8 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -35,11 +35,10 @@ object Dependencies { namespace %% "interop-be-authorization-management-client" % authorizationManagementVersion lazy val catalogManagementModels = namespace %% "interop-be-catalog-management-models" % catalogManagementVersion - lazy val partyProcessClient = namespace %% "interop-selfcare-party-process-client" % partyProcessVersion + lazy val selfcareV2Client = + namespace %% "interop-selfcare-v2-client" % selfcareV2ClientVersion lazy val tenantManagementModels = namespace %% "interop-be-tenant-management-models" % tenantManagementVersion - lazy val userRegistryManagement = - namespace %% "interop-selfcare-user-registry-client" % userRegistryManagementVersion - + lazy val commons = namespace %% "interop-commons-utils" % commonsVersion lazy val commonsMailManager = namespace %% "interop-commons-mail-manager" % commonsVersion lazy val commonsFileManager = namespace %% "interop-commons-file-manager" % commonsVersion @@ -112,6 +111,7 @@ object Dependencies { pagopa.agreementManagementClient % Compile, pagopa.agreementManagementModels % Compile, pagopa.attributeRegistryManagementModels % Compile, + pagopa.selfcareV2Client % Compile, pagopa.authorizationManagementClient % Compile, pagopa.catalogManagementModels % Compile, pagopa.tenantManagementModels % Compile, @@ -121,8 +121,6 @@ object Dependencies { pagopa.commonsJWT % Compile, pagopa.commonsCqrs % Compile, pagopa.commonsQueueManager % Compile, - pagopa.partyProcessClient % Compile, - pagopa.userRegistryManagement % Compile, akka.httpTestkit % Test, akka.testkit % Test, akka.untypedTestkit % Test, diff --git a/project/Versions.scala b/project/Versions.scala index e1612b0f..2febf535 100644 --- a/project/Versions.scala +++ b/project/Versions.scala @@ -26,7 +26,6 @@ object PagopaVersion { lazy val catalogManagementVersion = "1.0.x-SNAPSHOT" lazy val commonsVersion = "1.0.x-SNAPSHOT" lazy val certifiedMailSenderModelsVersion = "1.0.x-SNAPSHOT" - lazy val partyProcessVersion = "1.0.x-SNAPSHOT" lazy val tenantManagementVersion = "1.0.x-SNAPSHOT" - lazy val userRegistryManagementVersion = "1.0.x-SNAPSHOT" + lazy val selfcareV2ClientVersion = "1.0.x-SNAPSHOT" } diff --git a/src/main/resources/application-standalone.conf b/src/main/resources/application-standalone.conf index 0da8bfad..25cc52de 100644 --- a/src/main/resources/application-standalone.conf +++ b/src/main/resources/application-standalone.conf @@ -25,8 +25,7 @@ agreement-process { jwt { audience = ${ACCEPTED_AUDIENCES} } - user-registry-api-key = ${USER_REGISTRY_API_KEY} - party-process-api-key = ${PARTY_PROCESS_API_KEY} + selfcare-v2-client-api-key = ${SELFCARE_V2_API_KEY} services { catalog-management = "https://gateway.interop.pdnd.dev/catalog-management/0.1" agreement-management = "https://gateway.interop.pdnd.dev/agreement-management/0.1" @@ -34,7 +33,7 @@ agreement-process { authorization-management = "https://gateway.interop.pdnd.dev/authorization-management/0.1" tenant-management = "https://gateway.interop.pdnd.dev/tenant-management/0.1" party-process = "https://gateway.interop.pdnd.dev/party-process/0.1" - user-registry = "https://gateway.interop.pdnd.dev/user-registry/0.1" + selfcare-v2-client = "https://gateway.interop.pdnd.dev/userselfcare-v2-client/0.1" } queue { diff --git a/src/main/resources/application.conf b/src/main/resources/application.conf index cf2c9fa3..def9b463 100644 --- a/src/main/resources/application.conf +++ b/src/main/resources/application.conf @@ -25,16 +25,14 @@ agreement-process { jwt { audience = ${ACCEPTED_AUDIENCES} } - user-registry-api-key = ${USER_REGISTRY_API_KEY} - party-process-api-key = ${PARTY_PROCESS_API_KEY} + selfcare-v2-client-api-key = ${SELFCARE_V2_API_KEY} services { catalog-management = ${CATALOG_MANAGEMENT_URL} tenant-management = ${TENANT_MANAGEMENT_URL} agreement-management = ${AGREEMENT_MANAGEMENT_URL} attribute-registry-management = ${ATTRIBUTE_REGISTRY_MANAGEMENT_URL} authorization-management = ${AUTHORIZATION_MANAGEMENT_URL} - party-process = ${PARTY_PROCESS_URL} - user-registry = ${USER_REGISTRY_URL} + selfcare-v2-client = ${SELFCARE_V2_URL} } queue { diff --git a/src/main/scala/it/pagopa/interop/agreementprocess/api/impl/AgreementApiServiceImpl.scala b/src/main/scala/it/pagopa/interop/agreementprocess/api/impl/AgreementApiServiceImpl.scala index f8d8d7b2..7d7c69f7 100644 --- a/src/main/scala/it/pagopa/interop/agreementprocess/api/impl/AgreementApiServiceImpl.scala +++ b/src/main/scala/it/pagopa/interop/agreementprocess/api/impl/AgreementApiServiceImpl.scala @@ -60,8 +60,7 @@ final case class AgreementApiServiceImpl( tenantManagementService: TenantManagementService, attributeManagementService: AttributeManagementService, authorizationManagementService: AuthorizationManagementService, - partyProcessService: PartyProcessService, - userRegistry: UserRegistryService, + selfcareV2ClientService: SelfcareV2ClientService, pdfCreator: PDFCreator, fileManager: FileManager, offsetDateTimeSupplier: OffsetDateTimeSupplier, @@ -85,7 +84,7 @@ final case class AgreementApiServiceImpl( uuidSupplier, agreementManagementService, attributeManagementService, - userRegistry, + selfcareV2ClientService, offsetDateTimeSupplier ) @@ -847,24 +846,27 @@ final case class AgreementApiServiceImpl( val subject: String = activationMailTemplate.subject.interpolate(Map("agreementId" -> agreement.id.toString)) val envelope: Future[TextMail] = for { - producerSelfcareId <- producerTenant.selfcareId.toFuture(SelfcareIdNotFound(producerTenant.id)) - consumerSelfcareId <- consumerTenant.selfcareId.toFuture(SelfcareIdNotFound(consumerTenant.id)) - activationDate <- agreement.stamps.activation.map(_.when).toFuture(StampNotFound("activation")) - producer <- partyProcessService.getInstitution(producerSelfcareId) - consumer <- partyProcessService.getInstitution(consumerSelfcareId) - version <- eservice.descriptors + producerSelfcareId <- producerTenant.selfcareId.toFuture(SelfcareIdNotFound(producerTenant.id)) + consumerSelfcareId <- consumerTenant.selfcareId.toFuture(SelfcareIdNotFound(consumerTenant.id)) + producerSelfcareUuid <- producerSelfcareId.toFutureUUID + consumerSelfcareUuid <- consumerSelfcareId.toFutureUUID + activationDate <- agreement.stamps.activation.map(_.when).toFuture(StampNotFound("activation")) + producer <- selfcareV2ClientService.getInstitution(producerSelfcareUuid).map(_.toApi) + consumer <- selfcareV2ClientService.getInstitution(consumerSelfcareUuid).map(_.toApi) + (producerApi, consumerApi) <- producer.toFuture.zip(consumer.toFuture) + version <- eservice.descriptors .find(_.id == agreement.descriptorId) .toFuture(DescriptorNotFound(eServiceId = eservice.id, descriptorId = agreement.descriptorId)) - producerAddress <- Mail.addresses(producer.digitalAddress).toFuture - consumerAddress <- Mail.addresses(consumer.digitalAddress).toFuture + producerAddress <- Mail.addresses(producerApi.digitalAddress).toFuture + consumerAddress <- Mail.addresses(consumerApi.digitalAddress).toFuture } yield TextMail( id = envelopeId, recipients = producerAddress ++ consumerAddress, subject = subject, body = createBody( activationDate = activationDate, - producer = producer.description, - consumer = consumer.description, + producer = producerApi.description, + consumer = consumerApi.description, eserviceName = eservice.name, eserviceVersion = version.version ), diff --git a/src/main/scala/it/pagopa/interop/agreementprocess/common/Adapters.scala b/src/main/scala/it/pagopa/interop/agreementprocess/common/Adapters.scala index cf2be5e7..d73ad011 100644 --- a/src/main/scala/it/pagopa/interop/agreementprocess/common/Adapters.scala +++ b/src/main/scala/it/pagopa/interop/agreementprocess/common/Adapters.scala @@ -4,8 +4,12 @@ import cats.implicits._ import it.pagopa.interop.agreementmanagement.client.{model => AgreementManagement} import it.pagopa.interop.agreementprocess.error.AgreementProcessErrors.{ AgreementNotInExpectedState, - InvalidAttributeStructure + InvalidAttributeStructure, + SelfcareEntityNotFilled } +import it.pagopa.interop.commons.utils.TypeConversions._ +import it.pagopa.interop.agreementprocess.service.model.{Institution, UserResponse} +import it.pagopa.interop.selfcare.v2.client.{model => SelfcareV2Dependency} import it.pagopa.interop.agreementprocess.model._ import it.pagopa.interop.agreementmanagement.model.agreement._ import it.pagopa.interop.tenantmanagement.model.{tenant => TenantManagement} @@ -396,4 +400,22 @@ object Adapters { case _ => InvalidAttributeStructure.asLeft } } + + implicit class InstitutionWrapper(private val ist: SelfcareV2Dependency.Institution) extends AnyVal { + def toApi: Either[Throwable, Institution] = for { + id <- ist.id.toRight(SelfcareEntityNotFilled(ist.getClass().getName(), "id")) + digitalAddress <- ist.digitalAddress.toRight(SelfcareEntityNotFilled(ist.getClass().getName(), "digitalAddress")) + description <- ist.description.toRight(SelfcareEntityNotFilled(ist.getClass().getName(), "description")) + } yield (Institution(id = id, digitalAddress = digitalAddress, description = description)) + } + + implicit class UserResponseWrapper(private val ur: SelfcareV2Dependency.UserResponse) extends AnyVal { + def toApi: Either[Throwable, UserResponse] = for { + id <- ur.id.toRight(SelfcareEntityNotFilled(ur.getClass().getName(), "id")) + uuid <- id.toUUID.toEither + name <- ur.name.toRight(SelfcareEntityNotFilled(ur.getClass().getName(), "name")) + surname <- ur.surname.toRight(SelfcareEntityNotFilled(ur.getClass().getName(), "surname")) + taxCode <- ur.taxCode.toRight(SelfcareEntityNotFilled(ur.getClass().getName(), "taxCode")) + } yield UserResponse(id = uuid, name = name, surname = surname, taxCode = taxCode) + } } diff --git a/src/main/scala/it/pagopa/interop/agreementprocess/common/system/ApplicationConfiguration.scala b/src/main/scala/it/pagopa/interop/agreementprocess/common/system/ApplicationConfiguration.scala index b5520ab9..681af4d1 100644 --- a/src/main/scala/it/pagopa/interop/agreementprocess/common/system/ApplicationConfiguration.scala +++ b/src/main/scala/it/pagopa/interop/agreementprocess/common/system/ApplicationConfiguration.scala @@ -11,20 +11,18 @@ object ApplicationConfiguration { val catalogManagementURL: String = config.getString("agreement-process.services.catalog-management") val tenantManagementURL: String = config.getString("agreement-process.services.tenant-management") val authorizationManagementURL: String = config.getString("agreement-process.services.authorization-management") - val userRegistryURL: String = config.getString("agreement-process.services.user-registry") - val partyProcessURL: String = config.getString("agreement-process.services.party-process") + val selfcareV2ClientURL: String = config.getString("agreement-process.services.selfcare-v2-client") val jwtAudience: Set[String] = config.getString("agreement-process.jwt.audience").split(",").toSet.filter(_.nonEmpty) val attributeRegistryManagementURL: String = config.getString("agreement-process.services.attribute-registry-management") require(jwtAudience.nonEmpty, "Audience cannot be empty") - val storageKind: String = config.getString("agreement-process.storage.kind") - val storageContainer: String = config.getString("agreement-process.storage.container") - val agreementContractPath: String = config.getString("agreement-process.storage.agreement-contract-path") - val consumerDocumentsPath: String = config.getString("agreement-process.storage.consumer-documents-path") - val userRegistryApiKey: String = config.getString("agreement-process.user-registry-api-key") - val partyProcessApiKey: String = config.getString("agreement-process.party-process-api-key") + val storageKind: String = config.getString("agreement-process.storage.kind") + val storageContainer: String = config.getString("agreement-process.storage.container") + val agreementContractPath: String = config.getString("agreement-process.storage.agreement-contract-path") + val consumerDocumentsPath: String = config.getString("agreement-process.storage.consumer-documents-path") + val selfcareV2ClientApiKey: String = config.getString("agreement-process.selfcare-v2-client-api-key") val readModelConfig: ReadModelConfig = { val connectionString: String = config.getString("agreement-process.read-model.db.connection-string") 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 b41de705..420938d0 100644 --- a/src/main/scala/it/pagopa/interop/agreementprocess/error/AgreementProcessErrors.scala +++ b/src/main/scala/it/pagopa/interop/agreementprocess/error/AgreementProcessErrors.scala @@ -106,4 +106,13 @@ object AgreementProcessErrors { ) case object InvalidAttributeStructure extends ComponentError("0023", "Invalid Attribute Structure") + + final case class InstitutionNotFound(selfcareId: UUID) + extends ComponentError("0024", s"Institution $selfcareId not found") + + final case class UserNotFound(selfcareId: UUID, userId: UUID) + extends ComponentError("0025", s"User $userId not found for selfcare institution $selfcareId") + + final case class SelfcareEntityNotFilled(className: String, field: String) + extends ComponentError("0026", s"Selfcare entity $className with field $field not filled") } diff --git a/src/main/scala/it/pagopa/interop/agreementprocess/server/impl/Dependencies.scala b/src/main/scala/it/pagopa/interop/agreementprocess/server/impl/Dependencies.scala index adfd2660..58b266b6 100644 --- a/src/main/scala/it/pagopa/interop/agreementprocess/server/impl/Dependencies.scala +++ b/src/main/scala/it/pagopa/interop/agreementprocess/server/impl/Dependencies.scala @@ -17,6 +17,7 @@ import it.pagopa.interop.agreementprocess.common.system.ApplicationConfiguration import it.pagopa.interop.agreementprocess.service._ import it.pagopa.interop.agreementprocess.service.impl._ import it.pagopa.interop.authorizationmanagement.client.api.PurposeApi +import it.pagopa.interop.selfcare.v2.client.api.{InstitutionsApi, UsersApi} import it.pagopa.interop.commons.cqrs.service.{MongoDbReadModelService, ReadModelService} import it.pagopa.interop.commons.files.service.FileManager import it.pagopa.interop.commons.jwt.service.JWTReader @@ -29,8 +30,6 @@ import it.pagopa.interop.commons.utils.TypeConversions._ import it.pagopa.interop.commons.utils.errors.{Problem => CommonProblem} import it.pagopa.interop.commons.utils.service.{OffsetDateTimeSupplier, UUIDSupplier} import it.pagopa.interop.commons.utils.{AkkaUtils, OpenapiUtils} -import it.pagopa.interop.selfcare.partyprocess.client.api.ProcessApi -import it.pagopa.interop.selfcare.userregistry.client.api.UserApi import scala.concurrent.{ExecutionContext, ExecutionContextExecutor, Future} @@ -39,7 +38,7 @@ trait Dependencies { implicit val loggerTI: LoggerTakingImplicit[ContextFieldsToLog] = Logger.takingImplicit[ContextFieldsToLog]("OAuth2JWTValidatorAsContexts") - implicit val userRegistryApiKeyValue: UserRegistryApiKeyValue = UserRegistryApiKeyValue() + implicit val selfcareV2ClientApiKeyValue: SelfcareV2ClientApiKeyValue = SelfcareV2ClientApiKeyValue() implicit val readModelService: ReadModelService = new MongoDbReadModelService( ApplicationConfiguration.readModelConfig @@ -61,16 +60,11 @@ trait Dependencies { new PurposeApi(ApplicationConfiguration.authorizationManagementURL) ) - def partyProcess(implicit actorSystem: ActorSystem[_]): PartyProcessService = - new PartyProcessServiceImpl( - PartyProcessServiceInvoker()(actorSystem.classicSystem), - new ProcessApi(ApplicationConfiguration.partyProcessURL) - ) - - def userRegistry(implicit actorSystem: ActorSystem[_]): UserRegistryService = - new UserRegistryServiceImpl( - UserRegistryManagementInvoker()(actorSystem.classicSystem), - UserApi(ApplicationConfiguration.userRegistryURL) + def selfcareV2Client(implicit actorSystem: ActorSystem[_]): SelfcareV2ClientService = + new SelfcareV2ClientServiceImpl( + SelfcareV2ClientInvoker()(actorSystem.classicSystem), + new InstitutionsApi(ApplicationConfiguration.selfcareV2ClientURL), + new UsersApi(ApplicationConfiguration.selfcareV2ClientURL) ) def getJwtValidator(): Future[JWTReader] = JWTConfiguration.jwtReader @@ -125,8 +119,7 @@ trait Dependencies { TenantManagementServiceImpl, AttributeManagementServiceImpl, authorizationManagement(blockingEc), - partyProcess, - userRegistry, + selfcareV2Client, PDFCreator, fileManager(blockingEc), OffsetDateTimeSupplier, 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 c9937990..62f24471 100644 --- a/src/main/scala/it/pagopa/interop/agreementprocess/service/AgreementContractCreator.scala +++ b/src/main/scala/it/pagopa/interop/agreementprocess/service/AgreementContractCreator.scala @@ -1,6 +1,7 @@ package it.pagopa.interop.agreementprocess.service 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} @@ -9,7 +10,6 @@ import it.pagopa.interop.commons.cqrs.service.ReadModelService import it.pagopa.interop.commons.files.service.FileManager import it.pagopa.interop.commons.utils.TypeConversions._ import it.pagopa.interop.commons.utils.service.{OffsetDateTimeSupplier, UUIDSupplier} -import it.pagopa.interop.selfcare.userregistry.client.model.UserResource import it.pagopa.interop.catalogmanagement.model.CatalogItem import it.pagopa.interop.agreementmanagement.model.agreement.PersistentAgreement import it.pagopa.interop.tenantmanagement.model.tenant.{ @@ -18,12 +18,14 @@ import it.pagopa.interop.tenantmanagement.model.tenant.{ PersistentDeclaredAttribute, PersistentVerifiedAttribute } +import it.pagopa.interop.commons.utils.AkkaUtils.getSelfcareIdFutureUUID import java.time.OffsetDateTime import java.time.format.DateTimeFormatter import java.util.UUID import scala.concurrent.{ExecutionContext, Future} import scala.io.Source +import it.pagopa.interop.agreementprocess.service.model.UserResponse final class AgreementContractCreator( pdfCreator: PDFCreator, @@ -31,7 +33,7 @@ final class AgreementContractCreator( uuidSupplier: UUIDSupplier, agreementManagementService: AgreementManagementService, attributeManagementService: AttributeManagementService, - userRegistry: UserRegistryService, + selfcareV2ClientService: SelfcareV2ClientService, offsetDateTimeSupplier: OffsetDateTimeSupplier )(implicit readModel: ReadModelService) { @@ -121,25 +123,25 @@ final class AgreementContractCreator( seed: UpdateAgreementSeed )(implicit contexts: Seq[(String, String)], ec: ExecutionContext): Future[(String, OffsetDateTime)] = for { - submission <- seed.stamps.submission.toFuture(StampNotFound("submission")) - response <- userRegistry.getUserById(submission.who) - submitter <- getUserText(response).toFuture(MissingUserInfo(submission.who)) + 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)) } + submitter = getUserText(userResponseApi) } yield (submitter, submission.when) def getActivationInfo( seed: UpdateAgreementSeed )(implicit contexts: Seq[(String, String)], ec: ExecutionContext): Future[(String, OffsetDateTime)] = for { - activation <- seed.stamps.activation.toFuture(StampNotFound("activation")) - response <- userRegistry.getUserById(activation.who) - activator <- getUserText(response).toFuture(MissingUserInfo(activation.who)) + selfcareUuidd <- getSelfcareIdFutureUUID(contexts) + activation <- seed.stamps.activation.toFuture(StampNotFound("activation")) + userResponse <- selfcareV2ClientService.getUserById(selfcareUuidd, activation.who).map(_.toApi) + userResponseApi <- userResponse.toFuture.recoverWith { case _ => Future.failed(MissingUserInfo(activation.who)) } + activator = getUserText(userResponseApi) } yield (activator, activation.when) - def getUserText(user: UserResource): Option[String] = for { - name <- user.name - familyName <- user.familyName - fiscalCode <- user.fiscalCode - } yield s"${name.value} ${familyName.value} ($fiscalCode)" + def getUserText(user: UserResponse): String = s"${user.name} ${user.surname} (${user.taxCode})" def getPdfPayload( agreement: PersistentAgreement, diff --git a/src/main/scala/it/pagopa/interop/agreementprocess/service/PartyProcessService.scala b/src/main/scala/it/pagopa/interop/agreementprocess/service/PartyProcessService.scala deleted file mode 100644 index 803026e2..00000000 --- a/src/main/scala/it/pagopa/interop/agreementprocess/service/PartyProcessService.scala +++ /dev/null @@ -1,12 +0,0 @@ -package it.pagopa.interop.agreementprocess.service - -import it.pagopa.interop.selfcare.partyprocess.client.model.Institution - -import scala.concurrent.{ExecutionContext, Future} - -trait PartyProcessService { - - def getInstitution( - selfcareId: String - )(implicit contexts: Seq[(String, String)], ec: ExecutionContext): Future[Institution] -} diff --git a/src/main/scala/it/pagopa/interop/agreementprocess/service/SelfcareV2ClientService.scala b/src/main/scala/it/pagopa/interop/agreementprocess/service/SelfcareV2ClientService.scala new file mode 100644 index 00000000..80bef474 --- /dev/null +++ b/src/main/scala/it/pagopa/interop/agreementprocess/service/SelfcareV2ClientService.scala @@ -0,0 +1,17 @@ +package it.pagopa.interop.agreementprocess.service + +import scala.concurrent.{ExecutionContext, Future} +import it.pagopa.interop.selfcare.v2.client.model.{Institution, UserResponse} +import java.util.UUID + +trait SelfcareV2ClientService { + + def getInstitution( + selfcareId: UUID + )(implicit contexts: Seq[(String, String)], ec: ExecutionContext): Future[Institution] + + def getUserById(selfcareId: UUID, userId: UUID)(implicit + contexts: Seq[(String, String)], + ec: ExecutionContext + ): Future[UserResponse] +} diff --git a/src/main/scala/it/pagopa/interop/agreementprocess/service/UserRegistryService.scala b/src/main/scala/it/pagopa/interop/agreementprocess/service/UserRegistryService.scala deleted file mode 100644 index 1e1f66e0..00000000 --- a/src/main/scala/it/pagopa/interop/agreementprocess/service/UserRegistryService.scala +++ /dev/null @@ -1,11 +0,0 @@ -package it.pagopa.interop.agreementprocess.service - -import it.pagopa.interop.selfcare.userregistry.client.model.UserResource - -import java.util.UUID -import scala.concurrent.Future - -trait UserRegistryService { - - def getUserById(id: UUID)(implicit contexts: Seq[(String, String)]): Future[UserResource] -} diff --git a/src/main/scala/it/pagopa/interop/agreementprocess/service/impl/PartyProcessServiceImpl.scala b/src/main/scala/it/pagopa/interop/agreementprocess/service/impl/PartyProcessServiceImpl.scala deleted file mode 100644 index 1120bc5f..00000000 --- a/src/main/scala/it/pagopa/interop/agreementprocess/service/impl/PartyProcessServiceImpl.scala +++ /dev/null @@ -1,54 +0,0 @@ -package it.pagopa.interop.agreementprocess.service.impl - -import com.typesafe.scalalogging.{Logger, LoggerTakingImplicit} -import it.pagopa.interop.agreementprocess.common.system.ApplicationConfiguration -import it.pagopa.interop.agreementprocess.service.{PartyProcessInvoker, PartyProcessService} -import it.pagopa.interop.commons.logging.{CanLogContextFields, ContextFieldsToLog} -import it.pagopa.interop.commons.utils.TypeConversions._ -import it.pagopa.interop.commons.utils.errors.GenericComponentErrors.{ - GenericClientError, - ResourceNotFoundError, - ThirdPartyCallError -} -import it.pagopa.interop.commons.utils.withUid -import it.pagopa.interop.selfcare.partyprocess.client.api.ProcessApi -import it.pagopa.interop.selfcare.partyprocess.client.invoker.{ApiError, ApiKeyValue} -import it.pagopa.interop.selfcare.partyprocess.client.model.Institution - -import scala.concurrent.{ExecutionContext, Future} - -final class PartyProcessServiceImpl(invoker: PartyProcessInvoker, api: ProcessApi) extends PartyProcessService { - - implicit val partyProcessApiKeyValue: ApiKeyValue = ApiKeyValue(ApplicationConfiguration.partyProcessApiKey) - - private val replacementEntityId: String = "NoIdentifier" - private val serviceName: String = "party-process" - - implicit val logger: LoggerTakingImplicit[ContextFieldsToLog] = - Logger.takingImplicit[ContextFieldsToLog](this.getClass) - - override def getInstitution( - selfcareId: String - )(implicit contexts: Seq[(String, String)], ec: ExecutionContext): Future[Institution] = withUid { uid => - selfcareId.toFutureUUID.flatMap { selfcareUUID => - val request = api.getInstitution(selfcareUUID)(uid) - invoker.invoke(request, s"Institution ${selfcareId}", invocationRecovery(None)) - } - } - - private def invocationRecovery[T]( - entityId: Option[String] - ): (ContextFieldsToLog, LoggerTakingImplicit[ContextFieldsToLog], String) => PartialFunction[Throwable, Future[T]] = - (context, logger, msg) => { - case ex @ ApiError(code, message, _, _, _) if code == 404 => - logger.error(s"$msg. code > $code - message > $message", ex)(context) - Future.failed[T](ResourceNotFoundError(entityId.getOrElse(replacementEntityId))) - case ex @ ApiError(code, message, _, _, _) => - logger.error(s"$msg. code > $code - message > $message", ex)(context) - Future.failed[T](ThirdPartyCallError(serviceName, ex.getMessage)) - case ex => - logger.error(s"$msg. Error: ${ex.getMessage}", ex)(context) - Future.failed[T](GenericClientError(ex.getMessage)) - } - -} diff --git a/src/main/scala/it/pagopa/interop/agreementprocess/service/impl/SelfcareV2ClientServiceImpl.scala b/src/main/scala/it/pagopa/interop/agreementprocess/service/impl/SelfcareV2ClientServiceImpl.scala new file mode 100644 index 00000000..af9a67ac --- /dev/null +++ b/src/main/scala/it/pagopa/interop/agreementprocess/service/impl/SelfcareV2ClientServiceImpl.scala @@ -0,0 +1,52 @@ +package it.pagopa.interop.agreementprocess.service.impl + +import com.typesafe.scalalogging.{Logger, LoggerTakingImplicit} +import it.pagopa.interop.agreementprocess.service.{ + SelfcareV2ClientInvoker, + SelfcareV2ClientApiKeyValue, + SelfcareV2ClientService +} +import it.pagopa.interop.agreementprocess.error.AgreementProcessErrors.{InstitutionNotFound, UserNotFound} +import it.pagopa.interop.commons.logging.{CanLogContextFields, ContextFieldsToLog} +import it.pagopa.interop.selfcare.v2.client.api.{InstitutionsApi, UsersApi} +import it.pagopa.interop.selfcare.v2.client.invoker.{ApiError, ApiRequest} +import it.pagopa.interop.selfcare.v2.client.model.{Institution, UserResponse} +import cats.syntax.all._ + +import scala.concurrent.{ExecutionContext, Future} +import java.util.UUID + +final class SelfcareV2ClientServiceImpl( + invoker: SelfcareV2ClientInvoker, + institutionsApi: InstitutionsApi, + usersApi: UsersApi +)(implicit selfcareClientApiKeyValue: SelfcareV2ClientApiKeyValue) + extends SelfcareV2ClientService { + + implicit val logger: LoggerTakingImplicit[ContextFieldsToLog] = + Logger.takingImplicit[ContextFieldsToLog](this.getClass) + + override def getInstitution( + selfcareId: UUID + )(implicit contexts: Seq[(String, String)], ec: ExecutionContext): Future[Institution] = { + val request: ApiRequest[Institution] = institutionsApi.getInstitution(selfcareId) + invoker + .invoke(request, s"Institution ${selfcareId}") + .recoverWith { + case err: ApiError[_] if err.code == 404 => Future.failed(InstitutionNotFound(selfcareId)) + } + } + + override def getUserById(selfcareId: UUID, userId: UUID)(implicit + contexts: Seq[(String, String)], + ec: ExecutionContext + ): Future[UserResponse] = { + val request: ApiRequest[UserResponse] = + usersApi.getUserInfoUsingGET(id = userId.toString, institutionId = selfcareId.toString.some) + invoker + .invoke(request, s"Retrieving User with with istitution id $selfcareId, user $userId") + .recoverWith { + case err: ApiError[_] if err.code == 404 => Future.failed(UserNotFound(selfcareId, userId)) + } + } +} diff --git a/src/main/scala/it/pagopa/interop/agreementprocess/service/impl/UserRegistryServiceImpl.scala b/src/main/scala/it/pagopa/interop/agreementprocess/service/impl/UserRegistryServiceImpl.scala deleted file mode 100644 index f0f3de46..00000000 --- a/src/main/scala/it/pagopa/interop/agreementprocess/service/impl/UserRegistryServiceImpl.scala +++ /dev/null @@ -1,25 +0,0 @@ -package it.pagopa.interop.agreementprocess.service.impl - -import com.typesafe.scalalogging.{Logger, LoggerTakingImplicit} -import it.pagopa.interop.agreementprocess.service.{UserRegistryManagementInvoker, UserRegistryService} -import it.pagopa.interop.commons.logging.{CanLogContextFields, ContextFieldsToLog} -import it.pagopa.interop.selfcare.userregistry.client.api.UserApi -import it.pagopa.interop.selfcare.userregistry.client.invoker.{ApiKeyValue, ApiRequest} -import it.pagopa.interop.selfcare.userregistry.client.model.{Field, UserResource} - -import java.util.UUID -import scala.concurrent.Future - -final class UserRegistryServiceImpl(invoker: UserRegistryManagementInvoker, api: UserApi)(implicit - apiKeyValue: ApiKeyValue -) extends UserRegistryService { - - implicit val logger: LoggerTakingImplicit[ContextFieldsToLog] = - Logger.takingImplicit[ContextFieldsToLog](this.getClass) - - override def getUserById(id: UUID)(implicit contexts: Seq[(String, String)]): Future[UserResource] = { - val request: ApiRequest[UserResource] = - api.findByIdUsingGET(id, Seq(Field.name, Field.familyName, Field.fiscalCode)) - invoker.invoke(request, "Retrieve User by ID") - } -} diff --git a/src/main/scala/it/pagopa/interop/agreementprocess/service/model/Institution.scala b/src/main/scala/it/pagopa/interop/agreementprocess/service/model/Institution.scala new file mode 100644 index 00000000..83426ca3 --- /dev/null +++ b/src/main/scala/it/pagopa/interop/agreementprocess/service/model/Institution.scala @@ -0,0 +1,5 @@ +package it.pagopa.interop.agreementprocess.service.model + +import java.util.UUID + +final case class Institution(id: UUID, digitalAddress: String, description: String) diff --git a/src/main/scala/it/pagopa/interop/agreementprocess/service/model/UserResponse.scala b/src/main/scala/it/pagopa/interop/agreementprocess/service/model/UserResponse.scala new file mode 100644 index 00000000..6c798429 --- /dev/null +++ b/src/main/scala/it/pagopa/interop/agreementprocess/service/model/UserResponse.scala @@ -0,0 +1,5 @@ +package it.pagopa.interop.agreementprocess.service.model + +import java.util.UUID + +final case class UserResponse(id: UUID, name: String, surname: String, taxCode: String) diff --git a/src/main/scala/it/pagopa/interop/agreementprocess/service/package.scala b/src/main/scala/it/pagopa/interop/agreementprocess/service/package.scala index 8aa9aeff..1a099c82 100644 --- a/src/main/scala/it/pagopa/interop/agreementprocess/service/package.scala +++ b/src/main/scala/it/pagopa/interop/agreementprocess/service/package.scala @@ -3,22 +3,20 @@ package it.pagopa.interop.agreementprocess import akka.actor.ActorSystem import it.pagopa.interop._ import it.pagopa.interop.agreementprocess.common.system.ApplicationConfiguration -import it.pagopa.interop.selfcare._ import scala.concurrent.ExecutionContextExecutor package object service { type AgreementManagementInvoker = agreementmanagement.client.invoker.ApiInvoker type AuthorizationManagementInvoker = authorizationmanagement.client.invoker.ApiInvoker - type PartyProcessInvoker = partyprocess.client.invoker.ApiInvoker - type UserRegistryManagementInvoker = userregistry.client.invoker.ApiInvoker + type SelfcareV2ClientInvoker = selfcare.v2.client.invoker.ApiInvoker type AgreementManagementApi = agreementmanagement.client.api.AgreementApi - type UserRegistryApiKeyValue = selfcare.userregistry.client.invoker.ApiKeyValue - object UserRegistryApiKeyValue { - def apply(): UserRegistryApiKeyValue = - userregistry.client.invoker.ApiKeyValue(ApplicationConfiguration.userRegistryApiKey) + type SelfcareV2ClientApiKeyValue = selfcare.v2.client.invoker.ApiKeyValue + object SelfcareV2ClientApiKeyValue { + def apply(): SelfcareV2ClientApiKeyValue = + selfcare.v2.client.invoker.ApiKeyValue(ApplicationConfiguration.selfcareV2ClientApiKey) } type ClientAttribute = attributeregistrymanagement.model.persistence.attribute.PersistentAttribute @@ -33,18 +31,12 @@ package object service { .ApiInvoker(authorizationmanagement.client.api.EnumsSerializers.all, blockingEc) } - object PartyProcessServiceInvoker { - def apply()(implicit actorSystem: ActorSystem): PartyProcessInvoker = - partyprocess.client.invoker.ApiInvoker(partyprocess.client.api.EnumsSerializers.all) + object SelfcareV2ClientInvoker { + def apply()(implicit actorSystem: ActorSystem): SelfcareV2ClientInvoker = + selfcare.v2.client.invoker.ApiInvoker(selfcare.v2.client.api.EnumsSerializers.all) } object AgreementManagementApi { def apply(baseUrl: String): AgreementManagementApi = agreementmanagement.client.api.AgreementApi(baseUrl) } - - object UserRegistryManagementInvoker { - def apply()(implicit actorSystem: ActorSystem): UserRegistryManagementInvoker = - userregistry.client.invoker.ApiInvoker(userregistry.client.api.EnumsSerializers.all) - } - } diff --git a/src/test/resources/application-test.conf b/src/test/resources/application-test.conf index 4c5a22c7..71fd4299 100644 --- a/src/test/resources/application-test.conf +++ b/src/test/resources/application-test.conf @@ -9,8 +9,7 @@ agreement-process { jwt { audience = "aud" } - user-registry-api-key = "user-registry-api-key" - party-process-api-key = "party-process-api-key" + selfcare-v2-client-api-key = "selfcare-v2-api-key" services { catalog-management = "catalog-management" tenant-management = "tenant-management" @@ -18,8 +17,7 @@ agreement-process { attribute-registry-management = "attribute-registry-management" authorization-management = "authorization-management" tenant-management = "tenant-management" - user-registry = "user-registry" - party-process = "party-process" + selfcare-v2-client = "selfcare-v2-client" } queue { diff --git a/src/test/scala/it/pagopa/interop/agreementprocess/AgreementApiAuthzSpec.scala b/src/test/scala/it/pagopa/interop/agreementprocess/AgreementApiAuthzSpec.scala index b874b9cf..bb6890d2 100644 --- a/src/test/scala/it/pagopa/interop/agreementprocess/AgreementApiAuthzSpec.scala +++ b/src/test/scala/it/pagopa/interop/agreementprocess/AgreementApiAuthzSpec.scala @@ -28,8 +28,7 @@ class AgreementApiAuthzSpec extends AnyWordSpecLike with MockFactory with AuthzS val fakeTenantManagementService: TenantManagementService = new FakeTenantManagementService() val fakeAttributeManagementService: AttributeManagementService = new FakeAttributeManagementService() val fakeAuthorizationManagementService: AuthorizationManagementService = new FakeAuthorizationManagementService() - val fakePartyProcessService: PartyProcessService = new FakePartyProcessService() - val fakeUserRegistryService: UserRegistryService = new FakeUserRegistryService() + val fakeSelfcareV2ClientService: SelfcareV2ClientService = new FakeSelfcareV2ClientService() val fakePDFCreator: PDFCreator = new FakePDFCreator() val fakeFileManager: FileManager = new FakeFileManager() val fakerQueueService: QueueService = new FakeQueueService() @@ -47,8 +46,7 @@ class AgreementApiAuthzSpec extends AnyWordSpecLike with MockFactory with AuthzS tenantManagementService = fakeTenantManagementService, attributeManagementService = fakeAttributeManagementService, authorizationManagementService = fakeAuthorizationManagementService, - partyProcessService = fakePartyProcessService, - userRegistry = fakeUserRegistryService, + selfcareV2ClientService = fakeSelfcareV2ClientService, pdfCreator = fakePDFCreator, fileManager = fakeFileManager, offsetDateTimeSupplier = OffsetDateTimeSupplier, diff --git a/src/test/scala/it/pagopa/interop/agreementprocess/SpecData.scala b/src/test/scala/it/pagopa/interop/agreementprocess/SpecData.scala index 55e3e993..6b165a31 100644 --- a/src/test/scala/it/pagopa/interop/agreementprocess/SpecData.scala +++ b/src/test/scala/it/pagopa/interop/agreementprocess/SpecData.scala @@ -11,9 +11,6 @@ import it.pagopa.interop.agreementprocess.model.{ TenantVerifier, VerifiedTenantAttribute } -import it.pagopa.interop.selfcare.userregistry.client.model.CertifiableFieldResourceOfstringEnums.Certification -import it.pagopa.interop.selfcare.userregistry.client.model.{CertifiableFieldResourceOfstring, UserResource} - import java.time.{OffsetDateTime, ZoneOffset} import java.util.UUID import it.pagopa.interop.catalogmanagement.model.{ @@ -41,6 +38,7 @@ import it.pagopa.interop.tenantmanagement.model.tenant.{ } import it.pagopa.interop.tenantmanagement.model.tenant.PersistentTenantMailKind.ContactEmail import it.pagopa.interop.attributeregistrymanagement.model.persistence.attribute.{Certified, PersistentAttribute} +import it.pagopa.interop.selfcare.v2.client.model.UserResponse object SpecData { @@ -331,10 +329,11 @@ object SpecData { createdAt = timestamp ) - def userResource(name: String, familyName: String, fiscalCode: String): UserResource = UserResource( - familyName = Some(CertifiableFieldResourceOfstring(Certification.SPID, familyName)), - fiscalCode = Some(fiscalCode), - id = SpecData.who, - name = Some(CertifiableFieldResourceOfstring(Certification.SPID, name)) + def userResource(name: String, familyName: String, fiscalCode: String, email: String): UserResponse = UserResponse( + surname = Some(familyName), + taxCode = Some(fiscalCode), + id = Some(SpecData.who.toString), + name = Some(name), + email = Some(email) ) } diff --git a/src/test/scala/it/pagopa/interop/agreementprocess/SpecHelper.scala b/src/test/scala/it/pagopa/interop/agreementprocess/SpecHelper.scala index bacd02f5..147b86d3 100644 --- a/src/test/scala/it/pagopa/interop/agreementprocess/SpecHelper.scala +++ b/src/test/scala/it/pagopa/interop/agreementprocess/SpecHelper.scala @@ -10,20 +10,20 @@ import it.pagopa.interop.authorizationmanagement.client.model.{ ClientAgreementAndEServiceDetailsUpdate, ClientComponentState } +import it.pagopa.interop.selfcare.v2.client.model.{UserResponse, Institution} import it.pagopa.interop.catalogmanagement.model.CatalogItem import it.pagopa.interop.agreementmanagement.model.agreement.{PersistentAgreement, PersistentAgreementState} import it.pagopa.interop.tenantmanagement.model.tenant.PersistentTenant import it.pagopa.interop.commons.mail.TextMail import it.pagopa.interop.commons.files.service.FileManager import it.pagopa.interop.commons.utils.service.{OffsetDateTimeSupplier, UUIDSupplier} -import it.pagopa.interop.commons.utils.{ORGANIZATION_ID_CLAIM, UID, USER_ROLES} -import it.pagopa.interop.selfcare.partyprocess.client.model.Institution -import it.pagopa.interop.selfcare.userregistry.client.model.UserResource +import it.pagopa.interop.commons.utils.{ORGANIZATION_ID_CLAIM, UID, USER_ROLES, SELFCARE_ID_CLAIM} import it.pagopa.interop.agreementprocess.common.Adapters._ import it.pagopa.interop.agreementprocess.events.ArchiveEvent import it.pagopa.interop.commons.cqrs.service.ReadModelService import org.scalamock.scalatest.MockFactory import spray.json.JsonWriter +import cats.syntax.all._ import java.util.UUID import scala.concurrent.{ExecutionContext, Future} @@ -35,13 +35,15 @@ trait SpecHelper extends MockFactory { val bearerToken: String = "bearerToken" val requesterOrgId: UUID = UUID.randomUUID() + val selfcareId: UUID = UUID.randomUUID() implicit val contexts: Seq[(String, String)] = Seq( "bearer" -> "bearerToken", ORGANIZATION_ID_CLAIM -> requesterOrgId.toString, USER_ROLES -> "admin", - UID -> SpecData.who.toString + UID -> SpecData.who.toString, + SELFCARE_ID_CLAIM -> selfcareId.toString ) val agreementApiMarshaller: AgreementApiMarshaller = AgreementApiMarshallerImpl @@ -51,8 +53,7 @@ trait SpecHelper extends MockFactory { val mockTenantManagementService: TenantManagementService = mock[TenantManagementService] val mockAttributeManagementService: AttributeManagementService = mock[AttributeManagementService] val mockAuthorizationManagementService: AuthorizationManagementService = mock[AuthorizationManagementService] - val mockUserRegistryService: UserRegistryService = mock[UserRegistryService] - val mockPartyProcessService: PartyProcessService = mock[PartyProcessService] + val mockSelfcareV2ClientService: SelfcareV2ClientService = mock[SelfcareV2ClientService] val mockPDFCreator: PDFCreator = mock[PDFCreator] val mockFileManager: FileManager = mock[FileManager] val mockOffsetDateTimeSupplier: OffsetDateTimeSupplier = () => SpecData.when @@ -66,8 +67,7 @@ trait SpecHelper extends MockFactory { mockTenantManagementService, mockAttributeManagementService, mockAuthorizationManagementService, - mockPartyProcessService, - mockUserRegistryService, + mockSelfcareV2ClientService, mockPDFCreator, mockFileManager, mockOffsetDateTimeSupplier, @@ -192,10 +192,10 @@ trait SpecHelper extends MockFactory { .once() .returns(Future.unit) - def mockUserRegistryRetrieve(user: UserResource) = - (mockUserRegistryService - .getUserById(_: UUID)(_: Seq[(String, String)])) - .expects(*, *) + def mockUserRegistryRetrieve(user: UserResponse) = + (mockSelfcareV2ClientService + .getUserById(_: UUID, _: UUID)(_: Seq[(String, String)], _: ExecutionContext)) + .expects(*, *, *, *) .once() .returns(Future.successful(user)) @@ -227,23 +227,23 @@ trait SpecHelper extends MockFactory { .returns(Future.successful("sent")) def mockGetInstitution(selfcareId: String) = - (mockPartyProcessService - .getInstitution(_: String)(_: Seq[(String, String)], _: ExecutionContext)) - .expects(*, *, *) + (mockSelfcareV2ClientService + .getInstitution(_: UUID)(_: Seq[(String, String)], _: ExecutionContext)) + .expects(UUID.fromString(selfcareId), *, *) .returns( Future.successful( Institution( - id = UUID.fromString(selfcareId), - externalId = "externalId", - originId = "originId", - description = "description", - digitalAddress = "digitalAddress", - address = "address", - zipCode = "zipCode", - taxCode = "taxCode", - origin = "origin", + id = UUID.fromString(selfcareId).some, + externalId = "externalId".some, + originId = "originId".some, + description = "description".some, + digitalAddress = "digitalAddress".some, + address = "address".some, + zipCode = "zipCode".some, + taxCode = "taxCode".some, + origin = "origin".some, institutionType = None, - attributes = Seq.empty + attributes = Seq.empty.some ) ) ) @@ -296,8 +296,8 @@ trait SpecHelper extends MockFactory { mockAgreementContract mockTenantRetrieve(consumer.id, consumer) mockTenantRetrieve(producer.id, producer) - mockUserRegistryRetrieve(SpecData.userResource("a", "b", "c")) - mockUserRegistryRetrieve(SpecData.userResource("d", "e", "f")) + mockUserRegistryRetrieve(SpecData.userResource("a", "b", "c", "e")) + mockUserRegistryRetrieve(SpecData.userResource("d", "e", "f", "g")) mockAgreementUpdate( agreement.id, expectedSeed, @@ -337,8 +337,8 @@ trait SpecHelper extends MockFactory { mockFileManagerWrite mockAgreementContract mockTenantRetrieve(producer.id, producer) - mockUserRegistryRetrieve(SpecData.userResource("a", "b", "c")) - mockUserRegistryRetrieve(SpecData.userResource("d", "e", "f")) + mockUserRegistryRetrieve(SpecData.userResource("a", "b", "c", "e")) + mockUserRegistryRetrieve(SpecData.userResource("d", "e", "f", "g")) mockClientStateUpdate(agreement.eserviceId, agreement.consumerId, agreement.id, ClientComponentState.ACTIVE) mockGetInstitution(consumer.selfcareId.get) mockGetInstitution(producer.selfcareId.get) @@ -370,8 +370,8 @@ trait SpecHelper extends MockFactory { mockPDFCreatorCreate mockFileManagerWrite mockAgreementContract - mockUserRegistryRetrieve(SpecData.userResource("a", "b", "c")) - mockUserRegistryRetrieve(SpecData.userResource("d", "e", "f")) + mockUserRegistryRetrieve(SpecData.userResource("a", "b", "c", "e")) + mockUserRegistryRetrieve(SpecData.userResource("d", "e", "f", "g")) mockClientStateUpdate(agreement.eserviceId, agreement.consumerId, agreement.id, ClientComponentState.ACTIVE) mockGetInstitution(consumer.selfcareId.get) mockGetInstitution(producer.selfcareId.get) diff --git a/src/test/scala/it/pagopa/interop/agreementprocess/util/FakeDependencies.scala b/src/test/scala/it/pagopa/interop/agreementprocess/util/FakeDependencies.scala index 48745e02..b4bdfae4 100644 --- a/src/test/scala/it/pagopa/interop/agreementprocess/util/FakeDependencies.scala +++ b/src/test/scala/it/pagopa/interop/agreementprocess/util/FakeDependencies.scala @@ -7,8 +7,6 @@ import it.pagopa.interop.agreementprocess.service._ import it.pagopa.interop.agreementprocess.service.util.PDFPayload import it.pagopa.interop.authorizationmanagement.client.model._ import it.pagopa.interop.commons.files.service.FileManager -import it.pagopa.interop.selfcare.partyprocess.client.model.Institution -import it.pagopa.interop.selfcare.userregistry.client.model.UserResource import spray.json.JsonWriter import it.pagopa.interop.commons.cqrs.service.ReadModelService import it.pagopa.interop.agreementprocess.common.Adapters._ @@ -21,6 +19,7 @@ import it.pagopa.interop.attributeregistrymanagement.model.persistence.attribute import it.pagopa.interop.catalogmanagement.model.{CatalogItem, Rest, CatalogAttributes} import it.pagopa.interop.tenantmanagement.model.tenant.{PersistentTenant, PersistentExternalId, PersistentTenantKind} import it.pagopa.interop.catalogmanagement.model.{CatalogDescriptor, Published, Automatic, Deliver} +import it.pagopa.interop.selfcare.v2.client.model.{UserResponse, Institution} import java.io.{ByteArrayOutputStream, File} import java.time.OffsetDateTime @@ -194,43 +193,18 @@ object FakeDependencies { ) ) } - - class FakePartyProcessService extends PartyProcessService { + class FakeSelfcareV2ClientService extends SelfcareV2ClientService { override def getInstitution( - selfcareId: String - )(implicit contexts: Seq[(String, String)], ec: ExecutionContext): Future[Institution] = Future.successful( - Institution( - id = UUID.randomUUID(), - externalId = "", - originId = "", - description = "", - digitalAddress = "", - address = "", - zipCode = "", - taxCode = "", - origin = "", - institutionType = None, - attributes = Seq.empty - ) - ) - } - - class FakeUserRegistryService extends UserRegistryService { - override def getUserById(id: UUID)(implicit contexts: Seq[(String, String)]): Future[UserResource] = - Future.successful( - UserResource( - birthDate = None, - email = None, - familyName = None, - fiscalCode = None, - id = UUID.randomUUID(), - name = None, - workContacts = None - ) - ) + selfcareId: UUID + )(implicit contexts: Seq[(String, String)], ec: ExecutionContext): Future[Institution] = + Future.successful(Institution()) + + override def getUserById(selfcareId: UUID, userId: UUID)(implicit + contexts: Seq[(String, String)], + ec: ExecutionContext + ): Future[UserResponse] = Future.successful(UserResponse()) } - - class FakePDFCreator extends PDFCreator { + class FakePDFCreator extends PDFCreator { override def create(template: String, pdfPayload: PDFPayload): Future[Array[Byte]] = Future.successful(Array.empty) }