blob: b4e184ab44be52be87e5e96ab5bc81feb3023e69 [file] [log] [blame]
Michael Landodd603392017-07-12 00:54:52 +03001/*-
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 Landoa5445102018-03-04 14:53:33 +020021import * as _ from "lodash";
ys969316a9fce2020-01-19 13:50:02 +020022import {Module, AttributeModel, ResourceInstance, PropertyModel, InputFEModel, OperationModel} from "../models";
ojasdubey4192e3c2019-03-18 14:15:03 +053023import {ComponentInstanceFactory} from "./component-instance-factory";
24import {InputBEModel, PropertyBEModel, RelationshipModel} from "app/models";
Michael Landoa5445102018-03-04 14:53:33 +020025import { PolicyInstance } from "app/models/graph/zones/policy-instance";
Michael Lando5b593492018-07-29 16:13:45 +030026import { GroupInstance } from "../models/graph/zones/group-instance";
ys969316a9fce2020-01-19 13:50:02 +020027import { InterfaceModel } from "../models/operation";
vasraz26e50292021-02-16 17:37:57 +000028import {AttributeBEModel} from "../models/attributes-outputs/attribute-be-model";
29import {OutputBEModel} from "../models/attributes-outputs/output-be-model";
Michael Landoed64b5e2017-06-09 03:19:04 +030030
31export class CommonUtils {
32
33 static initProperties(propertiesObj:Array<PropertyModel>, uniqueId?:string):Array<PropertyModel> {
34
35 let properties = new Array<PropertyModel>();
36 if (propertiesObj) {
vasraz26e50292021-02-16 17:37:57 +000037 propertiesObj.forEach((property:PropertyModel):void => {
Michael Landoed64b5e2017-06-09 03:19:04 +030038 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) {
vasraz26e50292021-02-16 17:37:57 +000051 attributesObj.forEach((attribute:AttributeModel):void => {
Michael Landoed64b5e2017-06-09 03:19:04 +030052 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) {
vasraz26e50292021-02-16 17:37:57 +000065 componentInstanceObj.forEach((instance:ResourceInstance):void => {
Michael Landoed64b5e2017-06-09 03:19:04 +030066 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) {
vasraz26e50292021-02-16 17:37:57 +000077 moduleArrayObj.forEach((module:Module):void => {
Michael Landoed64b5e2017-06-09 03:19:04 +030078 if (module.type === "org.openecomp.groups.VfModule") {
79 modules.push(new Module(module));
80 }
81 });
82 }
83 return modules;
84 };
85
Tal Gitelmaned7e1c32017-06-29 19:30:00 +030086 static initInputs(inputsObj: Array<InputBEModel>): Array<InputBEModel> {
Michael Landoed64b5e2017-06-09 03:19:04 +030087
Tal Gitelmaned7e1c32017-06-29 19:30:00 +030088 let inputs = new Array<InputBEModel>();
Michael Landoed64b5e2017-06-09 03:19:04 +030089
90 if(inputsObj) {
vasraz26e50292021-02-16 17:37:57 +000091 inputsObj.forEach((input: InputBEModel):void => {
Tal Gitelmaned7e1c32017-06-29 19:30:00 +030092 inputs.push(new InputBEModel(input));
Michael Landoed64b5e2017-06-09 03:19:04 +030093 })
94 }
95
96 return inputs;
97 }
98
vasraz26e50292021-02-16 17:37:57 +000099 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 Landoed64b5e2017-06-09 03:19:04 +0300112 static initBeProperties(propertiesObj: Array<PropertyBEModel>): Array<PropertyBEModel> {
113
114 let properties = new Array<PropertyBEModel>();
115
116 if (propertiesObj) {
vasraz26e50292021-02-16 17:37:57 +0000117 propertiesObj.forEach((property: PropertyBEModel): void => {
Michael Landoed64b5e2017-06-09 03:19:04 +0300118 properties.push(new PropertyBEModel(property));
119 })
120 }
121
122 return properties;
123 }
124
vasraz26e50292021-02-16 17:37:57 +0000125 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 Landoed64b5e2017-06-09 03:19:04 +0300138 static initComponentInstanceRelations = (componentInstanceRelationsObj:Array<RelationshipModel>):Array<RelationshipModel> => {
139 if (componentInstanceRelationsObj) {
140 let componentInstancesRelations: Array<RelationshipModel> = [];
vasraz26e50292021-02-16 17:37:57 +0000141 componentInstanceRelationsObj.forEach((instanceRelation:RelationshipModel):void => {
Michael Landoed64b5e2017-06-09 03:19:04 +0300142 componentInstancesRelations.push(new RelationshipModel(instanceRelation));
143 });
144 return componentInstancesRelations;
145 }
146 };
Michael Landoa5445102018-03-04 14:53:33 +0200147
148 static initPolicies = (policiesObj: Array<PolicyInstance>):Array<PolicyInstance> => {
149 let policies = new Array<PolicyInstance>();
150
151 if (policiesObj) {
vasraz26e50292021-02-16 17:37:57 +0000152 policiesObj.forEach((policy: PolicyInstance): void => {
Michael Landoa5445102018-03-04 14:53:33 +0200153 policies.push(new PolicyInstance(policy));
154 })
155 }
156
157 return policies;
158 }
Michael Lando5b593492018-07-29 16:13:45 +0300159 static initGroups = (groupsObj: Array<GroupInstance>):Array<GroupInstance> => {
160 let groups = new Array<GroupInstance>();
161
162 if(groupsObj) {
vasraz26e50292021-02-16 17:37:57 +0000163 groupsObj.forEach((group: GroupInstance):void => {
Michael Lando5b593492018-07-29 16:13:45 +0300164 groups.push(new GroupInstance(group));
165 });
166 }
167
168 return groups;
169 }
Arielk802bd2a2018-04-16 15:37:39 +0300170
Arielk86a37522019-01-13 18:31:13 +0200171 static initInterfaces(interfaces: Array<InterfaceModel>): Array<InterfaceModel> {
Arielk802bd2a2018-04-16 15:37:39 +0300172
Arielk86a37522019-01-13 18:31:13 +0200173 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 }
ys969316a9fce2020-01-19 13:50:02 +0200199
Arielk86a37522019-01-13 18:31:13 +0200200 static initInterfaceOperations(interfaces: Array<InterfaceModel>): Array<OperationModel> {
201
202 return _.reduce(interfaces, (acc, interf: InterfaceModel) => {
Arielk802bd2a2018-04-16 15:37:39 +0300203
204 return acc.concat(
205 _.map(interf.operations,
Arielk86a37522019-01-13 18:31:13 +0200206 (operation: OperationModel) => {
207 const newOperation = new OperationModel(operation);
208 newOperation.interfaceType = interf.type;
209 newOperation.interfaceId = interf.uniqueId;
210
211 const {inputs, outputs} = operation;
Arielk802bd2a2018-04-16 15:37:39 +0300212 if (inputs) {
Arielk86a37522019-01-13 18:31:13 +0200213 newOperation.createInputsList(inputs.listToscaDataDefinition);
Arielk802bd2a2018-04-16 15:37:39 +0300214 }
215 if (outputs) {
Arielk86a37522019-01-13 18:31:13 +0200216 newOperation.createOutputsList(outputs.listToscaDataDefinition);
Arielk802bd2a2018-04-16 15:37:39 +0300217 }
Arielk86a37522019-01-13 18:31:13 +0200218
219 return newOperation;
Arielk802bd2a2018-04-16 15:37:39 +0300220 }
221 )
222 );
223
224 }, []);
225 }
ys969316a9fce2020-01-19 13:50:02 +0200226
Michael Landoed64b5e2017-06-09 03:19:04 +0300227}
228