Skip to content

Commit

Permalink
PIN-4084 Resolved PR issue
Browse files Browse the repository at this point in the history
  • Loading branch information
nttdata-rtorsoli committed Nov 24, 2023
1 parent f5fbd37 commit 794e1c7
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 17 deletions.
2 changes: 1 addition & 1 deletion project/Versions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ object PagopaVersions {
lazy val agreementProcessVersion = "1.0.x-SNAPSHOT"
lazy val agreementManagementVersion = "1.0.x-SNAPSHOT"
lazy val catalogManagementVersion = "1.0.x-SNAPSHOT"
lazy val tenantManagementVersion = "1.0.x-SNAPSHOT"
lazy val tenantManagementVersion = "PIN-4083-SNAPSHOT"//"1.0.x-SNAPSHOT"
lazy val commonsVersion = "1.0.x-SNAPSHOT"
}
11 changes: 10 additions & 1 deletion src/main/resources/interface-specification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/Tenant'
$ref: '#/components/schemas/CompactTenant'
'409':
description: Selfcare Id is already assigned and is different from the request
content:
Expand Down Expand Up @@ -817,6 +817,15 @@ components:
maxLength: 64
required:
- code
CompactTenant:
description: Tenant Compact model
type: object
properties:
id:
type: string
format: uuid
required:
- id
Tenant:
description: Tenant model
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ object TenantApiMarshallerImpl extends TenantApiMarshaller with SprayJsonSupport
override implicit def fromEntityUnmarshallerMailSeed: FromEntityUnmarshaller[MailSeed] =
sprayJsonUnmarshaller[MailSeed]

override implicit def toEntityMarshallerCompactTenant: ToEntityMarshaller[CompactTenant] =
sprayJsonMarshaller[CompactTenant]
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import it.pagopa.interop.tenantprocess.api.adapters.TenantManagementAdapters._
import it.pagopa.interop.tenantprocess.error.ResponseHandlers._
import it.pagopa.interop.tenantprocess.error.TenantProcessErrors._
import it.pagopa.interop.tenantprocess.model._
import it.pagopa.interop.tenantprocess.model.{CompactTenant => TenantUUID}
import it.pagopa.interop.tenantprocess.service._
import it.pagopa.interop.tenantmanagement.model.tenant.PersistentExternalId

