|
5 | 5 | import xml2js from "xml2js";
|
6 | 6 | import { getWebserviceByName } from "../constants/globals";
|
7 | 7 | import { app } from "../app";
|
8 |
| -import { CATEGORY_DATATEST } from "../constants/constants"; |
| 8 | +import { CATEGORY_DATATEST, CATEGORY_SERVICE } from "../constants/constants"; |
9 | 9 | import { Validation } from "divaservices-utils";
|
10 | 10 | import { sendWorkflowSteps } from "../api/requests";
|
| 11 | +import { getOrderedElements } from "../elements/orderElement"; |
11 | 12 |
|
12 | 13 | // we use the actual graph nodes to get the workflow
|
13 | 14 | // because it contains vital ids (especially ports)
|
14 | 15 | // we make a connection with our store elements
|
15 | 16 | // to retrieve the actual parameters
|
16 | 17 | export const saveWorkflow = jsonGraph => {
|
| 18 | + const orderedElements = getOrderedElements().filter( |
| 19 | + ({ attributes: { category } }) => category == CATEGORY_SERVICE |
| 20 | + ); |
| 21 | + |
17 | 22 | const log = [];
|
18 | 23 | const Steps = { Step: [] };
|
19 | 24 | // NODE
|
20 |
| - app.currentElements |
21 |
| - .filter(({ category }) => category != CATEGORY_DATATEST) |
22 |
| - .forEach((box, i) => { |
23 |
| - const { type, boxId } = box; |
24 |
| - const Name = type.replace(/\s/g, ""); |
25 |
| - const No = i; |
26 |
| - const Inputs = { Parameter: [], Data: [] }; |
27 |
| - |
28 |
| - // get actual defaultParams in store |
29 |
| - const defaultParams = app.elements.find(el => el.boxId == boxId) |
30 |
| - .defaultParams; |
31 |
| - |
32 |
| - for (const [paramType, values] of Object.entries(defaultParams)) { |
33 |
| - for (const [paramName, options] of Object.entries(values)) { |
34 |
| - const { value: Value, defaultValue, values } = options; |
35 |
| - if (Value != defaultValue.toString()) { |
36 |
| - Inputs.Parameter.push({ |
37 |
| - Name: paramName, |
38 |
| - Value |
39 |
| - }); |
40 |
| - } |
41 |
| - const validity = Validation.checkValue(Value, paramType, values); |
42 |
| - if (!validity) { |
43 |
| - log.push({ |
44 |
| - value: Value, |
45 |
| - Name: paramName, |
46 |
| - paramType, |
47 |
| - name: type, |
48 |
| - boxId |
49 |
| - }); |
50 |
| - } |
| 25 | + |
| 26 | + for (const [i, { attributes: box }] of orderedElements.entries()) { |
| 27 | + // app.currentElements |
| 28 | + // .filter(({ category }) => category != CATEGORY_DATATEST) |
| 29 | + // .forEach((box, i) => { |
| 30 | + const { type, boxId } = box; |
| 31 | + const Name = type.replace(/\s/g, ""); |
| 32 | + const No = i; |
| 33 | + const Inputs = { Parameter: [], Data: [] }; |
| 34 | + |
| 35 | + // get actual defaultParams in store |
| 36 | + const defaultParams = app.elements.find(el => el.boxId == boxId) |
| 37 | + .defaultParams; |
| 38 | + |
| 39 | + for (const [paramType, values] of Object.entries(defaultParams)) { |
| 40 | + for (const [paramName, options] of Object.entries(values)) { |
| 41 | + const { value: Value, defaultValue, values } = options; |
| 42 | + if (Value != defaultValue.toString()) { |
| 43 | + Inputs.Parameter.push({ |
| 44 | + Name: paramName, |
| 45 | + Value |
| 46 | + }); |
| 47 | + } |
| 48 | + const validity = Validation.checkValue(Value, paramType, values); |
| 49 | + if (!validity) { |
| 50 | + log.push({ |
| 51 | + value: Value, |
| 52 | + Name: paramName, |
| 53 | + paramType, |
| 54 | + name: type, |
| 55 | + boxId |
| 56 | + }); |
51 | 57 | }
|
52 | 58 | }
|
| 59 | + } |
53 | 60 |
|
54 |
| - // ports.items.forEach(port => { |
55 |
| - // console.log(port); |
56 |
| - // allPorts[port.id] = { |
57 |
| - // boxId, |
58 |
| - // boxNo: i, |
59 |
| - // name: port.name |
60 |
| - // }; |
61 |
| - // }); |
62 |
| - |
63 |
| - // key in webservices list |
64 |
| - const Key = getWebserviceByName(type).id; |
65 |
| - const Service = { Key }; |
| 61 | + // key in webservices list |
| 62 | + const Key = getWebserviceByName(type).id; |
| 63 | + const Service = { Key }; |
66 | 64 |
|
67 |
| - const step = { Id: boxId, No, Name, Service, Inputs }; |
68 |
| - Steps.Step.push(step); |
69 |
| - }); |
| 65 | + const step = { Id: boxId, No, Name, Service, Inputs }; |
| 66 | + Steps.Step.push(step); |
| 67 | + // }); |
| 68 | + } |
70 | 69 |
|
71 | 70 | // save data elements
|
72 | 71 | const dataPorts = {};
|
@@ -131,7 +130,6 @@ export const saveWorkflow = jsonGraph => {
|
131 | 130 |
|
132 | 131 | // remove Id to match relax validation schema
|
133 | 132 | for (const step of Steps.Step) {
|
134 |
| - console.log("TCL: step", step); |
135 | 133 | delete step.Id;
|
136 | 134 | }
|
137 | 135 |
|
|
0 commit comments