blob: eadb92bd4fa2b1c1f7eb000b0d4e22d0bfd23de0 [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";
Michael Landoed64b5e2017-06-09 03:19:04 +030028
29export 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 Gitelmaned7e1c32017-06-29 19:30:00 +030084 static initInputs(inputsObj: Array<InputBEModel>): Array<InputBEModel> {
Michael Landoed64b5e2017-06-09 03:19:04 +030085
Tal Gitelmaned7e1c32017-06-29 19:30:00 +030086 let inputs = new Array<InputBEModel>();
Michael Landoed64b5e2017-06-09 03:19:04 +030087
88 if(inputsObj) {
Tal Gitelmaned7e1c32017-06-29 19:30:00 +030089 _.forEach(inputsObj, (input: InputBEModel):void => {
90 inputs.push(new InputBEModel(input));
Michael Landoed64b5e2017-06-09 03:19:04 +030091 })
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 Landoa5445102018-03-04 14:53:33 +0200119
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 Lando5b593492018-07-29 16:13:45 +0300131 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 }
Arielk802bd2a2018-04-16 15:37:39 +0300142
Arielk86a37522019-01-13 18:31:13 +0200143 static initInterfaces(interfaces: Array<InterfaceModel>): Array<InterfaceModel> {
Arielk802bd2a2018-04-16 15:37:39 +0300144
Arielk86a37522019-01-13 18:31:13 +0200145 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 }
ys969316a9fce2020-01-19 13:50:02 +0200171
Arielk86a37522019-01-13 18:31:13 +0200172 static initInterfaceOperations(interfaces: Array<InterfaceModel>): Array<OperationModel> {
173
174 return _.reduce(interfaces, (acc, interf: InterfaceModel) => {
Arielk802bd2a2018-04-16 15:37:39 +0300175
176 return acc.concat(
177 _.map(interf.operations,
Arielk86a37522019-01-13 18:31:13 +0200178 (operation: OperationModel) => {
179 const newOperation = new OperationModel(operation);
180 newOperation.interfaceType = interf.type;
181 newOperation.interfaceId = interf.uniqueId;
182
183 const {inputs, outputs} = operation;
Arielk802bd2a2018-04-16 15:37:39 +0300184 if (inputs) {
Arielk86a37522019-01-13 18:31:13 +0200185 newOperation.createInputsList(inputs.listToscaDataDefinition);
Arielk802bd2a2018-04-16 15:37:39 +0300186 }
187 if (outputs) {
Arielk86a37522019-01-13 18:31:13 +0200188 newOperation.createOutputsList(outputs.listToscaDataDefinition);
Arielk802bd2a2018-04-16 15:37:39 +0300189 }
Arielk86a37522019-01-13 18:31:13 +0200190
191 return newOperation;
Arielk802bd2a2018-04-16 15:37:39 +0300192 }
193 )
194 );
195
196 }, []);
197 }
ys969316a9fce2020-01-19 13:50:02 +0200198
Michael Landoed64b5e2017-06-09 03:19:04 +0300199}
200