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"; |
Arielk | 802bd2a | 2018-04-16 15:37:39 +0300 | [diff] [blame] | 22 | import {Module, AttributeModel, ResourceInstance, PropertyModel, InputFEModel, OperationModel} from "../models"; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 23 | import {ComponentInstanceFactory} from "./component-instance-factory"; |
Tal Gitelman | ed7e1c3 | 2017-06-29 19:30:00 +0300 | [diff] [blame] | 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 | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 26 | |
| 27 | export class CommonUtils { |
| 28 | |
| 29 | static initProperties(propertiesObj:Array<PropertyModel>, uniqueId?:string):Array<PropertyModel> { |
| 30 | |
| 31 | let properties = new Array<PropertyModel>(); |
| 32 | if (propertiesObj) { |
| 33 | _.forEach(propertiesObj, (property:PropertyModel):void => { |
| 34 | if (uniqueId) { |
| 35 | property.readonly = property.parentUniqueId != uniqueId; |
| 36 | } |
| 37 | properties.push(new PropertyModel(property)); |
| 38 | }); |
| 39 | } |
| 40 | return properties; |
| 41 | }; |
| 42 | |
| 43 | static initAttributes(attributesObj:Array<AttributeModel>, uniqueId?:string):Array<AttributeModel> { |
| 44 | |
| 45 | let attributes = new Array<AttributeModel>(); |
| 46 | if (attributesObj) { |
| 47 | _.forEach(attributesObj, (attribute:AttributeModel):void => { |
| 48 | if (uniqueId) { |
| 49 | attribute.readonly = attribute.parentUniqueId != uniqueId; |
| 50 | } |
| 51 | attributes.push(new AttributeModel(attribute)); |
| 52 | }); |
| 53 | } |
| 54 | return attributes; |
| 55 | }; |
| 56 | |
| 57 | static initComponentInstances(componentInstanceObj:Array<ResourceInstance>):Array<ResourceInstance> { |
| 58 | |
| 59 | let componentInstances = new Array<ResourceInstance>(); |
| 60 | if (componentInstanceObj) { |
| 61 | _.forEach(componentInstanceObj, (instance:ResourceInstance):void => { |
| 62 | componentInstances.push(ComponentInstanceFactory.createComponentInstance(instance)); |
| 63 | }); |
| 64 | } |
| 65 | return componentInstances; |
| 66 | }; |
| 67 | |
| 68 | static initModules(moduleArrayObj:Array<Module>):Array<Module> { |
| 69 | |
| 70 | let modules = new Array<Module>(); |
| 71 | |
| 72 | if (moduleArrayObj) { |
| 73 | _.forEach(moduleArrayObj, (module:Module):void => { |
| 74 | if (module.type === "org.openecomp.groups.VfModule") { |
| 75 | modules.push(new Module(module)); |
| 76 | } |
| 77 | }); |
| 78 | } |
| 79 | return modules; |
| 80 | }; |
| 81 | |
Tal Gitelman | ed7e1c3 | 2017-06-29 19:30:00 +0300 | [diff] [blame] | 82 | static initInputs(inputsObj: Array<InputBEModel>): Array<InputBEModel> { |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 83 | |
Tal Gitelman | ed7e1c3 | 2017-06-29 19:30:00 +0300 | [diff] [blame] | 84 | let inputs = new Array<InputBEModel>(); |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 85 | |
| 86 | if(inputsObj) { |
Tal Gitelman | ed7e1c3 | 2017-06-29 19:30:00 +0300 | [diff] [blame] | 87 | _.forEach(inputsObj, (input: InputBEModel):void => { |
| 88 | inputs.push(new InputBEModel(input)); |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 89 | }) |
| 90 | } |
| 91 | |
| 92 | return inputs; |
| 93 | } |
| 94 | |
| 95 | static initBeProperties(propertiesObj: Array<PropertyBEModel>): Array<PropertyBEModel> { |
| 96 | |
| 97 | let properties = new Array<PropertyBEModel>(); |
| 98 | |
| 99 | if (propertiesObj) { |
| 100 | _.forEach(propertiesObj, (property: PropertyBEModel): void => { |
| 101 | properties.push(new PropertyBEModel(property)); |
| 102 | }) |
| 103 | } |
| 104 | |
| 105 | return properties; |
| 106 | } |
| 107 | |
| 108 | static initComponentInstanceRelations = (componentInstanceRelationsObj:Array<RelationshipModel>):Array<RelationshipModel> => { |
| 109 | if (componentInstanceRelationsObj) { |
| 110 | let componentInstancesRelations: Array<RelationshipModel> = []; |
| 111 | _.forEach(componentInstanceRelationsObj, (instanceRelation:RelationshipModel):void => { |
| 112 | componentInstancesRelations.push(new RelationshipModel(instanceRelation)); |
| 113 | }); |
| 114 | return componentInstancesRelations; |
| 115 | } |
| 116 | }; |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 117 | |
| 118 | static initPolicies = (policiesObj: Array<PolicyInstance>):Array<PolicyInstance> => { |
| 119 | let policies = new Array<PolicyInstance>(); |
| 120 | |
| 121 | if (policiesObj) { |
| 122 | _.forEach(policiesObj, (policy: PolicyInstance): void => { |
| 123 | policies.push(new PolicyInstance(policy)); |
| 124 | }) |
| 125 | } |
| 126 | |
| 127 | return policies; |
| 128 | } |
Arielk | 802bd2a | 2018-04-16 15:37:39 +0300 | [diff] [blame] | 129 | |
| 130 | static initInterfaceOperations(interfaces: any): Array<OperationModel> { |
| 131 | |
| 132 | return _.reduce(interfaces, (acc, interf: any) => { |
| 133 | |
| 134 | return acc.concat( |
| 135 | _.map(interf.operations, |
| 136 | ({description, name, uniqueId, inputs, outputs}) => { |
| 137 | const operation = new OperationModel({ |
| 138 | description, |
| 139 | operationType: name, |
| 140 | uniqueId |
| 141 | }); |
| 142 | if (inputs) { |
| 143 | const inputParams = _.map(inputs.listToscaDataDefinition, (input:any) => { |
| 144 | return {paramName: input.name, paramId: input.inputId}; |
| 145 | }); |
| 146 | operation.createInputParamsList(inputParams); |
| 147 | } |
| 148 | if (outputs) { |
| 149 | const outputParams = _.map(outputs.listToscaDataDefinition, (output:any) => { |
| 150 | return {paramName: output.name, paramId: output.outputId}; |
| 151 | }); |
| 152 | operation.createOutputParamsList(outputParams); |
| 153 | } |
| 154 | return operation; |
| 155 | } |
| 156 | ) |
| 157 | ); |
| 158 | |
| 159 | }, []); |
| 160 | } |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 161 | } |
| 162 | |