Expand Down Expand Up @@ -207,8 +208,8 @@ final case class TenantApiServiceImpl(

override def selfcareUpsertTenant(seed: SelfcareTenantSeed)(implicit
contexts: Seq[(String, String)],
toEntityMarshallerProblem: ToEntityMarshaller[Problem],
toEntityMarshallerTenant: ToEntityMarshaller[Tenant]
toEntityMarshallerTenant: ToEntityMarshaller[TenantUUID],
toEntityMarshallerProblem: ToEntityMarshaller[Problem]
): Route = authorize(ADMIN_ROLE, API_ROLE, SECURITY_ROLE, INTERNAL_ROLE) {
val operationLabel = s"Creating tenant with external id ${seed.externalId} via SelfCare request"
logger.info(operationLabel)
Expand All @@ -229,19 +230,18 @@ final case class TenantApiServiceImpl(
tenant.selfcareId.fold(updateTenant())(verifyConflict)
}

val result: Future[Tenant] = for {
val result: Future[TenantUUID] = for {
existingTenant <- findTenant(seed.externalId)
_ <- existingTenant.traverse(t => assertResourceAllowed(t.id))
tenant <- existingTenant
.fold(createTenant(seed, Nil, now, getTenantKind(Nil, seed.externalId).fromAPI))(Future.successful)
tenantKind <- getTenantKindLoadingCertifiedAttributes(tenant.attributes, tenant.externalId)
_ <- updateSelfcareId(tenant, tenantKind)
_ <- tenantManagementService.addTenantMail(tenant.id, seed.digitalAddress.toDependency)
tenant <- tenantManagementService.getTenantById(tenant.id)
} yield tenant.toApi
} yield TenantUUID(tenant.id)

onComplete(result) {
selfcareUpsertTenantResponse[Tenant](operationLabel)(selfcareUpsertTenant200)
selfcareUpsertTenantResponse[TenantUUID](operationLabel)(selfcareUpsertTenant200)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ package object impl extends SprayJsonSupport with DefaultJsonProtocol {
implicit def tenantVerifierFormat: RootJsonFormat[TenantVerifier] = jsonFormat4(TenantVerifier)
implicit def tenantRevokerFormat: RootJsonFormat[TenantRevoker] = jsonFormat5(TenantRevoker)

implicit def tenantFormat: RootJsonFormat[Tenant] = jsonFormat11(Tenant)
implicit def tenantsFormat: RootJsonFormat[Tenants] = jsonFormat2(Tenants)
implicit def problemErrorFormat: RootJsonFormat[ProblemError] = jsonFormat2(ProblemError)
implicit def problemFormat: RootJsonFormat[Problem] = jsonFormat6(Problem)
implicit def compactTenantFormat: RootJsonFormat[CompactTenant] = jsonFormat1(CompactTenant)
implicit def tenantFormat: RootJsonFormat[Tenant] = jsonFormat11(Tenant)
implicit def tenantsFormat: RootJsonFormat[Tenants] = jsonFormat2(Tenants)
implicit def problemErrorFormat: RootJsonFormat[ProblemError] = jsonFormat2(ProblemError)
implicit def problemFormat: RootJsonFormat[Problem] = jsonFormat6(Problem)

final val entityMarshallerProblem: ToEntityMarshaller[Problem] = sprayJsonMarshaller[Problem]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,6 @@ class TenantCreationSpec extends AnyWordSpecLike with SpecHelper with ScalatestR
mockCreateTenant(expectedTenantSeed, tenant)
mockUpdateTenant(tenantId, expectedTenantUpdate)
mockAddTenantMail(tenantId, dependencyMailSeed)
mockGetTenantById(tenantId, persistentTenant)

Get() ~> tenantService.selfcareUpsertTenant(seed) ~> check {
assert(status == StatusCodes.OK)
Expand Down Expand Up @@ -946,7 +945,6 @@ class TenantCreationSpec extends AnyWordSpecLike with SpecHelper with ScalatestR
mockCreateTenant(expectedTenantSeed, tenant)
mockUpdateTenant(tenantId, expectedTenantUpdate)
mockAddTenantMail(tenantId, dependencyMailSeed)
mockGetTenantById(tenantId, persistentTenant)

Get() ~> tenantService.selfcareUpsertTenant(seed) ~> check {
assert(status == StatusCodes.OK)
Expand Down Expand Up @@ -976,7 +974,6 @@ class TenantCreationSpec extends AnyWordSpecLike with SpecHelper with ScalatestR
mockGetTenantByExternalId(PersistentExternalId(seed.externalId.origin, seed.externalId.value), tenant)
mockUpdateTenant(tenantId, expectedTenantUpdate)
mockAddTenantMail(tenantId, dependencyMailSeed)
mockGetTenantById(tenantId, persistentTenant)

Get() ~> tenantService.selfcareUpsertTenant(seed) ~> check {
assert(status == StatusCodes.OK)
Expand All @@ -1000,7 +997,6 @@ class TenantCreationSpec extends AnyWordSpecLike with SpecHelper with ScalatestR
mockGetTenantByExternalId(PersistentExternalId(seed.externalId.origin, seed.externalId.value), tenant)

mockAddTenantMail(tenantId, dependencyMailSeed)
mockGetTenantById(tenantId, tenant)

Get() ~> tenantService.selfcareUpsertTenant(seed) ~> check {
assert(status == StatusCodes.OK)
Expand Down Expand Up @@ -1074,7 +1070,6 @@ class TenantCreationSpec extends AnyWordSpecLike with SpecHelper with ScalatestR
mockGetTenantByExternalId(PersistentExternalId(seed.externalId.origin, seed.externalId.value), tenant)
mockUpdateTenant(tenantId, expectedTenantUpdate)
mockAddTenantMail(tenantId, dependencyMailSeed)
mockGetTenantById(tenantId, tenant)

Get() ~> tenantService.selfcareUpsertTenant(seed) ~> check {
assert(status == StatusCodes.OK)
Expand Down

0 comments on commit 794e1c7

Please sign in to comment.