Skip to content

Commit

Permalink
PIN-4701 BKE agreement-process - Added to getAgreementEServiceProduce…
Browse files Browse the repository at this point in the history
…rs states filter
  • Loading branch information
nttdata-rtorsoli committed Mar 11, 2024
1 parent 84f1d66 commit 695b289
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
9 changes: 9 additions & 0 deletions src/main/resources/interface-specification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,15 @@ paths:
format: uuid
default: []
explode: false
- in: query
name: states
description: comma separated sequence of states
schema:
type: array
items:
$ref: '#/components/schemas/AgreementState'
default: []
explode: false
- in: query
name: offset
required: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,7 @@ final case class AgreementApiServiceImpl(
eServiceName: Option[String],
consumersIds: String,
producersIds: String,
states: String,
offset: Int,
limit: Int
)(implicit
Expand All @@ -1296,10 +1297,12 @@ final case class AgreementApiServiceImpl(
logger.info(operationLabel)

val result: Future[CompactEServices] = for {
eservices <- ReadModelAgreementQueries.listEServicesAgreements(
statesEnum <- parseArrayParameters(states).traverse(AgreementState.fromValue).toFuture
eservices <- ReadModelAgreementQueries.listEServicesAgreements(
eServiceName = eServiceName,
consumersIds = parseArrayParameters(consumersIds),
producersIds = parseArrayParameters(producersIds),
states = statesEnum,
offset = offset,
limit = limit
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,24 +301,29 @@ object ReadModelAgreementQueries extends ReadModelQuery {
private def listEServiceAgreementsFilters(
name: Option[String],
consumersIds: List[String],
producersIds: List[String]
producersIds: List[String],
states: List[AgreementState]
): Bson = {
val nameFilter = name.map(n => Filters.regex("eservices.data.name", escape(n), "i"))
val consumersIdsFilter = mapToVarArgs(consumersIds.map(Filters.eq("data.consumerId", _)))(Filters.or)
val producersIdsFilter = mapToVarArgs(producersIds.map(Filters.eq("data.producerId", _)))(Filters.or)
val statesFilter = listStatesFilter(states)

mapToVarArgs(nameFilter.toList ++ consumersIdsFilter.toList ++ producersIdsFilter.toList)(Filters.and)
mapToVarArgs(nameFilter.toList ++ consumersIdsFilter.toList ++ producersIdsFilter.toList ++ statesFilter.toList)(
Filters.and
)
.getOrElse(Filters.empty())
}

def listEServicesAgreements(
eServiceName: Option[String],
consumersIds: List[String],
producersIds: List[String],
states: List[AgreementState],
offset: Int,
limit: Int
)(implicit ec: ExecutionContext, readModel: ReadModelService): Future[PaginatedResult[CompactEService]] = {
val query: Bson = listEServiceAgreementsFilters(eServiceName, consumersIds, producersIds)
val query: Bson = listEServiceAgreementsFilters(eServiceName, consumersIds, producersIds, states)
val filterPipeline: Seq[Bson] = Seq(
lookup("eservices", "data.eserviceId", "data.id", "eservices"),
unwind("$eservices", UnwindOptions().preserveNullAndEmptyArrays(false)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class AgreementApiAuthzSpec extends AnyWordSpecLike with MockFactory with AuthzS
validateAuthorization(
endpoint,
{ implicit c: Seq[(String, String)] =>
service.getAgreementEServices(Some("query"), "consumersIds", "producersIds", 0, 0)
service.getAgreementEServices(Some("query"), "consumersIds", "producersIds", "states", 0, 0)
}
)
}
Expand Down

0 comments on commit 695b289

Please sign in to comment.