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";
28 import {AttributeBEModel} from "../models/attributes-outputs/attribute-be-model";
29 import {OutputBEModel} from "../models/attributes-outputs/output-be-model";
31 export class CommonUtils {
33 static initProperties(propertiesObj:Array<PropertyModel>, uniqueId?:string):Array<PropertyModel> {
35 let properties = new Array<PropertyModel>();
37 propertiesObj.forEach((property:PropertyModel):void => {
39 property.readonly = property.parentUniqueId != uniqueId;
41 properties.push(new PropertyModel(property));
47 static initAttributes(attributesObj:Array<AttributeModel>, uniqueId?:string):Array<AttributeModel> {
49 let attributes = new Array<AttributeModel>();
51 attributesObj.forEach((attribute:AttributeModel):void => {
53 attribute.readonly = attribute.parentUniqueId != uniqueId;
55 attributes.push(new AttributeModel(attribute));
61 static initComponentInstances(componentInstanceObj:Array<ResourceInstance>):Array<ResourceInstance> {
63 let componentInstances = new Array<ResourceInstance>();
64 if (componentInstanceObj) {
65 componentInstanceObj.forEach((instance:ResourceInstance):void => {
66 componentInstances.push(ComponentInstanceFactory.createComponentInstance(instance));
69 return componentInstances;
72 static initModules(moduleArrayObj:Array<Module>):Array<Module> {
74 let modules = new Array<Module>();
77 moduleArrayObj.forEach((module:Module):void => {
78 if (module.type === "org.openecomp.groups.VfModule") {
79 modules.push(new Module(module));
86 static initInputs(inputsObj: Array<InputBEModel>): Array<InputBEModel> {
88 let inputs = new Array<InputBEModel>();
91 inputsObj.forEach((input: InputBEModel):void => {
92 inputs.push(new InputBEModel(input));
99 static initOutputs(outputsObj: Array<OutputBEModel>): Array<OutputBEModel> {
101 let outputs = new Array<OutputBEModel>();
104 outputsObj.forEach((output: OutputBEModel):void => {
105 outputs.push(new OutputBEModel(output));
112 static initBeProperties(propertiesObj: Array<PropertyBEModel>): Array<PropertyBEModel> {
114 let properties = new Array<PropertyBEModel>();
117 propertiesObj.forEach((property: PropertyBEModel): void => {
118 properties.push(new PropertyBEModel(property));
125 static initBeAttributes(attributesObj: Array<AttributeBEModel>): Array<AttributeBEModel> {
127 let attributes = new Array<AttributeBEModel>();
130 attributesObj.forEach((attribute: AttributeBEModel): void => {
131 attributes.push(new AttributeBEModel(attribute));
138 static initComponentInstanceRelations = (componentInstanceRelationsObj:Array<RelationshipModel>):Array<RelationshipModel> => {
139 if (componentInstanceRelationsObj) {
140 let componentInstancesRelations: Array<RelationshipModel> = [];
141 componentInstanceRelationsObj.forEach((instanceRelation:RelationshipModel):void => {
142 componentInstancesRelations.push(new RelationshipModel(instanceRelation));
144 return componentInstancesRelations;
148 static initPolicies = (policiesObj: Array<PolicyInstance>):Array<PolicyInstance> => {
149 let policies = new Array<PolicyInstance>();
152 policiesObj.forEach((policy: PolicyInstance): void => {
153 policies.push(new PolicyInstance(policy));
159 static initGroups = (groupsObj: Array<GroupInstance>):Array<GroupInstance> => {
160 let groups = new Array<GroupInstance>();
163 groupsObj.forEach((group: GroupInstance):void => {
164 groups.push(new GroupInstance(group));
171 static initInterfaces(interfaces: Array<InterfaceModel>): Array<InterfaceModel> {
173 return _.map(interfaces, (interf: InterfaceModel) => {
175 return new InterfaceModel({
177 uniqueId: interf.uniqueId,
178 operations: _.map(interf.operations,
179 (operation: OperationModel) => {
180 const newOperation = new OperationModel(operation);
181 newOperation.interfaceType = interf.type;
182 newOperation.interfaceId = interf.uniqueId;
184 const {inputs, outputs, milestones} = operation;
186 newOperation.createInputsList(inputs.listToscaDataDefinition);
189 newOperation.createOutputsList(outputs.listToscaDataDefinition);
192 newOperation.milestones = milestones;
203 static initInterfaceOperations(interfaces: Array<InterfaceModel>): Array<OperationModel> {
205 return _.reduce(interfaces, (acc, interf: InterfaceModel) => {
208 _.map(interf.operations,
209 (operation: OperationModel) => {
210 const newOperation = new OperationModel(operation);
211 newOperation.interfaceType = interf.type;
212 newOperation.interfaceId = interf.uniqueId;
214 const {inputs, outputs} = operation;
216 newOperation.createInputsList(inputs.listToscaDataDefinition);
219 newOperation.createOutputsList(outputs.listToscaDataDefinition);