Skip to content

Commit

Permalink
PIN-4257 Added SubUnitType (#83)
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 28, 2023
1 parent 9706a83 commit 7157a51
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 22 deletions.
14 changes: 12 additions & 2 deletions src/main/resources/interface-specification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,9 @@ components:
$ref: '#/components/schemas/TenantKind'
onboardedAt:
type: string
format: date-time
format: date-time
subUnitType:
$ref: '#/components/schemas/TenantUnitType'
required:
- id
- certifier
Expand Down Expand Up @@ -1084,12 +1086,20 @@ components:
$ref: '#/components/schemas/MailSeed'
onboardedAt:
type: string
format: date-time
format: date-time
subUnitType:
$ref: '#/components/schemas/TenantUnitType'
required:
- externalId
- selfcareId
- name
- onboardedAt
- subUnitType
TenantUnitType:
type: string
enum:
- AOO
- UO
MailSeed:
description: A specific kind of mail
type: object
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package it.pagopa.interop.tenantprocess.api.adapters

import it.pagopa.interop.tenantmanagement.client.model.{TenantAttribute, TenantSeed, TenantKind}
import it.pagopa.interop.tenantprocess.api.adapters.ApiAdapters.ExternalIdWrapper
import it.pagopa.interop.tenantprocess.api.adapters.ApiAdapters._
import it.pagopa.interop.tenantprocess.model.{InternalTenantSeed, M2MTenantSeed, SelfcareTenantSeed}

import java.util.UUID
Expand Down Expand Up @@ -59,7 +59,8 @@ object AdaptableSeed {
attributes = attributes,
name = a.name,
kind = kind,
onboardedAt = Some(a.onboardedAt)
onboardedAt = Some(a.onboardedAt),
subUnitType = Some(a.subUnitType.toDependency)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import it.pagopa.interop.tenantmanagement.client.model.{
TenantFeature => DependencyTenantFeature,
TenantKind => DependencyTenantKind,
TenantVerifier => DependencyTenantVerifier,
VerifiedTenantAttribute => DependencyVerifiedTenantAttribute
VerifiedTenantAttribute => DependencyVerifiedTenantAttribute,
TenantUnitType => DependencyTenantUnitType
}
import it.pagopa.interop.tenantprocess.model._
import it.pagopa.interop.commons.utils.Digester.toSha256
Expand Down Expand Up @@ -70,6 +71,13 @@ object ApiAdapters {
)
}

implicit class TenantUnitTypeWrapper(private val u: TenantUnitType) extends AnyVal {
def toDependency: DependencyTenantUnitType = u match {
case TenantUnitType.AOO => DependencyTenantUnitType.AOO
case TenantUnitType.UO => DependencyTenantUnitType.UO
}
}

implicit class VerifiedTenantAttributeSeedWrapper(private val seed: VerifiedTenantAttributeSeed) extends AnyVal {
def toCreateDependency(now: OffsetDateTime, requesterId: UUID): DependencyTenantAttribute =
DependencyTenantAttribute(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ object ReadModelTenantAdapters extends SprayJsonSupport with DefaultJsonProtocol
createdAt = t.createdAt,
updatedAt = t.updatedAt,
onboardedAt = t.onboardedAt,
mails = t.mails.map(_.toApi)
mails = t.mails.map(_.toApi),
subUnitType = t.subUnitType.map(_.toApi)
)
def toManagement: Management.Tenant = Management.Tenant(
id = t.id,
Expand All @@ -34,7 +35,8 @@ object ReadModelTenantAdapters extends SprayJsonSupport with DefaultJsonProtocol
createdAt = t.createdAt,
updatedAt = t.updatedAt,
onboardedAt = t.onboardedAt,
mails = t.mails.map(_.toManagement)
mails = t.mails.map(_.toManagement),
subUnitType = t.subUnitType.map(_.toManagement)
)
}

Expand All @@ -61,6 +63,17 @@ object ReadModelTenantAdapters extends SprayJsonSupport with DefaultJsonProtocol
}
}

