Skip to content

Commit

Permalink
Added delegated filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Carminepo2 committed Nov 12, 2024
1 parent af285de commit afaf163
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 12 deletions.
5 changes: 5 additions & 0 deletions packages/api-clients/open-api/bffApi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4405,6 +4405,11 @@ paths:
format: uuid
default: []
explode: false
- in: query
name: delegated
description: if true only delegated e-services will be returned, if false only non-delegated e-services will be returned, if not present all e-services will be returned
schema:
type: boolean
- in: query
name: offset
required: true
Expand Down
5 changes: 5 additions & 0 deletions packages/api-clients/open-api/catalogApi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ paths:
description: mode
schema:
$ref: "#/components/schemas/EServiceMode"
- in: query
name: delegated
description: if true only delegated e-services will be returned, if false only non-delegated e-services will be returned, if not present all e-services will be returned
schema:
type: boolean
- in: query
name: offset
required: true
Expand Down
1 change: 1 addition & 0 deletions packages/backend-for-frontend/src/routers/catalogRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const catalogRouter = (
const response = await catalogService.getProducerEServices(
req.query.q,
req.query.consumersIds,
req.query.delegated,
req.query.offset,
req.query.limit,
ctx
Expand Down
3 changes: 3 additions & 0 deletions packages/backend-for-frontend/src/services/catalogService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ export function catalogServiceBuilder(
getProducerEServices: async (
eserviceName: string | undefined,
consumersIds: string[],
delegated: boolean | undefined,
offset: number,
limit: number,
{ headers, authData, logger }: WithLogger<BffAppContext>
Expand All @@ -454,6 +455,7 @@ export function catalogServiceBuilder(
queries: {
name: eserviceName,
producersIds: producerId,
delegated,
offset,
limit,
},
Expand All @@ -479,6 +481,7 @@ export function catalogServiceBuilder(
name: eserviceName,
eservicesIds: eserviceIds,
producersIds: producerId,
delegated,
offset,
limit,
},
Expand Down
1 change: 1 addition & 0 deletions packages/catalog-process/src/model/domain/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type ApiGetEServicesFilters = {
agreementStates: AgreementState[];
name?: string;
mode?: EServiceMode;
delegated?: boolean;
};

export type EServiceDocument = {
Expand Down
2 changes: 2 additions & 0 deletions packages/catalog-process/src/routers/EServiceRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ const eservicesRouter = (
states,
agreementStates,
mode,
delegated,
offset,
limit,
} = req.query;
Expand All @@ -128,6 +129,7 @@ const eservicesRouter = (
),
name,
mode: mode ? apiEServiceModeToEServiceMode(mode) : undefined,
delegated,
},
offset,
limit,
Expand Down
35 changes: 23 additions & 12 deletions packages/catalog-process/src/services/readModelService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export function readModelServiceBuilder(
name,
attributesIds,
mode,
delegated,
} = filters;
const ids = await match(agreementStates.length)
.with(0, () => eservicesIds)
Expand Down Expand Up @@ -165,7 +166,7 @@ export function readModelServiceBuilder(
);

const delegationLookup =
producersIds.length > 0
producersIds.length > 0 || delegated !== undefined
? [
{
$lookup: {
Expand Down Expand Up @@ -261,19 +262,29 @@ export function readModelServiceBuilder(
? { "data.mode": { $eq: mode } }
: {};

const delegatedFilter: ReadModelFilter<EService> = match(delegated)
.with(true, () => ({
"delegation.data.state": {
$in: [delegationState.active, delegationState.waitingForApproval],
},
}))
.with(false, () => ({
"delegation.data.state": {
$nin: [delegationState.active, delegationState.waitingForApproval],
},
}))
.otherwise(() => ({}));

const aggregationPipeline = [
...delegationLookup,
{
$match: {
...nameFilter,
...idsFilter,
...producersIdsFilter,
...descriptorsStateFilter,
...attributesFilter,
...visibilityFilter,
...modeFilter,
} satisfies ReadModelFilter<EService>,
},
{ $match: nameFilter },
{ $match: idsFilter },
{ $match: producersIdsFilter },
{ $match: descriptorsStateFilter },
{ $match: attributesFilter },
{ $match: visibilityFilter },
{ $match: modeFilter },
{ $match: delegatedFilter },
{
$project: {
data: 1,
Expand Down
125 changes: 125 additions & 0 deletions packages/catalog-process/test/getEservices.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,95 @@ describe("get eservices", () => {
eservice5,
]);
});
it("should get the eServices if they exist (parameters: delegated = true)", async () => {
const delegatedOrganization1 = generateId<TenantId>();
const delegatedOrganization2 = generateId<TenantId>();

await addOneDelegation({
...getMockDelegationProducer(),
eserviceId: eservice4.id,
delegateId: delegatedOrganization1,
state: delegationState.active,
});

await addOneDelegation({
...getMockDelegationProducer(),
eserviceId: eservice5.id,
delegateId: delegatedOrganization2,
state: delegationState.waitingForApproval,
});

await addOneDelegation({
...getMockDelegationProducer(),
eserviceId: eservice6.id,
delegateId: delegatedOrganization2,
state: delegationState.rejected,
});

const result = await catalogService.getEServices(
getMockAuthData(),
{
eservicesIds: [],
producersIds: [],
states: [],
agreementStates: [],
attributesIds: [],
delegated: true,
},
0,
50,
genericLogger
);
expect(result.totalCount).toBe(2);
expect(result.results).toEqual([eservice4, eservice5]);
});
it("should get the eServices if they exist (parameters: delegated = false)", async () => {
const delegatedOrganization1 = generateId<TenantId>();
const delegatedOrganization2 = generateId<TenantId>();

await addOneDelegation({
...getMockDelegationProducer(),
eserviceId: eservice4.id,
delegateId: delegatedOrganization1,
state: delegationState.active,
});

await addOneDelegation({
...getMockDelegationProducer(),
eserviceId: eservice5.id,
delegateId: delegatedOrganization2,
state: delegationState.waitingForApproval,
});

await addOneDelegation({
...getMockDelegationProducer(),
eserviceId: eservice6.id,
delegateId: delegatedOrganization2,
state: delegationState.rejected,
});

const result = await catalogService.getEServices(
getMockAuthData(),
{
eservicesIds: [],
producersIds: [],
states: [],
agreementStates: [],
attributesIds: [],
delegated: false,
},
0,
50,
genericLogger
);
expect(result.totalCount).toBe(4);
expect(result.results).toEqual([
eservice1,
eservice2,
eservice3,
eservice6,
]);
});
it("should get the eServices if they exist (parameters: statestates, name)", async () => {
const result = await catalogService.getEServices(
getMockAuthData(organizationId3),
Expand Down Expand Up @@ -658,6 +747,42 @@ describe("get eservices", () => {
});
});

it("should get the eServices if they exist (parameters: producersIds, mode, delegated = true)", async () => {
await addOneDelegation({
...getMockDelegationProducer(),
eserviceId: eservice4.id,
delegateId: organizationId3,
state: delegationState.active,
});

await addOneDelegation({
...getMockDelegationProducer(),
eserviceId: eservice5.id,
delegateId: organizationId3,
state: delegationState.revoked,
});

const result = await catalogService.getEServices(
getMockAuthData(),
{
eservicesIds: [],
producersIds: [organizationId2],
states: [],
agreementStates: [],
attributesIds: [],
mode: eserviceMode.deliver,
delegated: true,
},
0,
50,
genericLogger
);
expect(result).toEqual({
totalCount: 1,
results: [eservice4],
});
});

it("should get the eServices, including the ones with an active delegation, if they exist (parameters: producersIds, mode)", async () => {
const delegatedOrganization1: TenantId = generateId();
const delegatedOrganization2: TenantId = generateId();
Expand Down

0 comments on commit afaf163

Please sign in to comment.