2 * Copyright (c) 2017 ZTE Corporation.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * and the Apache License 2.0 which both accompany this distribution,
6 * and are available at http://www.eclipse.org/legal/epl-v10.html
7 * and http://www.apache.org/licenses/LICENSE-2.0
10 * ZTE - initial API and implementation and/or initial documentation
12 import { AfterViewInit, Component, Input } from '@angular/core';
13 import { Subscription } from '../../../../../node_modules/rxjs/Subscription.d';
15 import { PlanTreeviewItem } from '../../../model/plan-treeview-item';
16 import { NodeTemplate } from '../../../model/topology/node-template';
17 import { ValueSource } from '../../../model/value-source.enum';
18 import { Parameter } from '../../../model/workflow/parameter';
19 import { ToscaNodeTask } from '../../../model/workflow/tosca-node-task';
20 import { BroadcastService } from '../../../services/broadcast.service';
21 import { ToscaService } from '../../../services/tosca.service';
24 * node template component provides operations about tosca modules which saved in winery.
25 * This component will be used in the property component while the corresponding workflow node is calling the node template's operation
28 selector: 'wfm-node-template',
29 templateUrl: 'node-template.component.html',
31 export class NodeTemplateComponent implements AfterViewInit {
32 @Input() public node: ToscaNodeTask;
33 @Input() public planItems: PlanTreeviewItem[];
35 public inputSources: ValueSource[] = [ValueSource.string, ValueSource.Variable, ValueSource.Topology, ValueSource.Plan];
36 public outputSources: ValueSource[] = [ValueSource.Topology, ValueSource.Plan];
37 public nodeInterfaces: string[] = [];
38 public nodeOperations: any[] = [];
39 public nodeTemplates: NodeTemplate[] = [];
41 constructor(private toscaService: ToscaService) {
44 public ngAfterViewInit() {
45 this.nodeTemplates = this.toscaService.getNodeTemplate();
47 this.loadInterfaces();
48 this.loadOperations();
51 public nodeTemplateChanged() {
52 this.setTemplateNamespace();
54 this.nodeInterfaceChanged('');
56 this.loadInterfaces();
59 public nodeInterfaceChanged(newInterface: string) {
60 this.node.nodeInterface = newInterface;
62 this.nodeOperationChanged('');
64 this.loadOperations();
67 public nodeOperationChanged(operation: string) {
68 this.node.operation = operation;
71 this.node.output = [];
73 this.loadParameters();
76 private setTemplateNamespace() {
77 const nodeTemplate = this.nodeTemplates.find(
78 tmpNodeTemplate => tmpNodeTemplate.id === this.node.template.id);
81 this.node.template.namespace = nodeTemplate.namespace;
82 this.node.template.type = nodeTemplate.type;
86 private loadInterfaces() {
87 if (this.node.template.id) {
88 this.toscaService.loadNodeTemplateInterfaces(this.node.template)
89 .subscribe(interfaces => {
90 this.nodeInterfaces = interfaces;
93 this.nodeInterfaces = [];
97 private loadOperations() {
98 if (this.node.nodeInterface) {
99 this.nodeOperations = [];
100 this.toscaService.loadNodeTemplateOperations(
102 this.node.nodeInterface)
103 .subscribe(operations => this.nodeOperations = operations);
105 this.nodeOperations = [];
109 private loadParameters() {
110 if (this.node.operation) {
111 this.toscaService.loadNodeTemplateOperationParameter(
113 this.node.nodeInterface,
115 .subscribe(params => {
116 this.node.input = [];
117 this.node.output = [];
119 params.input.forEach(param => {
120 const p = new Parameter(param, '', ValueSource[ValueSource.string]);
121 this.node.input.push(p);
124 params.output.forEach(param => {
125 const p = new Parameter(param, '', ValueSource[ValueSource.Definition]);
126 this.node.output.push(p);