implicit class PersistentTenantUnitTypeWrapper(private val u: PersistentTenantUnitType) extends AnyVal {
def toApi: TenantUnitType = u match {
case PersistentTenantUnitType.Aoo => TenantUnitType.AOO
case PersistentTenantUnitType.Uo => TenantUnitType.UO
}
def toManagement: Management.TenantUnitType = u match {
case PersistentTenantUnitType.Aoo => Management.TenantUnitType.AOO
case PersistentTenantUnitType.Uo => Management.TenantUnitType.UO
}
}

implicit class PersistentExternalIdWrapper(private val t: PersistentExternalId) extends AnyVal {
def toApi: ExternalId = ExternalId(origin = t.origin, value = t.value)
def toManagement: Management.ExternalId = Management.ExternalId(origin = t.origin, value = t.value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import it.pagopa.interop.tenantmanagement.client.model.{
TenantKind => DependencyTenantKind,
TenantRevoker => DependencyTenantRevoker,
TenantVerifier => DependencyTenantVerifier,
VerifiedTenantAttribute => DependencyVerifiedTenantAttribute
VerifiedTenantAttribute => DependencyVerifiedTenantAttribute,
TenantUnitType => DependencyTenantUnitType
}
import it.pagopa.interop.agreementprocess.client.{model => AgreementDependency}
import it.pagopa.interop.tenantprocess.model._
Expand All @@ -35,7 +36,8 @@ object TenantManagementAdapters extends SprayJsonSupport with DefaultJsonProtoco
mails = t.mails.map(_.toApi),
name = t.name,
kind = t.kind.map(_.toApi),
onboardedAt = t.onboardedAt
onboardedAt = t.onboardedAt,
subUnitType = t.subUnitType.map(_.toApi)
)
}

Expand All @@ -59,6 +61,13 @@ object TenantManagementAdapters extends SprayJsonSupport with DefaultJsonProtoco
}
}

implicit class DependencyTenantUnitTypeWrapper(private val u: DependencyTenantUnitType) extends AnyVal {
def toApi: TenantUnitType = u match {
case DependencyTenantUnitType.AOO => TenantUnitType.AOO
case DependencyTenantUnitType.UO => TenantUnitType.UO
}
}

