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