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"; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 28 | |
| 29 | export class CommonUtils { |
| 30 | |
| 31 | static initProperties(propertiesObj:Array<PropertyModel>, uniqueId?:string):Array<PropertyModel> { |
| 32 | |
| 33 | let properties = new Array<PropertyModel>(); |
| 34 | if (propertiesObj) { |
| 35 | _.forEach(propertiesObj, (property:PropertyModel):void => { |
| 36 | if (uniqueId) { |
| 37 | property.readonly = property.parentUniqueId != uniqueId; |
| 38 | } |
| 39 | properties.push(new PropertyModel(property)); |
| 40 | }); |
| 41 | } |
| 42 | return properties; |
| 43 | }; |
| 44 | |
| 45 | static initAttributes(attributesObj:Array<AttributeModel>, uniqueId?:string):Array<AttributeModel> { |
| 46 | |
| 47 | let attributes = new Array<AttributeModel>(); |
| 48 | if (attributesObj) { |
| 49 | _.forEach(attributesObj, (attribute:AttributeModel):void => { |
| 50 | if (uniqueId) { |
| 51 | attribute.readonly = attribute.parentUniqueId != uniqueId; |
| 52 | } |
| 53 | attributes.push(new AttributeModel(attribute)); |
| 54 | }); |
| 55 | } |
| 56 | return attributes; |
| 57 | }; |
| 58 | |
| 59 | static initComponentInstances(componentInstanceObj:Array<ResourceInstance>):Array<ResourceInstance> { |
| 60 | |
| 61 | let componentInstances = new Array<ResourceInstance>(); |
| 62 | if (componentInstanceObj) { |
| 63 | _.forEach(componentInstanceObj, (instance:ResourceInstance):void => { |
| 64 | componentInstances.push(ComponentInstanceFactory.createComponentInstance(instance)); |
| 65 | }); |
| 66 | } |
| 67 | return componentInstances; |
| 68 | }; |
| 69 | |
| 70 | static initModules(moduleArrayObj:Array<Module>):Array<Module> { |
| 71 | |
| 72 | let modules = new Array<Module>(); |
| 73 | |
| 74 | if (moduleArrayObj) { |
| 75 | _.forEach(moduleArrayObj, (module:Module):void => { |
| 76 | if (module.type === "org.openecomp.groups.VfModule") { |
| 77 | modules.push(new Module(module)); |
| 78 | } |
| 79 | }); |
| 80 | } |
| 81 | return modules; |
| 82 | }; |
| 83 | |
Tal Gitelman | ed7e1c3 | 2017-06-29 19:30:00 +0300 | [diff] [blame] | 84 | static initInputs(inputsObj: Array<InputBEModel>): Array<InputBEModel> { |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 85 | |
Tal Gitelman | ed7e1c3 | 2017-06-29 19:30:00 +0300 | [diff] [blame] | 86 | let inputs = new Array<InputBEModel>(); |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 87 | |
| 88 | if(inputsObj) { |
Tal Gitelman | ed7e1c3 | 2017-06-29 19:30:00 +0300 | [diff] [blame] | 89 | _.forEach(inputsObj, (input: InputBEModel):void => { |
| 90 | inputs.push(new InputBEModel(input)); |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 91 | }) |
| 92 | } |
| 93 | |
| 94 | return inputs; |
| 95 | } |
| 96 | |
| 97 | static initBeProperties(propertiesObj: Array<PropertyBEModel>): Array<PropertyBEModel> { |
| 98 | |
| 99 | let properties = new Array<PropertyBEModel>(); |
| 100 | |
| 101 | if (propertiesObj) { |
| 102 | _.forEach(propertiesObj, (property: PropertyBEModel): void => { |
| 103 | properties.push(new PropertyBEModel(property)); |
| 104 | }) |
| 105 | } |
| 106 | |
| 107 | return properties; |
| 108 | } |
| 109 | |
| 110 | static initComponentInstanceRelations = (componentInstanceRelationsObj:Array<RelationshipModel>):Array<RelationshipModel> => { |
| 111 | if (componentInstanceRelationsObj) { |
| 112 | let componentInstancesRelations: Array<RelationshipModel> = []; |
| 113 | _.forEach(componentInstanceRelationsObj, (instanceRelation:RelationshipModel):void => { |
| 114 | componentInstancesRelations.push(new RelationshipModel(instanceRelation)); |
| 115 | }); |
| 116 | return componentInstancesRelations; |
| 117 | } |
| 118 | }; |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 119 | |
| 120 | static initPolicies = (policiesObj: Array<PolicyInstance>):Array<PolicyInstance> => { |
| 121 | let policies = new Array<PolicyInstance>(); |
| 122 | |
| 123 | if (policiesObj) { |
| 124 | _.forEach(policiesObj, (policy: PolicyInstance): void => { |
| 125 | policies.push(new PolicyInstance(policy)); |
| 126 | }) |
| 127 | } |
| 128 | |
| 129 | return policies; |
| 130 | } |
Michael Lando | 5b59349 | 2018-07-29 16:13:45 +0300 | [diff] [blame] | 131 | static initGroups = (groupsObj: Array<GroupInstance>):Array<GroupInstance> => { |
| 132 | let groups = new Array<GroupInstance>(); |
| 133 | |
| 134 | if(groupsObj) { |
| 135 | _.forEach(groupsObj, (group: GroupInstance):void => { |
| 136 | groups.push(new GroupInstance(group)); |
| 137 | }); |
| 138 | } |
| 139 | |
| 140 | return groups; |
| 141 | } |
Arielk | 802bd2a | 2018-04-16 15:37:39 +0300 | [diff] [blame] | 142 | |
Arielk | 86a3752 | 2019-01-13 18:31:13 +0200 | [diff] [blame] | 143 | static initInterfaces(interfaces: Array<InterfaceModel>): Array<InterfaceModel> { |
Arielk | 802bd2a | 2018-04-16 15:37:39 +0300 | [diff] [blame] | 144 | |
Arielk | 86a3752 | 2019-01-13 18:31:13 +0200 | [diff] [blame] | 145 | return _.map(interfaces, (interf: InterfaceModel) => { |
| 146 | |
| 147 | return new InterfaceModel({ |
| 148 | type: interf.type, |
| 149 | uniqueId: interf.uniqueId, |
| 150 | operations: _.map(interf.operations, |
| 151 | (operation: OperationModel) => { |
| 152 | const newOperation = new OperationModel(operation); |
| 153 | newOperation.interfaceType = interf.type; |
| 154 | newOperation.interfaceId = interf.uniqueId; |
| 155 | |
| 156 | const {inputs, outputs} = operation; |
| 157 | if (inputs) { |
| 158 | newOperation.createInputsList(inputs.listToscaDataDefinition); |
| 159 | } |
| 160 | if (outputs) { |
| 161 | newOperation.createOutputsList(outputs.listToscaDataDefinition); |
| 162 | } |
| 163 | |
| 164 | return newOperation; |
| 165 | } |
| 166 | ) |
| 167 | }); |
| 168 | |
| 169 | }); |
| 170 | } |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame] | 171 | |
Arielk | 86a3752 | 2019-01-13 18:31:13 +0200 | [diff] [blame] | 172 | static initInterfaceOperations(interfaces: Array<InterfaceModel>): Array<OperationModel> { |
| 173 | |
| 174 | return _.reduce(interfaces, (acc, interf: InterfaceModel) => { |
Arielk | 802bd2a | 2018-04-16 15:37:39 +0300 | [diff] [blame] | 175 | |
| 176 | return acc.concat( |
| 177 | _.map(interf.operations, |
Arielk | 86a3752 | 2019-01-13 18:31:13 +0200 | [diff] [blame] | 178 | (operation: OperationModel) => { |
| 179 | const newOperation = new OperationModel(operation); |
| 180 | newOperation.interfaceType = interf.type; |
| 181 | newOperation.interfaceId = interf.uniqueId; |
| 182 | |
| 183 | const {inputs, outputs} = operation; |
Arielk | 802bd2a | 2018-04-16 15:37:39 +0300 | [diff] [blame] | 184 | if (inputs) { |
Arielk | 86a3752 | 2019-01-13 18:31:13 +0200 | [diff] [blame] | 185 | newOperation.createInputsList(inputs.listToscaDataDefinition); |
Arielk | 802bd2a | 2018-04-16 15:37:39 +0300 | [diff] [blame] | 186 | } |
| 187 | if (outputs) { |
Arielk | 86a3752 | 2019-01-13 18:31:13 +0200 | [diff] [blame] | 188 | newOperation.createOutputsList(outputs.listToscaDataDefinition); |
Arielk | 802bd2a | 2018-04-16 15:37:39 +0300 | [diff] [blame] | 189 | } |
Arielk | 86a3752 | 2019-01-13 18:31:13 +0200 | [diff] [blame] | 190 | |
| 191 | return newOperation; |
Arielk | 802bd2a | 2018-04-16 15:37:39 +0300 | [diff] [blame] | 192 | } |
| 193 | ) |
| 194 | ); |
| 195 | |
| 196 | }, []); |
| 197 | } |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame] | 198 | |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 199 | } |
| 200 | |