Skip to content

Commit

Permalink
PIN-3888 Updated Agreement Process
Browse files Browse the repository at this point in the history
  • Loading branch information
nttdata-rtorsoli committed Sep 7, 2023
1 parent 2dce524 commit 4098157
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 47 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
package it.pagopa.interop.agreementprocess.lifecycle

import it.pagopa.interop.agreementmanagement.model.agreement._
import it.pagopa.interop.catalogmanagement.model.{
CatalogDescriptor,
CatalogAttribute,
SingleAttribute,
GroupAttribute,
CatalogAttributes
}
import it.pagopa.interop.catalogmanagement.model.{CatalogDescriptor, CatalogAttribute, CatalogAttributes}
import it.pagopa.interop.commons.utils.service.OffsetDateTimeSupplier
import it.pagopa.interop.tenantmanagement.model.tenant.{
PersistentCertifiedAttribute,
Expand Down Expand Up @@ -78,11 +72,14 @@ object AttributesRules {
consumerAttributes.collect { case a: PersistentVerifiedAttribute => a }
)

private def attributesSatisfied(requested: Seq[CatalogAttribute], assigned: Seq[UUID]): Boolean = {
requested.forall {
case SingleAttribute(value) => assigned.contains(value.id)
case GroupAttribute(values) => values.map(_.id).intersect(assigned).nonEmpty
case _ => true
private def attributesSatisfied(requested: Seq[Seq[CatalogAttribute]], assigned: Seq[UUID]): Boolean = {
requested.forall { list =>
{
list match {
case head :: Nil => assigned.contains(head.id)
case values => values.map(_.id).intersect(assigned).nonEmpty
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import it.pagopa.interop.catalogmanagement.model.{
CatalogDescriptor,
Rest,
CatalogAttributes,
SingleAttribute,
CatalogAttributeValue,
GroupAttribute
CatalogAttribute
}
import it.pagopa.interop.tenantmanagement.model.tenant.{
PersistentCertifiedAttribute,
Expand Down Expand Up @@ -75,15 +73,13 @@ object SpecData {
kind = Some(PersistentTenantKind.PA)
)

def catalogSingleAttribute(id: UUID = UUID.randomUUID()): SingleAttribute =
SingleAttribute(id = CatalogAttributeValue(id, explicitAttributeVerification = false))
def catalogSingleAttribute(id: UUID = UUID.randomUUID()): Seq[CatalogAttribute] =
Seq(CatalogAttribute(id = id, explicitAttributeVerification = false))

def catalogGroupAttributes(id1: UUID = UUID.randomUUID(), id2: UUID = UUID.randomUUID()): GroupAttribute =
GroupAttribute(ids =
Seq(
CatalogAttributeValue(id1, explicitAttributeVerification = false),
CatalogAttributeValue(id2, explicitAttributeVerification = false)
)
def catalogGroupAttributes(id1: UUID = UUID.randomUUID(), id2: UUID = UUID.randomUUID()): Seq[CatalogAttribute] =
Seq(
CatalogAttribute(id1, explicitAttributeVerification = false),
CatalogAttribute(id2, explicitAttributeVerification = false)
)

def catalogCertifiedAttribute(id: UUID = UUID.randomUUID()): CatalogAttributes =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ import it.pagopa.interop.catalogmanagement.model.{
CatalogDescriptorState,
CatalogItem,
Deprecated,
GroupAttribute,
Published,
SingleAttribute
Published
}
import it.pagopa.interop.certifiedMailSender.InteropEnvelope
import it.pagopa.interop.commons.cqrs.service.ReadModelService
Expand Down Expand Up @@ -543,11 +541,8 @@ final case class AgreementApiServiceImpl(
val declared = eService.descriptors.flatMap(_.attributes.declared)
val verified = eService.descriptors.flatMap(_.attributes.verified)
(certified ++ declared ++ verified)
.flatMap {
case single: SingleAttribute => Seq(single.id.id)
case group: GroupAttribute => group.ids.map(_.id)
}
.contains(attributeId)
.flatMap(_.map(_.id))
.exists(_ == attributeId)
}

val result: Future[Unit] = for {
Expand Down Expand Up @@ -1001,12 +996,12 @@ final case class AgreementApiServiceImpl(
case _ => stateByAttribute
}

private def matchingAttributes(eServiceAttributes: Seq[CatalogAttribute], consumerAttributes: Seq[UUID]): Seq[UUID] =
private def matchingAttributes(
eServiceAttributes: Seq[Seq[CatalogAttribute]],
consumerAttributes: Seq[UUID]
): Seq[UUID] =
eServiceAttributes
.flatMap {
case single: SingleAttribute => Seq(single.id.id)
case group: GroupAttribute => group.ids.map(_.id)
}
.flatMap(_.map(_.id))
.intersect(consumerAttributes)

private def matchingCertifiedAttributes(
Expand Down
18 changes: 7 additions & 11 deletions src/test/scala/it/pagopa/interop/agreementprocess/SpecData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ import java.time.{OffsetDateTime, ZoneOffset}
import java.util.UUID
import it.pagopa.interop.catalogmanagement.model.{
Automatic,
CatalogAttributeValue,
CatalogAttribute,
CatalogAttributes,
CatalogDescriptor,
CatalogItem,
GroupAttribute,
Rest,
SingleAttribute,
Archived => CatalogArchived,
Deprecated => CatalogDeprecated,
Draft => CatalogDraft,
Expand Down Expand Up @@ -118,15 +116,13 @@ object SpecData {
kind = PersistentTenantKind.PA.some
)

def catalogSingleAttribute(id: UUID = UUID.randomUUID()): SingleAttribute =
SingleAttribute(CatalogAttributeValue(id, explicitAttributeVerification = false))
def catalogSingleAttribute(id: UUID = UUID.randomUUID()): Seq[CatalogAttribute] =
Seq(CatalogAttribute(id, explicitAttributeVerification = false))

def catalogGroupAttributes(id1: UUID = UUID.randomUUID(), id2: UUID = UUID.randomUUID()): GroupAttribute =
GroupAttribute(
Seq(
CatalogAttributeValue(id1, explicitAttributeVerification = false),
CatalogAttributeValue(id2, explicitAttributeVerification = false)
)
def catalogGroupAttributes(id1: UUID = UUID.randomUUID(), id2: UUID = UUID.randomUUID()): Seq[CatalogAttribute] =
Seq(
CatalogAttribute(id1, explicitAttributeVerification = false),
CatalogAttribute(id2, explicitAttributeVerification = false)
)

def catalogCertifiedAttribute(id: UUID = UUID.randomUUID()): CatalogAttributes =
Expand Down

0 comments on commit 4098157

Please sign in to comment.