-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from catenax-ng/feature/policy_hub
update(policies): setup for policy hub
- Loading branch information
Showing
2 changed files
with
264 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 || ''], | ||
}, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters