Skip to content

Commit

Permalink
PIN-3518 Alignment to Selfcare API v.2 (#252)
Browse files Browse the repository at this point in the history
Co-authored-by: nttdata-rtorsoli <[email protected]>
  • Loading branch information
nttdata-rtorsoli and nttdata-rtorsoli authored Nov 9, 2023
1 parent f421279 commit 19470a2
Show file tree
Hide file tree
Showing 24 changed files with 225 additions and 267 deletions.
10 changes: 4 additions & 6 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions project/Versions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
5 changes: 2 additions & 3 deletions src/main/resources/application-standalone.conf
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,15 @@ 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"
attribute-registry-management = "https://gateway.interop.pdnd.dev/attribute-registry-management/0.1"
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 {
Expand Down
6 changes: 2 additions & 4 deletions src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -85,7 +84,7 @@ final case class AgreementApiServiceImpl(
uuidSupplier,
agreementManagementService,
attributeManagementService,
userRegistry,
selfcareV2ClientService,
offsetDateTimeSupplier
)

Expand Down Expand Up @@ -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
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}

Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -125,8 +119,7 @@ trait Dependencies {
TenantManagementServiceImpl,
AttributeManagementServiceImpl,
authorizationManagement(blockingEc),
partyProcess,
userRegistry,
selfcareV2Client,
PDFCreator,
fileManager(blockingEc),
OffsetDateTimeSupplier,
Expand Down
Original file line number Diff line number Diff line change
@@ -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}
Expand All @@ -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.{
Expand All @@ -18,20 +18,22 @@ 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,
fileManager: FileManager,
uuidSupplier: UUIDSupplier,
agreementManagementService: AgreementManagementService,
attributeManagementService: AttributeManagementService,
userRegistry: UserRegistryService,
selfcareV2ClientService: SelfcareV2ClientService,
offsetDateTimeSupplier: OffsetDateTimeSupplier
)(implicit readModel: ReadModelService) {

Expand Down Expand Up @@ -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,
Expand Down

This file was deleted.

Loading

0 comments on commit 19470a2

Please sign in to comment.