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 { ComponentInstanceFactory } from "./component-instance-factory";
23 import { Module, AttributeModel, ResourceInstance, PropertyModel, InputFEModel, InterfaceModel, OperationModel } from "../models";
24 import { InputBEModel, PropertyBEModel, RelationshipModel } from "app/models";
25 import { PolicyInstance } from "app/models/graph/zones/policy-instance";
26 import { GroupInstance } from "../models/graph/zones/group-instance";
28 export class CommonUtils {
30 static initProperties(propertiesObj:Array<PropertyModel>, uniqueId?:string):Array<PropertyModel> {
32 let properties = new Array<PropertyModel>();
34 _.forEach(propertiesObj, (property:PropertyModel):void => {
36 property.readonly = property.parentUniqueId != uniqueId;
38 properties.push(new PropertyModel(property));
44 static initAttributes(attributesObj:Array<AttributeModel>, uniqueId?:string):Array<AttributeModel> {
46 let attributes = new Array<AttributeModel>();
48 _.forEach(attributesObj, (attribute:AttributeModel):void => {
50 attribute.readonly = attribute.parentUniqueId != uniqueId;
52 attributes.push(new AttributeModel(attribute));
58 static initComponentInstances(componentInstanceObj:Array<ResourceInstance>):Array<ResourceInstance> {
60 let componentInstances = new Array<ResourceInstance>();
61 if (componentInstanceObj) {
62 _.forEach(componentInstanceObj, (instance:ResourceInstance):void => {
63 componentInstances.push(ComponentInstanceFactory.createComponentInstance(instance));
66 return componentInstances;
69 static initModules(moduleArrayObj:Array<Module>):Array<Module> {
71 let modules = new Array<Module>();
74 _.forEach(moduleArrayObj, (module:Module):void => {
75 if (module.type === "org.openecomp.groups.VfModule") {
76 modules.push(new Module(module));
83 static initInputs(inputsObj: Array<InputBEModel>): Array<InputBEModel> {
85 let inputs = new Array<InputBEModel>();
88 _.forEach(inputsObj, (input: InputBEModel):void => {
89 inputs.push(new InputBEModel(input));
96 static initBeProperties(propertiesObj: Array<PropertyBEModel>): Array<PropertyBEModel> {
98 let properties = new Array<PropertyBEModel>();
101 _.forEach(propertiesObj, (property: PropertyBEModel): void => {
102 properties.push(new PropertyBEModel(property));
109 static initComponentInstanceRelations = (componentInstanceRelationsObj:Array<RelationshipModel>):Array<RelationshipModel> => {
110 if (componentInstanceRelationsObj) {
111 let componentInstancesRelations: Array<RelationshipModel> = [];
112 _.forEach(componentInstanceRelationsObj, (instanceRelation:RelationshipModel):void => {
113 componentInstancesRelations.push(new RelationshipModel(instanceRelation));
115 return componentInstancesRelations;
119 static initPolicies = (policiesObj: Array<PolicyInstance>):Array<PolicyInstance> => {
120 let policies = new Array<PolicyInstance>();
123 _.forEach(policiesObj, (policy: PolicyInstance): void => {
124 policies.push(new PolicyInstance(policy));
130 static initGroups = (groupsObj: Array<GroupInstance>):Array<GroupInstance> => {
131 let groups = new Array<GroupInstance>();
134 _.forEach(groupsObj, (group: GroupInstance):void => {
135 groups.push(new GroupInstance(group));
142 static initInterfaces(interfaces: Array<InterfaceModel>): Array<InterfaceModel> {
144 return _.map(interfaces, (interf: InterfaceModel) => {
146 return new InterfaceModel({
148 uniqueId: interf.uniqueId,
149 operations: _.map(interf.operations,
150 (operation: OperationModel) => {
151 const newOperation = new OperationModel(operation);
152 newOperation.interfaceType = interf.type;
153 newOperation.interfaceId = interf.uniqueId;
155 const {inputs, outputs} = operation;
157 newOperation.createInputsList(inputs.listToscaDataDefinition);
160 newOperation.createOutputsList(outputs.listToscaDataDefinition);
171 static initInterfaceOperations(interfaces: Array<InterfaceModel>): Array<OperationModel> {
173 return _.reduce(interfaces, (acc, interf: InterfaceModel) => {
176 _.map(interf.operations,
177 (operation: OperationModel) => {
178 const newOperation = new OperationModel(operation);
179 newOperation.interfaceType = interf.type;
180 newOperation.interfaceId = interf.uniqueId;
182 const {inputs, outputs} = operation;
184 newOperation.createInputsList(inputs.listToscaDataDefinition);
187 newOperation.createOutputsList(outputs.listToscaDataDefinition);