implicit class DependencyExternalIdWrapper(private val t: DependencyExternalId) extends AnyVal {
def toApi: ExternalId = ExternalId(origin = t.origin, value = t.value)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ package object impl extends SprayJsonSupport with DefaultJsonProtocol {

implicit def m2mAttributeSeedFormat: RootJsonFormat[M2MAttributeSeed] = jsonFormat1(M2MAttributeSeed)
implicit def m2mTenantSeedFormat: RootJsonFormat[M2MTenantSeed] = jsonFormat3(M2MTenantSeed)

implicit def selfcareTenantSeedFormat: RootJsonFormat[SelfcareTenantSeed] = jsonFormat5(SelfcareTenantSeed)
implicit def selfcareTenantSeedFormat: RootJsonFormat[SelfcareTenantSeed] = jsonFormat6(SelfcareTenantSeed)

implicit def certifierFormat: RootJsonFormat[Certifier] = jsonFormat1(Certifier)
implicit def tenantFeatureFormat: RootJsonFormat[TenantFeature] = jsonFormat1(TenantFeature)
Expand All @@ -43,7 +42,7 @@ package object impl extends SprayJsonSupport with DefaultJsonProtocol {
implicit def tenantRevokerFormat: RootJsonFormat[TenantRevoker] = jsonFormat5(TenantRevoker)

implicit def resourceIdFormat: RootJsonFormat[ResourceId] = jsonFormat1(ResourceId)
implicit def tenantFormat: RootJsonFormat[Tenant] = jsonFormat11(Tenant)
implicit def tenantFormat: RootJsonFormat[Tenant] = jsonFormat12(Tenant)
implicit def tenantsFormat: RootJsonFormat[Tenants] = jsonFormat2(Tenants)
implicit def problemErrorFormat: RootJsonFormat[ProblemError] = jsonFormat2(ProblemError)
implicit def problemFormat: RootJsonFormat[Problem] = jsonFormat6(Problem)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,8 @@ class TenantCreationSpec extends AnyWordSpecLike with SpecHelper with ScalatestR
attributes = Nil,
name = "test_name",
kind = TenantKind.PA,
onboardedAt = Some(timestamp)
onboardedAt = Some(timestamp),
subUnitType = Some(TenantUnitType.AOO)
)
val expectedTenantUpdate =
TenantDelta(selfcareId = Some(seed.selfcareId), features = Nil, kind = TenantKind.PA)
Expand Down Expand Up @@ -931,7 +932,8 @@ class TenantCreationSpec extends AnyWordSpecLike with SpecHelper with ScalatestR
attributes = Nil,
name = "test_name",
kind = TenantKind.PRIVATE,
onboardedAt = Some(timestamp)
onboardedAt = Some(timestamp),
subUnitType = Some(TenantUnitType.AOO)
)
val expectedTenantUpdate =
TenantDelta(selfcareId = Some(seed.selfcareId), features = Nil, kind = TenantKind.PRIVATE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import it.pagopa.interop.tenantmanagement.model.tenant.{
PersistentTenant,
PersistentTenantAttribute,
PersistentTenantFeature,
PersistentTenantKind
PersistentTenantKind,
PersistentTenantUnitType
}
import it.pagopa.interop.attributeregistrymanagement.model.persistence.attribute.{Certified, PersistentAttribute}
import it.pagopa.interop.catalogmanagement.model.CatalogItem
Expand Down Expand Up @@ -197,7 +198,8 @@ object FakeDependencies extends SpecData {
mails = Nil,
name = "test_name",
kind = Some(PersistentTenantKind.PA),
onboardedAt = None
onboardedAt = None,
subUnitType = Some(PersistentTenantUnitType.Aoo)
)

val fakeAttribute: PersistentCertifiedAttribute =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import it.pagopa.interop.tenantmanagement.model.tenant.{
PersistentTenantAttribute,
PersistentTenantRevoker,
PersistentTenantVerifier,
PersistentVerifiedAttribute
PersistentVerifiedAttribute,
PersistentTenantUnitType
}
import it.pagopa.interop.tenantprocess.model._
import it.pagopa.interop.agreementmanagement.model.agreement.{
Expand Down Expand Up @@ -62,15 +63,17 @@ trait SpecData {
UUID.randomUUID().toString,
"test_name",
None,
timestamp
timestamp,
TenantUnitType.AOO
)
val selfcareTenantSeedNotIpa: SelfcareTenantSeed =
SelfcareTenantSeed(
ExternalId("NOT_IPA", s"tenant-${UUID.randomUUID()}"),
UUID.randomUUID().toString,
"test_name",
None,
timestamp
timestamp,
TenantUnitType.AOO
)

val dependencyTenant: Dependency.Tenant = Dependency.Tenant(
Expand All @@ -84,7 +87,8 @@ trait SpecData {
mails = Nil,
name = "test_name",
kind = None,
onboardedAt = Some(timestamp)
onboardedAt = Some(timestamp),
subUnitType = Some(Dependency.TenantUnitType.AOO)
)

val persistentAttribute: PersistentAttribute = PersistentAttribute(
Expand Down Expand Up @@ -125,7 +129,8 @@ trait SpecData {
mails = Nil,
name = "test_name",
kind = None,
onboardedAt = Some(timestamp)
onboardedAt = Some(timestamp),
subUnitType = Some(PersistentTenantUnitType.Aoo)
)

val persistentTenantNotIPA: PersistentTenant = PersistentTenant(
Expand All @@ -139,7 +144,8 @@ trait SpecData {
mails = Nil,
name = "test_name",
kind = None,
onboardedAt = Some(timestamp)
onboardedAt = Some(timestamp),
subUnitType = Some(PersistentTenantUnitType.Aoo)
)

val fakeMailSeed = MailSeed(MailKind.CONTACT_EMAIL, address = "fakeAddress", description = None)
Expand Down

0 comments on commit 7157a51

Please sign in to comment.