Skip to content

Commit

Permalink
Merge pull request #1050 from eclipse-tractusx/feature/962-fe-notific…
Browse files Browse the repository at this point in the history
…ation-model-change

Feature/962 fe notification model change
  • Loading branch information
ds-mwesener authored Jun 19, 2024
2 parents 715365f + 1d02944 commit 2a04dc2
Show file tree
Hide file tree
Showing 18 changed files with 280 additions and 283 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ _**For better traceability add the corresponding GitHub issue number in each cha
## [UNRELEASED - DD.MM.YYYY]
### Changed
- #965 Implement proxy functionality of the IRS policy store
- #962 Changed notification model to new one in frontend/backend

### Added
- #832 added policymanagement list view, creator and editor
Expand Down
20 changes: 5 additions & 15 deletions frontend/src/app/mocks/services/alerts-mock/alerts.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,30 +80,20 @@ export const alertsHandlers = [
}),

rest.get(`*${ environment.apiUrl }/notifications/:notificationId`, (req, res, ctx) => {
const { alertId } = req.params;

const indexFromId = parseInt((alertId as string).replace('id-', ''), 10);

const statusCollection = [
NotificationStatus.CREATED,
NotificationStatus.SENT,
const { notificationId } = req.params;
const indexFromId = parseInt((notificationId as string).replace('id-', ''), 10);
const currentStatus = [
NotificationStatus.RECEIVED,
NotificationStatus.CLOSED,
NotificationStatus.CANCELED,
NotificationStatus.ACKNOWLEDGED,
NotificationStatus.ACCEPTED,
NotificationStatus.DECLINED,

NotificationStatus.ACKNOWLEDGED,
NotificationStatus.ACCEPTED,
NotificationStatus.DECLINED,
NotificationStatus.CLOSED,
NotificationStatus.CANCELED,
];
const channel = [ 2, 8, 9, 10, 11, 12 ].includes(indexFromId) ? 'RECEIVER' : 'SENDER';
const randomNotification = buildMockAlerts([ statusCollection[indexFromId] ], channel)[0];
const randomNotification = buildMockAlerts(currentStatus, channel)[0];

return res(ctx.status(200), ctx.json({ ...randomNotification, id: alertId }));
return res(ctx.status(200), ctx.json({ ...randomNotification, id: notificationId }));
}),
rest.post(`*${ environment.apiUrl }/notifications`, (_, res, ctx) => {
return res(ctx.status(400), ctx.json({message: "Error while sending Alert to EDC"} ));
Expand Down
48 changes: 17 additions & 31 deletions frontend/src/app/mocks/services/alerts-mock/alerts.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,62 +38,48 @@ export const buildMockAlerts = (
new Array(101).fill(null).map((_, index) => {
const status = statuses[index % statuses.length];
const severity = severities[index % severities.length];
// every 10th alert should have an error
const errorAlert = (index + 1) % 10 === 0 ? 'The Services returned an Error while processing this Alert' : undefined;

const close = status === NotificationStatus.CLOSED ? getRandomText(getRandomIntFromInterval(15, 500)) : '';
const isDeclined = Math.random() >= 0.5;

const decline =
status === NotificationStatus.DECLINED || (!!close && isDeclined)
? getRandomText(getRandomIntFromInterval(15, 500))
: '';

const accept =
status === NotificationStatus.ACCEPTED || (!!close && !isDeclined)
? getRandomText(getRandomIntFromInterval(15, 500))
: '';

const numberToString = (i: number) => i.toString().padStart(2, '0');
const month = getRandomIntFromInterval(1, 12);
const day = getRandomIntFromInterval(1, 27);

return {
id: `${ AlertIdPrefix }${ index + 1 }`,
description: `Alert No ${ index + 1 } ${ getRandomText(getRandomIntFromInterval(15, 500)) }`,
title: 'title',
type: NotificationTypeResponse.ALERT,
status,
severity,
channel,
description: `Alert No ${ index + 1 } ${ getRandomText(getRandomIntFromInterval(15, 500)) }`,
createdBy: 'BPN10000000OEM0A',
createdByName: 'OEM xxxxxxxxxxxxxxx A',
createdDate: `2022-${ numberToString(month) }-${ numberToString(day) }T12:34:12`,
updatedDate: `2022-${ numberToString(month) }-${ numberToString(day) }T12:34:12`,
assetIds: [ MOCK_part_1.id, getRandomAsset().id, getRandomAsset().id, getRandomAsset().id ],
channel,
sendTo: 'BPN20000000OEM0B',
sendToName: 'OEM xxxxxxxxxxxxxxx B',
reason: { close, decline, accept },
createdDate: `2022-${ numberToString(month) }-${ numberToString(day) }T12:34:12`,
severity,
targetDate: `2022-${ numberToString(month) }-${ numberToString(day + 1) }T12:34:12`,
assetIds: [ MOCK_part_1.id, getRandomAsset().id, getRandomAsset().id, getRandomAsset().id ],
errorMessage: errorAlert,
type: NotificationTypeResponse.ALERT,
messages: [],
};
});

const MockEmptyAlert: NotificationResponse = {
id: `${ AlertIdPrefix }000`,
description: `Alert No 000`,
status: NotificationStatus.CREATED,
title: 'Title',
severity: Severity.MINOR,
type: NotificationTypeResponse.ALERT,
status: NotificationStatus.CREATED,
description: `Alert No 000`,
createdBy: 'BPN10000000OEM0A',
createdByName: 'OEM xxxxxxxxxxxxxxx A',
sendTo: 'BPN20000000OEM0B',
sendToName: 'OEM xxxxxxxxxxxxxxx B',
reason: { close: '', decline: '', accept: '' },
createdDate: `2022-05-01T12:34:12`,
targetDate: `2022-02-01T12:34:12`,
updatedDate: `2022-05-01T12:34:12`,
assetIds: [ getRandomAsset().id ],
channel: 'SENDER',
type: NotificationTypeResponse.ALERT,
sendTo: 'BPN20000000OEM0B',
sendToName: 'OEM xxxxxxxxxxxxxxx B',
severity: Severity.MINOR,
targetDate: `2022-02-01T12:34:12`,
messages: [],
};

export const getAlertById = (id: string) => {
Expand Down
37 changes: 20 additions & 17 deletions frontend/src/app/mocks/services/alerts-mock/alerts.test.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { NotificationStatus, NotificationTypeResponse } from '@shared/model/noti
import { Severity } from '@shared/model/severity.model';
import { getRandomAsset } from '../parts-mock/partsAsPlanned/partsAsPlanned.model';
import { MOCK_part_1 } from '../parts-mock/partsAsPlanned/partsAsPlanned.test.model';
import { getRandomIntFromInterval, getRandomText } from '../text-generator.helper';

export const AlertIdPrefix = 'id-';

Expand All @@ -39,42 +40,44 @@ export const buildMockAlerts = (
const numberToString = (i: number) => i.toString().padStart(2, '0');
const month = (index % 12) + 1;
const day = (index % 28) + 1;
const errorAlert = (index + 1) % 10 === 0 ? 'The Services returned an Error while processing this Alert' : '';

return {
id: `${ AlertIdPrefix }${ index + 1 }`,
description: `Alert No ${ index + 1 }`,
title: 'title',
type: NotificationTypeResponse.ALERT,
status,
severity,
channel,
description: `Alert No ${ index + 1 } ${ getRandomText(getRandomIntFromInterval(15, 500)) }`,
createdBy: 'BPN10000000OEM0A',
createdByName: 'OEM xxxxxxxxxxxxxxx A',
sendTo: 'BPN20000000OEM0B',
title: 'Title',
sendToName: 'OEM xxxxxxxxxxxxxxx B',
reason: { close: '', accept: '', decline: '' },
createdDate: `2022-${ numberToString(month) }-${ numberToString(day) }T12:34:12`,
updatedDate: `2022-${ numberToString(month) }-${ numberToString(day) }T12:34:12`,
assetIds: [ MOCK_part_1.id, getRandomAsset().id, getRandomAsset().id, getRandomAsset().id ],
errorMessage: errorAlert,
type: NotificationTypeResponse.ALERT,
channel,
sendTo: 'BPN20000000OEM0B',
sendToName: 'OEM xxxxxxxxxxxxxxx B',
severity,
targetDate: `2022-${ numberToString(month) }-${ numberToString(day + 1) }T12:34:12`,
messages: [],
};
});

export const MockEmptyAlert: NotificationResponse = {
id: `${ AlertIdPrefix }000`,
description: `Alert No 000`,
title: 'Title',
type: NotificationTypeResponse.ALERT,
status: NotificationStatus.CREATED,
severity: Severity.MINOR,
description: `Alert No 000`,
createdBy: 'BPN10000000OEM0A',
createdByName: 'OEM xxxxxxxxxxxxxxx A',
sendTo: 'BPN20000000OEM0B',
sendToName: 'OEM xxxxxxxxxxxxxxx B',
reason: { close: '', accept: '', decline: '' },
createdDate: `2022-05-01T12:34:12`,
updatedDate: `2022-05-01T12:34:12`,
assetIds: [ getRandomAsset().id ],
channel: 'SENDER',
title: 'Title',
type: NotificationTypeResponse.ALERT,
sendTo: 'BPN20000000OEM0B',
sendToName: 'OEM xxxxxxxxxxxxxxx B',
severity: Severity.MINOR,
targetDate: `2022-02-01T12:34:12`,
messages: [],
};

export const getAlertById = (id: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,21 @@ export const buildMockInvestigations = (

return {
id: `${ InvestigationIdPrefix }${ index + 1 }`,
description: `Investigation No ${ index + 1 }`,
title: 'Title',
type: NotificationTypeResponse.INVESTIGATION,
status,
severity,
channel,
description: `Investigation No ${ index + 1 }`,
createdBy: 'BPN10000000OEM0A',
createdByName: 'OEM xxxxxxxxxxxxxxx A',
sendTo: 'BPN20000000OEM0B',
sendToName: 'OEM xxxxxxxxxxxxxxx B',
reason: { close: '', accept: '', decline: '' },
createdDate: `2022-${ numberToString(month) }-${ numberToString(day) }T12:34:12`,
updatedDate: `2022-${ numberToString(month) }-${ numberToString(day) }T12:34:12`,
assetIds: [ MOCK_part_1.id, getRandomAsset().id, getRandomAsset().id, getRandomAsset().id ],
errorMessage: errorInvestigation,
title: 'Title',
type: NotificationTypeResponse.INVESTIGATION,
channel,
sendTo: 'BPN20000000OEM0B',
sendToName: 'OEM xxxxxxxxxxxxxxx B',
severity,
targetDate: `2022-${ numberToString(month) }-${ numberToString(day + 1) }T12:34:12`,
messages: [],
};
});

Loading

0 comments on commit 2a04dc2

Please sign in to comment.