2 ============LICENSE_START==========================================
3 ===================================================================
4 Copyright (C) 2019 Orange. All rights reserved.
5 ===================================================================
7 Unless otherwise specified, all software contained herein is licensed
8 under the Apache License, Version 2.0 (the License);
9 you may not use this software except in compliance with the License.
10 You may obtain a copy of the License at
12 http://www.apache.org/licenses/LICENSE-2.0
14 Unless required by applicable law or agreed to in writing, software
15 distributed under the License is distributed on an "AS IS" BASIS,
16 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 See the License for the specific language governing permissions and
18 limitations under the License.
19 ============LICENSE_END============================================
21 import { TopologyTemplate } from './model/designer.topologyTemplate.model';
22 import { Injectable } from '@angular/core';
23 import { GraphUtil } from './graph.util';
24 import { NodeTemplate } from './model/desinger.nodeTemplate.model';
29 export class GraphGenerator {
31 constructor(private graphUtil: GraphUtil) {
35 * loops over workflows
36 * create action element
37 * from steps --> create function element
38 * add function element to action element
39 * example toplogyTemplate
46 * "target": "NODE_TEMPLATE_NAME",
53 * "NODE_TEMPLATE_NAME": {
54 * "type": "dg-generic",
56 * "dependency-node-templates": [
57 * "component-config-snapshots-executor",
58 * "component-jython-executor"
62 * "component-config-snapshots-executor": {
63 * "type": "component-config-snapshots-executor",
66 * "component-jython-executor": {
67 * "type": "component-jython-executor",
74 public populate(topologyTempalte: TopologyTemplate,
75 boardGraph: joint.dia.Graph) {
77 Object.keys(topologyTempalte.workflows).forEach(workFlowName => {
78 console.log('drawing workflow item --> ', workFlowName);
80 // create action element
82 this.graphUtil.createCustomActionWithName(workFlowName, boardGraph);
84 // create board function elements
85 const workflow = topologyTempalte.workflows[workFlowName].steps;
86 const stepName = Object.keys(workflow)[0];
88 const nodeTemplateName = workflow[stepName].target;
89 const functionType = topologyTempalte.node_templates[nodeTemplateName].type;
90 console.log('draw function with ', stepName, functionType);
92 this.graphUtil.dropFunctionOverActionRelativeToParent(
94 stepName , functionType, boardGraph);
96 // TODO handle dg-generic case (multi-step in the same action)
97 if (functionType === 'dg-generic') {
98 const props = topologyTempalte.node_templates[nodeTemplateName].properties;
99 console.log('dg props', props);
100 props['dependency-node-templates'].forEach(dependencyStepName => {
101 const dependencyType = topologyTempalte.node_templates[dependencyStepName].type;
102 console.log('dependencyType', dependencyType);
103 this.graphUtil.dropFunctionOverActionRelativeToParent(
105 dependencyStepName, dependencyType, boardGraph);