blob: 171903435454f8de49725525696399df9ad36de4 [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 Landoed64b5e2017-06-09 03:19:04 +030021import {Module, AttributeModel, ResourceInstance, PropertyModel, InputFEModel} from "../models";
22import {ComponentInstanceFactory} from "./component-instance-factory";
Tal Gitelmaned7e1c32017-06-29 19:30:00 +030023import {InputBEModel, PropertyBEModel, RelationshipModel} from "app/models";
Michael Landoed64b5e2017-06-09 03:19:04 +030024
25export class CommonUtils {
26
27 static initProperties(propertiesObj:Array<PropertyModel>, uniqueId?:string):Array<PropertyModel> {
28
29 let properties = new Array<PropertyModel>();
30 if (propertiesObj) {
31 _.forEach(propertiesObj, (property:PropertyModel):void => {
32 if (uniqueId) {
33 property.readonly = property.parentUniqueId != uniqueId;
34 }
35 properties.push(new PropertyModel(property));
36 });
37 }
38 return properties;
39 };
40
41 static initAttributes(attributesObj:Array<AttributeModel>, uniqueId?:string):Array<AttributeModel> {
42
43 let attributes = new Array<AttributeModel>();
44 if (attributesObj) {
45 _.forEach(attributesObj, (attribute:AttributeModel):void => {
46 if (uniqueId) {
47 attribute.readonly = attribute.parentUniqueId != uniqueId;
48 }
49 attributes.push(new AttributeModel(attribute));
50 });
51 }
52 return attributes;
53 };
54
55 static initComponentInstances(componentInstanceObj:Array<ResourceInstance>):Array<ResourceInstance> {
56
57 let componentInstances = new Array<ResourceInstance>();
58 if (componentInstanceObj) {
59 _.forEach(componentInstanceObj, (instance:ResourceInstance):void => {
60 componentInstances.push(ComponentInstanceFactory.createComponentInstance(instance));
61 });
62 }
63 return componentInstances;
64 };
65
66 static initModules(moduleArrayObj:Array<Module>):Array<Module> {
67
68 let modules = new Array<Module>();
69
70 if (moduleArrayObj) {
71 _.forEach(moduleArrayObj, (module:Module):void => {
72 if (module.type === "org.openecomp.groups.VfModule") {
73 modules.push(new Module(module));
74 }
75 });
76 }
77 return modules;
78 };
79
Tal Gitelmaned7e1c32017-06-29 19:30:00 +030080 static initInputs(inputsObj: Array<InputBEModel>): Array<InputBEModel> {
Michael Landoed64b5e2017-06-09 03:19:04 +030081
Tal Gitelmaned7e1c32017-06-29 19:30:00 +030082 let inputs = new Array<InputBEModel>();
Michael Landoed64b5e2017-06-09 03:19:04 +030083
84 if(inputsObj) {
Tal Gitelmaned7e1c32017-06-29 19:30:00 +030085 _.forEach(inputsObj, (input: InputBEModel):void => {
86 inputs.push(new InputBEModel(input));
Michael Landoed64b5e2017-06-09 03:19:04 +030087 })
88 }
89
90 return inputs;
91 }
92
93 static initBeProperties(propertiesObj: Array<PropertyBEModel>): Array<PropertyBEModel> {
94
95 let properties = new Array<PropertyBEModel>();
96
97 if (propertiesObj) {
98 _.forEach(propertiesObj, (property: PropertyBEModel): void => {
99 properties.push(new PropertyBEModel(property));
100 })
101 }
102
103 return properties;
104 }
105
106 static initComponentInstanceRelations = (componentInstanceRelationsObj:Array<RelationshipModel>):Array<RelationshipModel> => {
107 if (componentInstanceRelationsObj) {
108 let componentInstancesRelations: Array<RelationshipModel> = [];
109 _.forEach(componentInstanceRelationsObj, (instanceRelation:RelationshipModel):void => {
110 componentInstancesRelations.push(new RelationshipModel(instanceRelation));
111 });
112 return componentInstancesRelations;
113 }
114 };
115}
116