Michael Lando | dd60339 | 2017-07-12 00:54:52 +0300 | [diff] [blame] | 1 | /*- |
| 2 | * ============LICENSE_START======================================================= |
| 3 | * SDC |
| 4 | * ================================================================================ |
| 5 | * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. |
| 6 | * ================================================================================ |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | * you may not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at |
| 10 | * |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | * |
| 13 | * Unless required by applicable law or agreed to in writing, software |
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | * See the License for the specific language governing permissions and |
| 17 | * limitations under the License. |
| 18 | * ============LICENSE_END========================================================= |
| 19 | */ |
| 20 | |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 21 | import * as _ from "lodash"; |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame] | 22 | import {Module, AttributeModel, ResourceInstance, PropertyModel, InputFEModel, OperationModel} from "../models"; |
ojasdubey | 4192e3c | 2019-03-18 14:15:03 +0530 | [diff] [blame] | 23 | import {ComponentInstanceFactory} from "./component-instance-factory"; |
| 24 | import {InputBEModel, PropertyBEModel, RelationshipModel} from "app/models"; |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 25 | import { PolicyInstance } from "app/models/graph/zones/policy-instance"; |
Michael Lando | 5b59349 | 2018-07-29 16:13:45 +0300 | [diff] [blame] | 26 | import { GroupInstance } from "../models/graph/zones/group-instance"; |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame] | 27 | import { InterfaceModel } from "../models/operation"; |
vasraz | 26e5029 | 2021-02-16 17:37:57 +0000 | [diff] [blame^] | 28 | import {AttributeBEModel} from "../models/attributes-outputs/attribute-be-model"; |
| 29 | import {OutputBEModel} from "../models/attributes-outputs/output-be-model"; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 30 | |
| 31 | export class CommonUtils { |
| 32 | |
| 33 | static initProperties(propertiesObj:Array<PropertyModel>, uniqueId?:string):Array<PropertyModel> { |
| 34 | |
| 35 | let properties = new Array<PropertyModel>(); |
| 36 | if (propertiesObj) { |
vasraz | 26e5029 | 2021-02-16 17:37:57 +0000 | [diff] [blame^] | 37 | propertiesObj.forEach((property:PropertyModel):void => { |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 38 | if (uniqueId) { |
| 39 | property.readonly = property.parentUniqueId != uniqueId; |
| 40 | } |
| 41 | properties.push(new PropertyModel(property)); |
| 42 | }); |
| 43 | } |
| 44 | return properties; |
| 45 | }; |
| 46 | |
| 47 | static initAttributes(attributesObj:Array<AttributeModel>, uniqueId?:string):Array<AttributeModel> { |
| 48 | |
| 49 | let attributes = new Array<AttributeModel>(); |
| 50 | if (attributesObj) { |
vasraz | 26e5029 | 2021-02-16 17:37:57 +0000 | [diff] [blame^] | 51 | attributesObj.forEach((attribute:AttributeModel):void => { |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 52 | if (uniqueId) { |
| 53 | attribute.readonly = attribute.parentUniqueId != uniqueId; |
| 54 | } |
| 55 | attributes.push(new AttributeModel(attribute)); |
| 56 | }); |
| 57 | } |
| 58 | return attributes; |
| 59 | }; |
| 60 | |
| 61 | static initComponentInstances(componentInstanceObj:Array<ResourceInstance>):Array<ResourceInstance> { |
| 62 | |
| 63 | let componentInstances = new Array<ResourceInstance>(); |
| 64 | if (componentInstanceObj) { |
vasraz | 26e5029 | 2021-02-16 17:37:57 +0000 | [diff] [blame^] | 65 | componentInstanceObj.forEach((instance:ResourceInstance):void => { |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 66 | componentInstances.push(ComponentInstanceFactory.createComponentInstance(instance)); |
| 67 | }); |
| 68 | } |
| 69 | return componentInstances; |
| 70 | }; |
| 71 | |
| 72 | static initModules(moduleArrayObj:Array<Module>):Array<Module> { |
| 73 | |
| 74 | let modules = new Array<Module>(); |
| 75 | |
| 76 | if (moduleArrayObj) { |
vasraz | 26e5029 | 2021-02-16 17:37:57 +0000 | [diff] [blame^] | 77 | moduleArrayObj.forEach((module:Module):void => { |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 78 | if (module.type === "org.openecomp.groups.VfModule") { |
| 79 | modules.push(new Module(module)); |
| 80 | } |
| 81 | }); |
| 82 | } |
| 83 | return modules; |
| 84 | }; |
| 85 | |
Tal Gitelman | ed7e1c3 | 2017-06-29 19:30:00 +0300 | [diff] [blame] | 86 | static initInputs(inputsObj: Array<InputBEModel>): Array<InputBEModel> { |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 87 | |
Tal Gitelman | ed7e1c3 | 2017-06-29 19:30:00 +0300 | [diff] [blame] | 88 | let inputs = new Array<InputBEModel>(); |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 89 | |
| 90 | if(inputsObj) { |
vasraz | 26e5029 | 2021-02-16 17:37:57 +0000 | [diff] [blame^] | 91 | inputsObj.forEach((input: InputBEModel):void => { |
Tal Gitelman | ed7e1c3 | 2017-06-29 19:30:00 +0300 | [diff] [blame] | 92 | inputs.push(new InputBEModel(input)); |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 93 | }) |
| 94 | } |
| 95 | |
| 96 | return inputs; |
| 97 | } |
| 98 | |
vasraz | 26e5029 | 2021-02-16 17:37:57 +0000 | [diff] [blame^] | 99 | static initOutputs(outputsObj: Array<OutputBEModel>): Array<OutputBEModel> { |
| 100 | |
| 101 | let outputs = new Array<OutputBEModel>(); |
| 102 | |
| 103 | if(outputsObj) { |
| 104 | outputsObj.forEach((output: OutputBEModel):void => { |
| 105 | outputs.push(new OutputBEModel(output)); |
| 106 | }) |
| 107 | } |
| 108 | |
| 109 | return outputs; |
| 110 | } |
| 111 | |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 112 | static initBeProperties(propertiesObj: Array<PropertyBEModel>): Array<PropertyBEModel> { |
| 113 | |
| 114 | let properties = new Array<PropertyBEModel>(); |
| 115 | |
| 116 | if (propertiesObj) { |
vasraz | 26e5029 | 2021-02-16 17:37:57 +0000 | [diff] [blame^] | 117 | propertiesObj.forEach((property: PropertyBEModel): void => { |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 118 | properties.push(new PropertyBEModel(property)); |
| 119 | }) |
| 120 | } |
| 121 | |
| 122 | return properties; |
| 123 | } |
| 124 | |
vasraz | 26e5029 | 2021-02-16 17:37:57 +0000 | [diff] [blame^] | 125 | static initBeAttributes(attributesObj: Array<AttributeBEModel>): Array<AttributeBEModel> { |
| 126 | |
| 127 | let attributes = new Array<AttributeBEModel>(); |
| 128 | |
| 129 | if (attributesObj) { |
| 130 | attributesObj.forEach((attribute: AttributeBEModel): void => { |
| 131 | attributes.push(new AttributeBEModel(attribute)); |
| 132 | }) |
| 133 | } |
| 134 | |
| 135 | return attributes; |
| 136 | } |
| 137 | |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 138 | static initComponentInstanceRelations = (componentInstanceRelationsObj:Array<RelationshipModel>):Array<RelationshipModel> => { |
| 139 | if (componentInstanceRelationsObj) { |
| 140 | let componentInstancesRelations: Array<RelationshipModel> = []; |
vasraz | 26e5029 | 2021-02-16 17:37:57 +0000 | [diff] [blame^] | 141 | componentInstanceRelationsObj.forEach((instanceRelation:RelationshipModel):void => { |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 142 | componentInstancesRelations.push(new RelationshipModel(instanceRelation)); |
| 143 | }); |
| 144 | return componentInstancesRelations; |
| 145 | } |
| 146 | }; |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 147 | |
| 148 | static initPolicies = (policiesObj: Array<PolicyInstance>):Array<PolicyInstance> => { |
| 149 | let policies = new Array<PolicyInstance>(); |
| 150 | |
| 151 | if (policiesObj) { |
vasraz | 26e5029 | 2021-02-16 17:37:57 +0000 | [diff] [blame^] | 152 | policiesObj.forEach((policy: PolicyInstance): void => { |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 153 | policies.push(new PolicyInstance(policy)); |
| 154 | }) |
| 155 | } |
| 156 | |
| 157 | return policies; |
| 158 | } |
Michael Lando | 5b59349 | 2018-07-29 16:13:45 +0300 | [diff] [blame] | 159 | static initGroups = (groupsObj: Array<GroupInstance>):Array<GroupInstance> => { |
| 160 | let groups = new Array<GroupInstance>(); |
| 161 | |
| 162 | if(groupsObj) { |
vasraz | 26e5029 | 2021-02-16 17:37:57 +0000 | [diff] [blame^] | 163 | groupsObj.forEach((group: GroupInstance):void => { |
Michael Lando | 5b59349 | 2018-07-29 16:13:45 +0300 | [diff] [blame] | 164 | groups.push(new GroupInstance(group)); |
| 165 | }); |
| 166 | } |
| 167 | |
| 168 | return groups; |
| 169 | } |
Arielk | 802bd2a | 2018-04-16 15:37:39 +0300 | [diff] [blame] | 170 | |
Arielk | 86a3752 | 2019-01-13 18:31:13 +0200 | [diff] [blame] | 171 | static initInterfaces(interfaces: Array<InterfaceModel>): Array<InterfaceModel> { |
Arielk | 802bd2a | 2018-04-16 15:37:39 +0300 | [diff] [blame] | 172 | |
Arielk | 86a3752 | 2019-01-13 18:31:13 +0200 | [diff] [blame] | 173 | return _.map(interfaces, (interf: InterfaceModel) => { |
| 174 | |
| 175 | return new InterfaceModel({ |
| 176 | type: interf.type, |
| 177 | uniqueId: interf.uniqueId, |
| 178 | operations: _.map(interf.operations, |
| 179 | (operation: OperationModel) => { |
| 180 | const newOperation = new OperationModel(operation); |
| 181 | newOperation.interfaceType = interf.type; |
| 182 | newOperation.interfaceId = interf.uniqueId; |
| 183 | |
| 184 | const {inputs, outputs} = operation; |
| 185 | if (inputs) { |
| 186 | newOperation.createInputsList(inputs.listToscaDataDefinition); |
| 187 | } |
| 188 | if (outputs) { |
| 189 | newOperation.createOutputsList(outputs.listToscaDataDefinition); |
| 190 | } |
| 191 | |
| 192 | return newOperation; |
| 193 | } |
| 194 | ) |
| 195 | }); |
| 196 | |
| 197 | }); |
| 198 | } |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame] | 199 | |
Arielk | 86a3752 | 2019-01-13 18:31:13 +0200 | [diff] [blame] | 200 | static initInterfaceOperations(interfaces: Array<InterfaceModel>): Array<OperationModel> { |
| 201 | |
| 202 | return _.reduce(interfaces, (acc, interf: InterfaceModel) => { |
Arielk | 802bd2a | 2018-04-16 15:37:39 +0300 | [diff] [blame] | 203 | |
| 204 | return acc.concat( |
| 205 | _.map(interf.operations, |
Arielk | 86a3752 | 2019-01-13 18:31:13 +0200 | [diff] [blame] | 206 | (operation: OperationModel) => { |
| 207 | const newOperation = new OperationModel(operation); |
| 208 | newOperation.interfaceType = interf.type; |
| 209 | newOperation.interfaceId = interf.uniqueId; |
| 210 | |
| 211 | const {inputs, outputs} = operation; |
Arielk | 802bd2a | 2018-04-16 15:37:39 +0300 | [diff] [blame] | 212 | if (inputs) { |
Arielk | 86a3752 | 2019-01-13 18:31:13 +0200 | [diff] [blame] | 213 | newOperation.createInputsList(inputs.listToscaDataDefinition); |
Arielk | 802bd2a | 2018-04-16 15:37:39 +0300 | [diff] [blame] | 214 | } |
| 215 | if (outputs) { |
Arielk | 86a3752 | 2019-01-13 18:31:13 +0200 | [diff] [blame] | 216 | newOperation.createOutputsList(outputs.listToscaDataDefinition); |
Arielk | 802bd2a | 2018-04-16 15:37:39 +0300 | [diff] [blame] | 217 | } |
Arielk | 86a3752 | 2019-01-13 18:31:13 +0200 | [diff] [blame] | 218 | |
| 219 | return newOperation; |
Arielk | 802bd2a | 2018-04-16 15:37:39 +0300 | [diff] [blame] | 220 | } |
| 221 | ) |
| 222 | ); |
| 223 | |
| 224 | }, []); |
| 225 | } |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame] | 226 | |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 227 | } |
| 228 | |