Skip to content

Commit 2735eb4

Browse files
committed
feat: compute workflow installation json on save
1 parent 444c5f9 commit 2735eb4

File tree

2 files changed

+42
-13
lines changed

2 files changed

+42
-13
lines changed

src/js/constants/globals.js

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Decorators } from "divaservices-utils";
22
import { getServicesAPI } from "../api/requests";
3-
import { INPUTS_DATA_XML_FILEPATH } from "../../config";
4-
import { dataTestDecorator } from "./dataTestDecorator";
3+
// import { INPUTS_DATA_XML_FILEPATH } from "../../config";
4+
// import { dataTestDecorator } from "./dataTestDecorator";
55
import { DATATEST_TYPE } from "./constants";
66

77
export let webservices;
@@ -12,12 +12,12 @@ const _initWebservices = async () => {
1212
webservices = await Decorators.webservicesDecorator(xml);
1313
};
1414

15-
const _initDataInputsOld = async () => {
16-
const inputDataFilePath = INPUTS_DATA_XML_FILEPATH;
17-
const inputDataXml = (await import(`!!raw-loader!../../${inputDataFilePath}`))
18-
.default;
19-
dataInputs = await dataTestDecorator(inputDataXml);
20-
};
15+
// const _initDataInputsOld = async () => {
16+
// const inputDataFilePath = INPUTS_DATA_XML_FILEPATH;
17+
// const inputDataXml = (await import(`!!raw-loader!../../${inputDataFilePath}`))
18+
// .default;
19+
// dataInputs = await dataTestDecorator(inputDataXml);
20+
// };
2121

2222
const _initDataInputs = async () => {
2323
dataInputs = [
@@ -42,10 +42,7 @@ const _initDataInputs = async () => {
4242
// init webservices from xml file
4343
export const initWebservices = async () => {
4444
await _initWebservices();
45-
await _initDataInputsOld();
46-
console.log(dataInputs);
4745
await _initDataInputs();
48-
console.log(dataInputs);
4946
};
5047

5148
export const getWebserviceByName = name => {

src/js/workflows/saveWorkflow.js

+34-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export const saveWorkflow = jsonGraph => {
2121

2222
const log = [];
2323
const Steps = { Step: [] };
24+
const _steps = [];
2425
// NODE
2526

2627
for (const [i, { attributes: box }] of orderedElements.entries()) {
@@ -32,6 +33,8 @@ export const saveWorkflow = jsonGraph => {
3233
const No = i;
3334
const Inputs = { Parameter: [], Data: [] };
3435

36+
const _inputs = { parameters: {}, data: [] };
37+
3538
// get actual defaultParams in store
3639
const defaultParams = app.elements.find(el => el.boxId == boxId)
3740
.defaultParams;
@@ -44,6 +47,7 @@ export const saveWorkflow = jsonGraph => {
4447
Name: paramName,
4548
Value
4649
});
50+
_inputs.parameters[paramName] = JSON.parse(Value);
4751
}
4852
const validity = Validation.checkValue(Value, paramType, values);
4953
if (!validity) {
@@ -59,9 +63,18 @@ export const saveWorkflow = jsonGraph => {
5963
}
6064

6165
// key in webservices list
62-
const Key = getWebserviceByName(type).id;
66+
const currentService = getWebserviceByName(type);
67+
const { id: Key, method } = currentService;
6368
const Service = { Key };
6469

70+
const _step = {
71+
name: Name,
72+
type: "regular",
73+
method,
74+
inputs: _inputs
75+
};
76+
_steps.push(_step);
77+
6578
const step = { Id: boxId, No, Name, Service, Inputs };
6679
Steps.Step.push(step);
6780
// });
@@ -89,9 +102,12 @@ export const saveWorkflow = jsonGraph => {
89102
// search in steps step because it contains the inputs.data array
90103
const targetWebservice = Steps.Step.find(el => el.Id == targetId);
91104
const sourceWebservice = Steps.Step.find(el => el.Id == sourceId);
105+
const _targetWebservice = _steps.find(
106+
el => el.name == targetWebservice.Name
107+
);
92108

93109
if (sourceWebservice) {
94-
const { No: Ref } = sourceWebservice;
110+
const { No: Ref, Name: name } = sourceWebservice;
95111
const p = {
96112
Name: link.target.portName,
97113
Value: {
@@ -102,6 +118,10 @@ export const saveWorkflow = jsonGraph => {
102118
}
103119
};
104120
targetWebservice.Inputs.Data.push(p);
121+
122+
_targetWebservice.inputs.data.push({
123+
[link.target.portName]: `$${name}/$${link.source.portName}`
124+
});
105125
} else {
106126
const sourceDataBox = app.currentDataElements.find(
107127
el => el.boxId == sourceId
@@ -122,6 +142,9 @@ export const saveWorkflow = jsonGraph => {
122142
Name: dataName,
123143
Path: file.identifier
124144
});
145+
_targetWebservice.inputs.data.push({
146+
[link.target.portName]: file.identifier
147+
});
125148
}
126149
});
127150

@@ -133,10 +156,19 @@ export const saveWorkflow = jsonGraph => {
133156
delete step.Id;
134157
}
135158

159+
console.log(JSON.stringify(_steps));
160+
136161
const builder = new xml2js.Builder({ rootName: "Steps" });
137162
const xml = builder.buildObject(Steps);
138163
console.log("TCL: xml", xml);
139164

165+
// add json request to xml
166+
const finalXml = `<Request>
167+
<JsonRequest>${JSON.stringify(_steps)}</JsonRequest>
168+
${xml}
169+
</Request>`;
170+
console.log(finalXml);
171+
140172
app.$refs.log.setLogMessages(log);
141173

142174
//@TODO add xml headers

0 commit comments

Comments
 (0)