2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 import * as _ from "lodash";
22 import {Module, AttributeModel, ResourceInstance, PropertyModel, InputFEModel} from "../models";
23 import {ComponentInstanceFactory} from "./component-instance-factory";
24 import {InputBEModel, PropertyBEModel, RelationshipModel} from "app/models";
25 import { PolicyInstance } from "app/models/graph/zones/policy-instance";
27 export class CommonUtils {
29 static initProperties(propertiesObj:Array<PropertyModel>, uniqueId?:string):Array<PropertyModel> {
31 let properties = new Array<PropertyModel>();
33 _.forEach(propertiesObj, (property:PropertyModel):void => {
35 property.readonly = property.parentUniqueId != uniqueId;
37 properties.push(new PropertyModel(property));
43 static initAttributes(attributesObj:Array<AttributeModel>, uniqueId?:string):Array<AttributeModel> {
45 let attributes = new Array<AttributeModel>();
47 _.forEach(attributesObj, (attribute:AttributeModel):void => {
49 attribute.readonly = attribute.parentUniqueId != uniqueId;
51 attributes.push(new AttributeModel(attribute));
57 static initComponentInstances(componentInstanceObj:Array<ResourceInstance>):Array<ResourceInstance> {
59 let componentInstances = new Array<ResourceInstance>();
60 if (componentInstanceObj) {
61 _.forEach(componentInstanceObj, (instance:ResourceInstance):void => {
62 componentInstances.push(ComponentInstanceFactory.createComponentInstance(instance));
65 return componentInstances;
68 static initModules(moduleArrayObj:Array<Module>):Array<Module> {
70 let modules = new Array<Module>();
73 _.forEach(moduleArrayObj, (module:Module):void => {
74 if (module.type === "org.openecomp.groups.VfModule") {
75 modules.push(new Module(module));
82 static initInputs(inputsObj: Array<InputBEModel>): Array<InputBEModel> {
84 let inputs = new Array<InputBEModel>();
87 _.forEach(inputsObj, (input: InputBEModel):void => {
88 inputs.push(new InputBEModel(input));
95 static initBeProperties(propertiesObj: Array<PropertyBEModel>): Array<PropertyBEModel> {
97 let properties = new Array<PropertyBEModel>();
100 _.forEach(propertiesObj, (property: PropertyBEModel): void => {
101 properties.push(new PropertyBEModel(property));
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));
114 return componentInstancesRelations;
118 static initPolicies = (policiesObj: Array<PolicyInstance>):Array<PolicyInstance> => {
119 let policies = new Array<PolicyInstance>();
122 _.forEach(policiesObj, (policy: PolicyInstance): void => {
123 policies.push(new PolicyInstance(policy));