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, OperationModel} 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";
26 import { GroupInstance } from "../models/graph/zones/group-instance";
27 import { InterfaceModel } from "../models/operation";
29 export class CommonUtils {
31 static initProperties(propertiesObj:Array<PropertyModel>, uniqueId?:string):Array<PropertyModel> {
33 let properties = new Array<PropertyModel>();
35 _.forEach(propertiesObj, (property:PropertyModel):void => {
37 property.readonly = property.parentUniqueId != uniqueId;
39 properties.push(new PropertyModel(property));
45 static initAttributes(attributesObj:Array<AttributeModel>, uniqueId?:string):Array<AttributeModel> {
47 let attributes = new Array<AttributeModel>();
49 _.forEach(attributesObj, (attribute:AttributeModel):void => {
51 attribute.readonly = attribute.parentUniqueId != uniqueId;
53 attributes.push(new AttributeModel(attribute));
59 static initComponentInstances(componentInstanceObj:Array<ResourceInstance>):Array<ResourceInstance> {
61 let componentInstances = new Array<ResourceInstance>();
62 if (componentInstanceObj) {
63 _.forEach(componentInstanceObj, (instance:ResourceInstance):void => {
64 componentInstances.push(ComponentInstanceFactory.createComponentInstance(instance));
67 return componentInstances;
70 static initModules(moduleArrayObj:Array<Module>):Array<Module> {
72 let modules = new Array<Module>();
75 _.forEach(moduleArrayObj, (module:Module):void => {
76 if (module.type === "org.openecomp.groups.VfModule") {
77 modules.push(new Module(module));
84 static initInputs(inputsObj: Array<InputBEModel>): Array<InputBEModel> {
86 let inputs = new Array<InputBEModel>();
89 _.forEach(inputsObj, (input: InputBEModel):void => {
90 inputs.push(new InputBEModel(input));
97 static initBeProperties(propertiesObj: Array<PropertyBEModel>): Array<PropertyBEModel> {
99 let properties = new Array<PropertyBEModel>();
102 _.forEach(propertiesObj, (property: PropertyBEModel): void => {
103 properties.push(new PropertyBEModel(property));
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));
116 return componentInstancesRelations;
120 static initPolicies = (policiesObj: Array<PolicyInstance>):Array<PolicyInstance> => {
121 let policies = new Array<PolicyInstance>();
124 _.forEach(policiesObj, (policy: PolicyInstance): void => {
125 policies.push(new PolicyInstance(policy));
131 static initGroups = (groupsObj: Array<GroupInstance>):Array<GroupInstance> => {
132 let groups = new Array<GroupInstance>();
135 _.forEach(groupsObj, (group: GroupInstance):void => {
136 groups.push(new GroupInstance(group));
143 static initInterfaces(interfaces: Array<InterfaceModel>): Array<InterfaceModel> {
145 return _.map(interfaces, (interf: InterfaceModel) => {
147 return new InterfaceModel({
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;
156 const {inputs, outputs} = operation;
158 newOperation.createInputsList(inputs.listToscaDataDefinition);
161 newOperation.createOutputsList(outputs.listToscaDataDefinition);
172 static initInterfaceOperations(interfaces: Array<InterfaceModel>): Array<OperationModel> {
174 return _.reduce(interfaces, (acc, interf: InterfaceModel) => {
177 _.map(interf.operations,
178 (operation: OperationModel) => {
179 const newOperation = new OperationModel(operation);
180 newOperation.interfaceType = interf.type;
181 newOperation.interfaceId = interf.uniqueId;
183 const {inputs, outputs} = operation;
185 newOperation.createInputsList(inputs.listToscaDataDefinition);
188 newOperation.createOutputsList(outputs.listToscaDataDefinition);