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";
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 initInterfaceOperations(interfaces: any): Array<OperationModel> {
144 return _.reduce(interfaces, (acc, interf: any) => {
147 _.map(interf.operations,
148 ({description, name, uniqueId, inputs, outputs}) => {
149 const operation = new OperationModel({
155 const inputParams = _.map(inputs.listToscaDataDefinition, (input:any) => {
156 return {paramName: input.name, paramId: input.inputId};
158 operation.createInputParamsList(inputParams);
161 const outputParams = _.map(outputs.listToscaDataDefinition, (output:any) => {
162 return {paramName: output.name, paramId: output.outputId};
164 operation.createOutputParamsList(outputParams);