Skip to content

Commit

Permalink
Merge pull request #61 from catenax-ng/feature/policy_hub
Browse files Browse the repository at this point in the history
update(policies): setup for policy hub
  • Loading branch information
almadigabor authored Feb 8, 2024
2 parents e6989cb + 8a74693 commit 6be2289
Show file tree
Hide file tree
Showing 2 changed files with 264 additions and 6 deletions.
142 changes: 142 additions & 0 deletions src/models/RecurringUpload.models.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/********************************************************************************
* 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.
*
* 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 || ''],
},
];
}
}
128 changes: 122 additions & 6 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -21,14 +21,21 @@
import { theme } from 'cx-portal-shared-components';

import { IDefaultObject, ISelectList } 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*$/;

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,
Expand All @@ -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 = {
Expand Down Expand Up @@ -75,22 +83,130 @@ const DURATION_UNIT_MAPPING = {
YEAR: 'years',
};

const PURPOSE_VALUES: ISelectList[] = [
const BPN_TYPE_FIELDS = [
{
id: 0,
title: 'ID 3.1 Trace',
id: 1,
title: 'Company Name',
value: 'company',
},
{
id: 2,
title: 'Business Partner Number',
value: 'bpn',
},
];

const TRACABILITY_FRAMEWORK = [
{
key: 'Version',
value: 'active:1.0',
},
{
key: 'Version',
value: 'active:1.1',
},
{
key: 'Version',
value: 'active:1.2',
},
];

const QUALTIY_FRAMEWORK = [
{
key: 'Version',
value: 'active:1.0',
},
];

const PCF_FRAMEWORK = [
{
key: 'Version',
value: 'active:1.0',
},
];

const PURPOSE_VALUES = [
{
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,
DEFAULT_POLICY_DATA,
DURATION_UNIT_MAPPING,
DURATION_UNITS,
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,
};

0 comments on commit 6be2289

Please sign in to comment.