Merge "Truncate message published on Kafka / Spike: Define solution for logs separation"
[ccsdk/cds.git] / cds-ui / designer-client / src / app / modules / feature-modules / packages / designer / graph.generator.util.ts
1 /*
2 ============LICENSE_START==========================================
3 ===================================================================
4 Copyright (C) 2019 Orange. All rights reserved.
5 ===================================================================
6
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
11
12     http://www.apache.org/licenses/LICENSE-2.0
13
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============================================
20 */
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';
25
26 @Injectable({
27     providedIn: 'root'
28 })
29 export class GraphGenerator {
30
31     constructor(private graphUtil: GraphUtil) {
32     }
33
34     /**
35      * loops over workflows
36      * create action element
37      * from steps --> create function element
38      * add function element to action element
39      * example toplogyTemplate
40      *
41      * {
42      * "workflows": {
43      *   "Action1": {
44      *       "steps": {
45      *           "STEP_NAME": {
46      *               "target": "NODE_TEMPLATE_NAME",
47      *                   "description": ""
48      *           }
49      *       }
50      *   }
51      * },
52      * "node_templates": {
53      *    "NODE_TEMPLATE_NAME": {
54      *        "type": "dg-generic",
55      *            "properties": {
56      *            "dependency-node-templates": [
57      *                "component-config-snapshots-executor",
58      *                "component-jython-executor"
59      *            ]
60      *        }
61      *    },
62      *    "component-config-snapshots-executor": {
63      *        "type": "component-config-snapshots-executor",
64      *            "properties": { }
65      *    },
66      *    "component-jython-executor": {
67      *        "type": "component-jython-executor",
68      *            "properties": { }
69      *    }
70      * }
71      * }
72      */
73
74     public populate(topologyTempalte: TopologyTemplate,
75                     boardGraph: joint.dia.Graph) {
76
77         Object.keys(topologyTempalte.workflows).forEach(workFlowName => {
78             console.log('drawing workflow item --> ', workFlowName);
79
80             // create action element
81             const actionElement =
82                     this.graphUtil.createCustomActionWithName(workFlowName, boardGraph);
83
84             // create board function elements
85             const workflow = topologyTempalte.workflows[workFlowName].steps;
86             const stepName = Object.keys(workflow)[0];
87             if (stepName) {
88                 const nodeTemplateName = workflow[stepName].target;
89                 const functionType = topologyTempalte.node_templates[nodeTemplateName].type;
90                 console.log('draw function with ', stepName, functionType);
91
92                 this.graphUtil.dropFunctionOverActionRelativeToParent(
93                     actionElement,
94                     stepName , functionType, boardGraph);
95
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(
104                             actionElement,
105                             dependencyStepName, dependencyType, boardGraph);
106
107                     });
108                 }
109             }
110         });
111
112     }
113 }