From 1c5d474d91b0d421bbbaefa5491f2a6abe8fbe17 Mon Sep 17 00:00:00 2001 From: Abhinav Verma Date: Wed, 18 Sep 2024 11:43:08 +0530 Subject: [PATCH] fix(core): saurabh sinha json changes saurabh sinha json changes GH-9-valueAny --- projects/workflows-creator/src/lib/const.ts | 10 ++-- .../bpmn/elements/gateways/gateway.element.ts | 4 +- .../bpmn/elements/process/process.element.ts | 3 +- .../strategies/create/task-create.strategy.ts | 53 ++++++++++++------- .../strategies/link/gateway-link.strategy.ts | 28 ++++++++-- .../link/or-gateway-link.strategy.ts | 7 +-- 6 files changed, 70 insertions(+), 35 deletions(-) diff --git a/projects/workflows-creator/src/lib/const.ts b/projects/workflows-creator/src/lib/const.ts index 65c943d..4050e0f 100644 --- a/projects/workflows-creator/src/lib/const.ts +++ b/projects/workflows-creator/src/lib/const.ts @@ -14,14 +14,14 @@ xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_1aj5pzu" targetNamespace="http://bpmn.io/schema/bpmn" -exporter="Camunda Modeler" exporterVersion="4.12.0" +exporter="Camunda Modeler" exporterVersion="5.21.0" modeler:executionPlatform="Camunda Platform" -modeler:executionPlatformVersion="7.15.0"> +modeler:executionPlatformVersion="7.21.0"> `; -export const JSON_SCRIPT_START = `var json = S(\"{}\");\n`; -export const JSON_SCRIPT_END = `\n json`; +export const JSON_SCRIPT_START = `var json = {};\n`; +export const JSON_SCRIPT_END = `\n JSON.stringify(json)`; export const BASE_XML = new InjectionToken('diagram.bpmn.base'); export const MODDLE = new InjectionToken( @@ -48,4 +48,4 @@ export const typeTuppleList: Array = [ {condition: ConditionTypes.LessThan, operator: '<', value: true}, {condition: ConditionTypes.ComingIn, operator: '-', value: true}, {condition: ConditionTypes.PastBy, operator: '+', value: true}, -]; +]; \ No newline at end of file diff --git a/projects/workflows-creator/src/lib/services/bpmn/elements/gateways/gateway.element.ts b/projects/workflows-creator/src/lib/services/bpmn/elements/gateways/gateway.element.ts index 6c178e5..9840a38 100644 --- a/projects/workflows-creator/src/lib/services/bpmn/elements/gateways/gateway.element.ts +++ b/projects/workflows-creator/src/lib/services/bpmn/elements/gateways/gateway.element.ts @@ -21,7 +21,7 @@ export class GatewayElement extends BpmnElement { ) { super(); } - tag = 'bpmn:ExclusiveGateway'; + tag = 'bpmn:InclusiveGateway'; name = 'gateway'; properties = {}; statement: string | undefined; @@ -40,4 +40,4 @@ export class GatewayElement extends BpmnElement { getIdentifier(): string { return GatewayElement.identifier; } -} +} \ No newline at end of file diff --git a/projects/workflows-creator/src/lib/services/bpmn/elements/process/process.element.ts b/projects/workflows-creator/src/lib/services/bpmn/elements/process/process.element.ts index 059f7ba..9aec485 100644 --- a/projects/workflows-creator/src/lib/services/bpmn/elements/process/process.element.ts +++ b/projects/workflows-creator/src/lib/services/bpmn/elements/process/process.element.ts @@ -30,9 +30,10 @@ export class ProcessElement extends BpmnElement { static identifier = 'ProcessElement'; attributes = { isExecutable: true, + historyTimeToLive: 'P3650D', }; getIdentifier(): string { return ProcessElement.identifier; } -} +} \ No newline at end of file diff --git a/projects/workflows-creator/src/lib/services/bpmn/strategies/create/task-create.strategy.ts b/projects/workflows-creator/src/lib/services/bpmn/strategies/create/task-create.strategy.ts index 72562df..aef6847 100644 --- a/projects/workflows-creator/src/lib/services/bpmn/strategies/create/task-create.strategy.ts +++ b/projects/workflows-creator/src/lib/services/bpmn/strategies/create/task-create.strategy.ts @@ -142,38 +142,53 @@ export class CreateTaskStrategy implements CreateStrategy { let read = ''; if (froms.length > 0) { if (prevIds.length) { - read = `var readObj = ${prevIds - .map(id => `JSON.parse(execution.getVariable('${id}'))`) - .join(' || ')} || {};`; + read = `${prevIds + .map( + (id, index) => + `var readObj${index} = JSON.parse(execution.getVariable('${id}')) || {};`, + ) + .join('\n')} + `; } } - const getVariables = froms - .map( - p => - `var ${(p as FromParam).from}Local = readObj.${ - (p as FromParam).from - };`, - ) - .join('\n'); + const getVariables = froms.map( + p => + ` + var ${(p as FromParam).from}Local; + ${prevIds + .map( + (_: any, index: number) => ` + if(readObj${index}.${ + (p as FromParam).from + } && readObj${index}.${(froms[0] as FromParam).from}.length){ + ${(froms[0] as FromParam).from}Local = readObj${index}.${ + (froms[0] as FromParam).from + }; + } + `, + ) + .join('\n')} + `, + ); const setVariabels = Object.keys(params).reduce( (p: string, key: string) => { const tmp = params[key]; if (isFormattedParam(tmp)) { - return `${p}\njson.prop("${key}", ${tmp.formatter(state)});`; + return `${p}\njson["${key}"] = ${tmp.formatter(state)};`; } else if (isFromParam(tmp)) { - return `${p}\njson.prop("${key}", ${tmp.from}Local);`; + return `${p}\njson["${key}"] = ${tmp.from}Local;`; } else if (isStateParam(tmp)) { if ( tmp.state === 'recipients' && Array.isArray(state.get(tmp.state)) ) { const metaValue = this.transposeArrayToString(state.get(tmp.state)); - return `${p}\njson.prop("${key}", [${metaValue ?? ''}]);`; + return `${p}\njson["${key}"] = [${metaValue ?? ''}];`; } - return `${p}\njson.prop("${key}", "${state.get(tmp.state) ?? ''}");`; + return `${p}\njson["${key}"] = "${state.get(tmp.state) ?? ''}";`; } else { - return `${p}\njson.prop("${key}", "${tmp.value}");`; + return `${p}\njson["${key}"] = "${tmp.value}";`; } }, '', @@ -181,9 +196,9 @@ export class CreateTaskStrategy implements CreateStrategy { return [ read, getVariables, - `var json = S("{}");`, + `var json = {};`, setVariabels, - 'json', + 'JSON.stringify(json)', ].join('\n'); } @@ -207,4 +222,4 @@ export class CreateTaskStrategy implements CreateStrategy { return [node.prev[0].element.id]; } } -} +} \ No newline at end of file diff --git a/projects/workflows-creator/src/lib/services/bpmn/strategies/link/gateway-link.strategy.ts b/projects/workflows-creator/src/lib/services/bpmn/strategies/link/gateway-link.strategy.ts index 5d79f97..32342b8 100644 --- a/projects/workflows-creator/src/lib/services/bpmn/strategies/link/gateway-link.strategy.ts +++ b/projects/workflows-creator/src/lib/services/bpmn/strategies/link/gateway-link.strategy.ts @@ -193,12 +193,13 @@ export class GatewayLinkStrategy implements LinkStrategy { ) { const lastNodeWithOutput = this.getLastNodeWithOutput(node); const read = `var readObj = JSON.parse(execution.getVariable('${lastNodeWithOutput.element.id}'));`; - const declarations = `var ids = [];var json = S("{}");`; + const declarations = `var ids = [];var json = {};`; const column = node.workflowNode.state.get('columnName'); const condition = this.getCondition(node); const loop = this.createLoopScript(node, condition, isElse); const setters = ` - json.prop("taskIds", ids); + json["taskIds"] = ids; + json = JSON.stringify(json); execution.setVariable('${flowId}',json); if(ids.length > 0){true;}else {false;} `; @@ -227,6 +228,25 @@ export class GatewayLinkStrategy implements LinkStrategy { const valueType = node.workflowNode.state.get('valueType'); const valueInputType = node.workflowNode.state.get('valueInputType'); + if ( + valueInputType === InputTypes.Date && + (valueType === ValueTypes.Custom || + conditionType === ConditionTypes.Equal) + ) { + return ` + for (var key in readObj) { + var taskValuePair = readObj[key]; + if (taskValuePair && (taskValuePair.value || taskValuePair.value==='')) { + var readDateValue = taskValuePair.value.split('T')[0]; + var customDate = "${condition}"; + + if (${isElse ? '!' : ''}(readDateValue === customDate)) { + ids.push(taskValuePair.id); + } + } + } + `; + } if (!conditionType && valueType && valueInputType === InputTypes.Date) { switch (valueType) { case ValueTypes.PastToday: @@ -261,9 +281,7 @@ export class GatewayLinkStrategy implements LinkStrategy { var readDateValue = taskValuePair.value.split('T')[0]; var customDate = "${condition}"; - if (${ - isElse ? '!' : '' - }(readDateValue === customDate)) { + if (${isElse ? '!' : ''}(readDateValue === customDate)) { ids.push(taskValuePair.id); } } diff --git a/projects/workflows-creator/src/lib/services/bpmn/strategies/link/or-gateway-link.strategy.ts b/projects/workflows-creator/src/lib/services/bpmn/strategies/link/or-gateway-link.strategy.ts index f20ddfc..dd81fd3 100644 --- a/projects/workflows-creator/src/lib/services/bpmn/strategies/link/or-gateway-link.strategy.ts +++ b/projects/workflows-creator/src/lib/services/bpmn/strategies/link/or-gateway-link.strategy.ts @@ -112,12 +112,13 @@ export class OrGatewayLinkStrategy implements LinkStrategy { ) { const lastNodeWithOutput = this.getLastNodeWithOutput(node); const read = `var readObj = JSON.parse(execution.getVariable('${lastNodeWithOutput.element.id}'));`; - const declarations = `var ids = [];var json = S("{}");`; + const declarations = `var ids = [];var json = {};`; const column = node.workflowNode.state.get('columnName'); const condition = this.getCondition(node); const loop = this.createLoopScript(node, condition, isElse); const setters = ` - json.prop("taskIds", ids); + json["taskIds"] = ids; + json.stringify(json); execution.setVariable('${flowId}',json); if(ids.length > 0){true;}else {false;} `; @@ -229,4 +230,4 @@ export class OrGatewayLinkStrategy implements LinkStrategy { return `${pair.operator}`; } } -} +} \ No newline at end of file