Skip to content

Commit

Permalink
fix(core): saurabh sinha json changes
Browse files Browse the repository at this point in the history
saurabh sinha json changes

GH-9-valueAny
  • Loading branch information
Abhinav Verma authored and Abhinav Verma committed Sep 18, 2024
1 parent 5b73dc1 commit 1c5d474
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 35 deletions.
10 changes: 5 additions & 5 deletions projects/workflows-creator/src/lib/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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">
</bpmn:definitions>
`;

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<string>('diagram.bpmn.base');
export const MODDLE = new InjectionToken<CustomBpmnModdle>(
Expand All @@ -48,4 +48,4 @@ export const typeTuppleList: Array<ConditionOperatorPair> = [
{condition: ConditionTypes.LessThan, operator: '<', value: true},
{condition: ConditionTypes.ComingIn, operator: '-', value: true},
{condition: ConditionTypes.PastBy, operator: '+', value: true},
];
];
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class GatewayElement extends BpmnElement {
) {
super();
}
tag = 'bpmn:ExclusiveGateway';
tag = 'bpmn:InclusiveGateway';
name = 'gateway';
properties = {};
statement: string | undefined;
Expand All @@ -40,4 +40,4 @@ export class GatewayElement extends BpmnElement {
getIdentifier(): string {
return GatewayElement.identifier;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ export class ProcessElement extends BpmnElement {
static identifier = 'ProcessElement';
attributes = {
isExecutable: true,
historyTimeToLive: 'P3650D',
};

getIdentifier(): string {
return ProcessElement.identifier;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,48 +142,63 @@ export class CreateTaskStrategy implements CreateStrategy<ModdleElement> {
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}";`;
}
},
'',
);
return [
read,
getVariables,
`var json = S("{}");`,
`var json = {};`,
setVariabels,
'json',
'JSON.stringify(json)',
].join('\n');
}

Expand All @@ -207,4 +222,4 @@ export class CreateTaskStrategy implements CreateStrategy<ModdleElement> {
return [node.prev[0].element.id];
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,13 @@ export class GatewayLinkStrategy implements LinkStrategy<ModdleElement> {
) {
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;}
`;
Expand Down Expand Up @@ -227,6 +228,25 @@ export class GatewayLinkStrategy implements LinkStrategy<ModdleElement> {
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:
Expand Down Expand Up @@ -261,9 +281,7 @@ export class GatewayLinkStrategy implements LinkStrategy<ModdleElement> {
var readDateValue = taskValuePair.value.split('T')[0];
var customDate = "${condition}";
if (${
isElse ? '!' : ''
}(readDateValue === customDate)) {
if (${isElse ? '!' : ''}(readDateValue === customDate)) {
ids.push(taskValuePair.id);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,13 @@ export class OrGatewayLinkStrategy implements LinkStrategy<ModdleElement> {
) {
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;}
`;
Expand Down Expand Up @@ -229,4 +230,4 @@ export class OrGatewayLinkStrategy implements LinkStrategy<ModdleElement> {
return `${pair.operator}`;
}
}
}
}

0 comments on commit 1c5d474

Please sign in to comment.