From 2ccbc3c0cd52c9c986cda6153eb529898f0769ae Mon Sep 17 00:00:00 2001 From: ajithsimons Date: Wed, 7 Feb 2024 13:25:19 +0530 Subject: [PATCH 1/4] update(policies): setup for policy hub --- src/models/RecurringUpload.models.tsx | 142 ++++++++++++++++++++++++++ src/utils/constants.ts | 136 +++++++++++++++++++----- 2 files changed, 252 insertions(+), 26 deletions(-) create mode 100644 src/models/RecurringUpload.models.tsx diff --git a/src/models/RecurringUpload.models.tsx b/src/models/RecurringUpload.models.tsx new file mode 100644 index 00000000..db613996 --- /dev/null +++ b/src/models/RecurringUpload.models.tsx @@ -0,0 +1,142 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +/******************************************************************************** + * Copyright (c) 2023 T-Systems International GmbH + * Copyright (c) 2022,2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +import { find, includes } from 'lodash'; + +import { PCF_FRAMEWORK, PURPOSE_VALUES, QUALTIY_FRAMEWORK, TRACABILITY_FRAMEWORK } from '../utils/constants'; + +export class PolicyModel { + uuid: string; + + policy_name: string; + + inputBpn: string; + + access_policies: any; + + usage_policies: any; + + private static findValueInFramework(framework: any[], policyData: any, technicalKey: string): string { + const policyValue = find(policyData.usage_policies, { technicalKey })?.value[0] || ''; + return find(framework, { value: policyValue }) || ''; + } + + constructor(policyData: any) { + this.uuid = policyData.uuid; + this.policy_name = policyData.policy_name; + this.inputBpn = policyData.inputBpn; + + const isActive = (technicalKey: string, data: any) => includes(find(data, { technicalKey })?.value, 'active'); + + this.access_policies = { + bpn_numbers: { + value: find(policyData.access_policies, { technicalKey: 'BusinessPartnerNumber' })?.value || [], + }, + membership: { + value: isActive('Membership', policyData.access_policies), + }, + dismantler: { + value: isActive('Dismantler', policyData.access_policies), + }, + }; + this.usage_policies = { + membership: { + value: isActive('Membership', policyData.usage_policies), + }, + dismantler: { + value: isActive('Dismantler', policyData.usage_policies), + }, + traceability: { + technicalKey: 'FrameworkAgreement.traceability', + value: PolicyModel.findValueInFramework(TRACABILITY_FRAMEWORK, policyData, 'FrameworkAgreement.traceability'), + }, + quality: { + technicalKey: 'FrameworkAgreement.quality', + value: PolicyModel.findValueInFramework(QUALTIY_FRAMEWORK, policyData, 'FrameworkAgreement.quality'), + }, + pcf: { + technicalKey: 'FrameworkAgreement.pcf', + value: PolicyModel.findValueInFramework(PCF_FRAMEWORK, policyData, 'FrameworkAgreement.pcf'), + }, + purpose: { + technicalKey: 'PURPOSE', + value: PolicyModel.findValueInFramework(PURPOSE_VALUES, policyData, 'PURPOSE'), + }, + }; + } +} + +export class PolicyPayload { + uuid: string; + + policy_name: string; + + inputBpn: string; + + access_policies: any; + + usage_policies: any; + + constructor(policyData: any) { + this.uuid = policyData.uuid; + this.policy_name = policyData.policy_name; + this.access_policies = [ + { + technicalKey: 'BusinessPartnerNumber', + value: policyData.access_policies.bpn_numbers.value, + }, + { + technicalKey: 'Membership', + value: [policyData.access_policies.membership.value ? 'active' : ''], + }, + { + technicalKey: 'Dismantler', + value: [policyData.access_policies.dismantler.value ? 'active' : ''], + }, + ]; + this.usage_policies = [ + { + technicalKey: 'Membership', + value: [policyData.usage_policies.membership.value ? 'active' : ''], + }, + { + technicalKey: 'Dismantler', + value: [policyData.usage_policies.dismantler.value ? 'active' : ''], + }, + { + technicalKey: 'FrameworkAgreement.traceability', + value: [policyData.usage_policies.traceability?.value?.value || ''], + }, + { + technicalKey: 'FrameworkAgreement.quality', + value: [policyData.usage_policies.quality?.value?.value || ''], + }, + { + technicalKey: 'FrameworkAgreement.pcf', + value: [policyData.usage_policies.pcf?.value?.value || ''], + }, + { + technicalKey: 'PURPOSE', + value: [policyData.usage_policies.purpose?.value?.value || ''], + }, + ]; + } +} diff --git a/src/utils/constants.ts b/src/utils/constants.ts index b0c847b7..3ad32f44 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -20,7 +20,14 @@ import { theme } from 'cx-portal-shared-components'; -import { IDefaultObject, ISelectList } from '../models/Common'; +import { IDefaultObject } from '../models/Common'; +import { PolicyModel } from '../models/RecurringUpload.models'; +import { Config } from './config'; + +const USER_GUIDE_URL = + 'https://github.com/eclipse-tractusx/managed-simple-data-exchanger-frontend/blob/main/docs/user-guide/README.md'; + +const MAX_CONTRACTS_AGREEMENTS = 2147483647; const ONLY_NUM_REGEX = /^[1-9]\d*$/; @@ -28,7 +35,7 @@ const ALPHA_NUM_REGEX = /[a-zA-Z0-9]$/; const SPACE_CHECK_REGEX = /^\S*$/; -const CONTRACT_STATES: string[] = ['FINALIZED', 'DECLINED', 'TERMINATED', 'ERROR']; +const CONTRACT_STATES = ['FINALIZED', 'DECLINED', 'TERMINATED', 'ERROR']; const STATUS_COLOR_MAPPING: IDefaultObject = { IN_PROGRESS: theme.palette.info.main, @@ -38,6 +45,7 @@ const STATUS_COLOR_MAPPING: IDefaultObject = { DECLINED: theme.palette.error.main, ERROR: theme.palette.error.main, FAILED: theme.palette.error.main, + PARTIALLY_FAILED: theme.palette.error.main, }; const USER_TYPE_SWITCH: IDefaultObject = { @@ -45,52 +53,128 @@ const USER_TYPE_SWITCH: IDefaultObject = { consumer: 'provider', }; -const DURATION_UNITS: ISelectList[] = [ - { - id: 0, - title: 'Hour', - value: 'HOUR', - }, +const BPN_TYPE_FIELDS = [ { id: 1, - title: 'Day', - value: 'DAY', + title: 'Company Name', + value: 'company', }, { id: 2, - title: 'Month', - value: 'MONTH', + title: 'Business Partner Number', + value: 'bpn', + }, +]; + +const TRACABILITY_FRAMEWORK = [ + { + key: 'Version', + value: 'active:1.0', + }, + { + key: 'Version', + value: 'active:1.1', }, { - id: 3, - title: 'Year', - value: 'YEAR', + key: 'Version', + value: 'active:1.2', }, ]; -const DURATION_UNIT_MAPPING = { - HOUR: 'hours', - DAY: 'days', - MONTH: 'months', - YEAR: 'years', -}; +const QUALTIY_FRAMEWORK = [ + { + key: 'Version', + value: 'active:1.0', + }, +]; + +const PCF_FRAMEWORK = [ + { + key: 'Version', + value: 'active:1.0', + }, +]; -const PURPOSE_VALUES: ISelectList[] = [ +const PURPOSE_VALUES = [ { - id: 0, - title: 'ID 3.1 Trace', + key: 'ID 3.1 Trace', value: 'ID 3.1 Trace', }, ]; +const CHECKBOXES = [ + { name: 'membership', title: 'Membership', type: 'checkbox', values: '' }, + { name: 'dismantler', title: 'Dismantler', type: 'checkbox', values: '' }, +]; + +const FRAMEWORKS = [ + { name: 'traceability', title: 'Framework Traceability', type: 'select', values: TRACABILITY_FRAMEWORK }, + { name: 'quality', title: 'Framework Quality', type: 'select', values: QUALTIY_FRAMEWORK }, + { name: 'pcf', title: 'Framework PCF', type: 'select', values: PCF_FRAMEWORK }, + { name: 'purpose', title: 'Select Purpose', type: 'select', values: PURPOSE_VALUES }, +]; + +const DEFAULT_POLICY_DATA: PolicyModel = { + uuid: '', + policy_name: '', + inputBpn: '', + access_policies: [ + { + technicalKey: 'BusinessPartnerNumber', + value: [Config.REACT_APP_DEFAULT_COMPANY_BPN], + }, + { + technicalKey: 'Membership', + value: false, + }, + { + technicalKey: 'Dismantler', + value: false, + }, + ], + usage_policies: [ + { + technicalKey: 'Membership', + value: false, + }, + { + technicalKey: 'Dismantler', + value: false, + }, + { + technicalKey: 'FrameworkAgreement.traceability', + value: '', + }, + { + technicalKey: 'FrameworkAgreement.quality', + value: '', + }, + { + technicalKey: 'FrameworkAgreement.pcf', + value: '', + }, + { + technicalKey: 'PURPOSE', + value: '', + }, + ], +}; + export { ALPHA_NUM_REGEX, + BPN_TYPE_FIELDS, + CHECKBOXES, CONTRACT_STATES, - DURATION_UNIT_MAPPING, - DURATION_UNITS, + DEFAULT_POLICY_DATA, + FRAMEWORKS, + MAX_CONTRACTS_AGREEMENTS, ONLY_NUM_REGEX, + PCF_FRAMEWORK, PURPOSE_VALUES, + QUALTIY_FRAMEWORK, SPACE_CHECK_REGEX, STATUS_COLOR_MAPPING, + TRACABILITY_FRAMEWORK, + USER_GUIDE_URL, USER_TYPE_SWITCH, }; From 9927587a4dd266330f75f16b6e2690fe19e50497 Mon Sep 17 00:00:00 2001 From: ajithsimons Date: Wed, 7 Feb 2024 13:59:03 +0530 Subject: [PATCH 2/4] bug fix --- src/utils/constants.ts | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 3ad32f44..6d9c21d4 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -20,7 +20,7 @@ import { theme } from 'cx-portal-shared-components'; -import { IDefaultObject } from '../models/Common'; +import { IDefaultObject, ISelectList } from '../models/Common'; import { PolicyModel } from '../models/RecurringUpload.models'; import { Config } from './config'; @@ -53,6 +53,36 @@ const USER_TYPE_SWITCH: IDefaultObject = { consumer: 'provider', }; +const DURATION_UNITS: ISelectList[] = [ + { + id: 0, + title: 'Hour', + value: 'HOUR', + }, + { + id: 1, + title: 'Day', + value: 'DAY', + }, + { + id: 2, + title: 'Month', + value: 'MONTH', + }, + { + id: 3, + title: 'Year', + value: 'YEAR', + }, +]; + +const DURATION_UNIT_MAPPING = { + HOUR: 'hours', + DAY: 'days', + MONTH: 'months', + YEAR: 'years', +}; + const BPN_TYPE_FIELDS = [ { id: 1, @@ -166,6 +196,8 @@ export { CHECKBOXES, CONTRACT_STATES, DEFAULT_POLICY_DATA, + DURATION_UNIT_MAPPING, + DURATION_UNITS, FRAMEWORKS, MAX_CONTRACTS_AGREEMENTS, ONLY_NUM_REGEX, From ef4cd3d7d9da697530a8488900a78955298631e6 Mon Sep 17 00:00:00 2001 From: ajithsimons Date: Wed, 7 Feb 2024 20:57:17 +0530 Subject: [PATCH 3/4] 2024 copyrights updated --- src/models/RecurringUpload.models.tsx | 2 +- src/utils/constants.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/models/RecurringUpload.models.tsx b/src/models/RecurringUpload.models.tsx index db613996..4c441ef9 100644 --- a/src/models/RecurringUpload.models.tsx +++ b/src/models/RecurringUpload.models.tsx @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ /******************************************************************************** - * Copyright (c) 2023 T-Systems International GmbH + * Copyright (c) 2023, 2024 T-Systems International GmbH * Copyright (c) 2022,2023 Contributors to the Eclipse Foundation * * See the NOTICE file(s) distributed with this work for additional diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 6d9c21d4..05e988bb 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -1,6 +1,6 @@ /******************************************************************************** - * Copyright (c) 2021,2022,2023 T-Systems International GmbH - * Copyright (c) 2022,2023 Contributors to the Eclipse Foundation + * Copyright (c) 2023,2024 T-Systems International GmbH + * Copyright (c) 2023,2024 Contributors to the Eclipse Foundation * * See the NOTICE file(s) distributed with this work for additional * information regarding copyright ownership. From 8a74693f1b3c0cf69820d18296c44a318a699b42 Mon Sep 17 00:00:00 2001 From: ajithsimons Date: Thu, 8 Feb 2024 14:39:28 +0530 Subject: [PATCH 4/4] copyrights updated --- src/models/RecurringUpload.models.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/models/RecurringUpload.models.tsx b/src/models/RecurringUpload.models.tsx index 4c441ef9..ef6d934f 100644 --- a/src/models/RecurringUpload.models.tsx +++ b/src/models/RecurringUpload.models.tsx @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ /******************************************************************************** - * Copyright (c) 2023, 2024 T-Systems International GmbH - * Copyright (c) 2022,2023 Contributors to the Eclipse Foundation + * Copyright (c) 2024 T-Systems International GmbH + * Copyright (c) 2024 Contributors to the Eclipse Foundation * * See the NOTICE file(s) distributed with this work for additional * information regarding copyright ownership.