Skip to content

Commit

Permalink
Ms2 user task execution (#425)
Browse files Browse the repository at this point in the history
* Added a submit button and some data to the generated html files to make them submittable on the engine

* Added support for checkbox group submit as an array value

* Fixed export of images used in processes; Made images used in user task from the new MS work on the engine

* Fixed: Cannot version processes that have a user task with a saved user task form

* Fixed: Processes using the new (uuid) version ids are not executed correctly

* Fixed: The change to the version ids can result in another version than the last being deployed

* Improved the way the version is extracted from the neo-engine information to support both the old and new version id format and fixed the unit tests

* Fixed: Changing an image in a user task does not work due to throwing and error

* Removed empty inline style attribute
  • Loading branch information
jjoderis authored Dec 10, 2024
1 parent ef50588 commit 5e698ff
Show file tree
Hide file tree
Showing 19 changed files with 316 additions and 114 deletions.
42 changes: 21 additions & 21 deletions src/engine/universal/core/src/__tests__/engine.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ describe('ProceedEngine', () => {
it('calls given callbacks for executed process', async () => {
distribution.db.getProcessVersion.mockResolvedValueOnce(scriptTaskBPMN);

await engine.deployProcessVersion(0, 123);
engine.startProcessVersion(123, {}, onStarted, onEnded, onTokenEnded);
await engine.deployProcessVersion('0', '123');
engine.startProcessVersion('123', {}, onStarted, onEnded, onTokenEnded);

await sleep(1000);

Expand All @@ -119,8 +119,8 @@ describe('ProceedEngine', () => {
it('contains added information from proceed in token and logs for executed process', async () => {
distribution.db.getProcessVersion.mockResolvedValueOnce(scriptTaskBPMN);

await engine.deployProcessVersion(0, 123);
engine.startProcessVersion(123, {}, onStarted, onEnded, onTokenEnded);
await engine.deployProcessVersion('0', '123');
engine.startProcessVersion('123', {}, onStarted, onEnded, onTokenEnded);

await hasEnded;

Expand Down Expand Up @@ -195,8 +195,8 @@ describe('ProceedEngine', () => {
let onEnded1;
const hasEnded1 = new Promise((resolve) => (onEnded1 = resolve));

await engine.deployProcessVersion(0, 123);
engine.startProcessVersion(123, {}, onStarted, onEnded1);
await engine.deployProcessVersion('0', '123');
engine.startProcessVersion('123', {}, onStarted, onEnded1);
expect(engine.instanceIDs.length).toBe(1);

await hasEnded1;
Expand All @@ -205,7 +205,7 @@ describe('ProceedEngine', () => {
const hasEnded2 = new Promise((resolve) => (onEnded2 = resolve));

expect(() => {
engine.startProcessVersion(123, {}, onStarted, onEnded2);
engine.startProcessVersion('123', {}, onStarted, onEnded2);
}).not.toThrow();
expect(engine.instanceIDs.length).toBe(1);

Expand All @@ -218,9 +218,9 @@ describe('ProceedEngine', () => {
let onEnded1;
const hasEnded1 = new Promise((resolve) => (onEnded1 = resolve));

await engine.deployProcessVersion(0, 123);
await engine.deployProcessVersion('0', '123');
const onStarted1 = jest.fn();
engine.startProcessVersion(123, {}, onStarted1, onEnded1);
engine.startProcessVersion('123', {}, onStarted1, onEnded1);
expect(engine.instanceIDs.length).toBe(1);

await hasEnded1;
Expand All @@ -230,9 +230,9 @@ describe('ProceedEngine', () => {
let onEnded2;
const hasEnded2 = new Promise((resolve) => (onEnded2 = resolve));

await engine.deployProcessVersion(0, 456);
await engine.deployProcessVersion('0', '456');
const onStarted2 = jest.fn();
engine.startProcessVersion(456, {}, onStarted2, onEnded2);
engine.startProcessVersion('456', {}, onStarted2, onEnded2);
expect(engine.instanceIDs.length).toBe(1);

await hasEnded2;
Expand All @@ -248,8 +248,8 @@ describe('ProceedEngine', () => {
it('calls given network-service in a script task', async () => {
distribution.db.getProcessVersion.mockResolvedValueOnce(scriptTaskBPMN);

await engine.deployProcessVersion(0, 123);
engine.startProcessVersion(123, {}, onStarted, onEnded);
await engine.deployProcessVersion('0', '123');
engine.startProcessVersion('123', {}, onStarted, onEnded);

await hasEnded;

Expand All @@ -260,8 +260,8 @@ describe('ProceedEngine', () => {
distribution.db.getProcessVersion.mockResolvedValueOnce(userTaskBPMN);
const userTaskID = 'Task_1y4wd2q';

await engine.deployProcessVersion(0, 123);
engine.startProcessVersion(123, {}, onStarted, onEnded);
await engine.deployProcessVersion('0', '123');
engine.startProcessVersion('123', {}, onStarted, onEnded);

await sleep(500);

Expand All @@ -285,8 +285,8 @@ describe('ProceedEngine', () => {
it('takes variables input on a userTask', async () => {
distribution.db.getProcessVersion.mockResolvedValueOnce(userTaskBPMN);

await engine.deployProcessVersion(0, 123);
engine.startProcessVersion(123, {}, onStarted, onEnded);
await engine.deployProcessVersion('0', '123');
engine.startProcessVersion('123', {}, onStarted, onEnded);

await sleep(500);

Expand Down Expand Up @@ -317,8 +317,8 @@ describe('ProceedEngine', () => {
it('can be stopped through api function', async () => {
distribution.db.getProcessVersion.mockResolvedValueOnce(userTaskBPMN);

await engine.deployProcessVersion(0, 123);
engine.startProcessVersion(123, {}, onStarted, onEnded);
await engine.deployProcessVersion('0', '123');
engine.startProcessVersion('123', {}, onStarted, onEnded);

await sleep(500);

Expand All @@ -345,9 +345,9 @@ describe('ProceedEngine', () => {
log: [],
};

await engine.deployProcessVersion(0, 123);
await engine.deployProcessVersion('0', '123');
engine.startProcessVersion(
123,
'123',
{},
instance,
() => {
Expand Down
32 changes: 16 additions & 16 deletions src/engine/universal/core/src/__tests__/management.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ describe('Management', () => {
jest.spyOn(Engine.prototype, 'deployProcessVersion');
jest.spyOn(Engine.prototype, 'startProcessVersion');
distribution.db.isProcessVersionValid.mockResolvedValue(true);
const instanceId = await management.createInstance(0, 123, {});
const instanceId = await management.createInstance('0', '123', {});
expect(management.getEngineWithID(instanceId)).toBeInstanceOf(Engine);
expect(Engine.prototype.deployProcessVersion).toHaveBeenCalledWith(0, 123);
expect(Engine.prototype.deployProcessVersion).toHaveBeenCalledWith('0', '123');
expect(Engine.prototype.startProcessVersion).toHaveBeenCalledWith(
123,
'123',
{},
undefined,
undefined,
Expand All @@ -166,9 +166,9 @@ describe('Management', () => {
it('reuses an existing ProceedEngine instance when there is one for the given definitionsId to start an instance', async () => {
jest.spyOn(Engine.prototype, 'deployProcessVersion');
jest.spyOn(Engine.prototype, 'startProcessVersion');
const firstInstanceId = await management.createInstance(0, 123, {});
const firstInstanceId = await management.createInstance('0', '123', {});

const secondInstanceId = await management.createInstance(0, 123, {});
const secondInstanceId = await management.createInstance('0', '123', {});

const firstEngine = management.getEngineWithID(firstInstanceId);
expect(management.getEngineWithID(firstInstanceId)).toBe(
Expand All @@ -183,7 +183,7 @@ describe('Management', () => {

const instance = {
processId: '0',
processVersion: 789,
processVersion: '789',
processInstanceId: '0-123',
tokens: [
{
Expand Down Expand Up @@ -213,11 +213,11 @@ describe('Management', () => {
};

// try to continue instance which was never started on this engine
const engine = await management.continueInstance(0, instance);
const engine = await management.continueInstance('0', instance);
expect(engine).toBeInstanceOf(Engine);
expect(Engine.prototype.deployProcessVersion).toHaveBeenCalledWith(0, 789);
expect(Engine.prototype.deployProcessVersion).toHaveBeenCalledWith('0', '789');
expect(Engine.prototype.startProcessVersion).toHaveBeenCalledWith(
789,
'789',
{},
startingInstanceInfo,
expect.any(Function),
Expand Down Expand Up @@ -252,13 +252,13 @@ describe('Management', () => {
});
distribution.db.getProcessVersion.mockReturnValue(testBPMN);
distribution.db.isProcessVersionValid.mockResolvedValue(true);
await management.createInstance(0, 123, {});
await management.createInstance('0', '123', {});

// distribution.db.getProcess.mockResolvedValueOnce(testBPMN);
await management.createInstance(1, 456, {});
await management.createInstance('1', '456', {});

// distribution.db.getProcess.mockResolvedValueOnce(testBPMN);
await management.createInstance(2, 789, {});
await management.createInstance('2', '789', {});

await new Promise((resolve) => {
setTimeout(() => {
Expand All @@ -271,9 +271,9 @@ describe('Management', () => {

it('remove process engine', async () => {
jest.spyOn(Engine.prototype, 'startProcessVersion');
await management.createInstance(0, 123, {});
expect(management.getEngineWithDefinitionId(0)).toBeInstanceOf(Engine);
management.removeProcessEngine(0);
expect(management.getEngineWithDefinitionId(0)).toBeUndefined();
await management.createInstance('0', '123', {});
expect(management.getEngineWithDefinitionId('0')).toBeInstanceOf(Engine);
management.removeProcessEngine('0');
expect(management.getEngineWithDefinitionId('0')).toBeUndefined();
});
});
13 changes: 5 additions & 8 deletions src/engine/universal/core/src/engine/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,7 @@ class Engine {
const instance = this.getInstance(instanceId);

const state = instance.getState();
const processId = state.processId.substring(0, state.processId.lastIndexOf('-'));
const version = state.processId.substring(processId.length + 1);
const version = state.processId.substring(this.definitionId.length + 1);

return this._versionBpmnMapping[version];
}
Expand Down Expand Up @@ -439,25 +438,23 @@ class Engine {

const state = instance.getState();

// FIXME: Doesn't work when version ID is not a number string (e.g. uuid)
const processId = state.processId.substring(0, state.processId.lastIndexOf('-'));
const processVersion = state.processId.substring(processId.length + 1);
const processVersion = state.processId.substring(this.definitionId.length + 1);

// map the adaptation log migration entries to show the version info
const adaptationLog = state.adaptationLog.map((entry) => {
if (entry.type === 'MIGRATION' && entry.from && entry.to) {
return {
type: entry.type,
time: entry.time,
sourceVersion: entry.from.substring(processId.length + 1),
targetVersion: entry.to.substring(processId.length + 1),
sourceVersion: entry.from.substring(this.definitionId.length + 1),
targetVersion: entry.to.substring(this.definitionId.length + 1),
};
} else {
return entry;
}
});

const instanceInfo = { ...state, processId, processVersion, adaptationLog };
const instanceInfo = { ...state, processId: this.definitionId, processVersion, adaptationLog };

if (instance.callingInstance) {
instanceInfo.callingInstance = instance.callingInstance;
Expand Down
4 changes: 2 additions & 2 deletions src/engine/universal/core/src/engine/hookCallbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,11 @@ module.exports = {
});
// we are starting a new local instance to continue an instance started on another machine
}

engine.instanceIDs.push(newInstance.id);

const state = newInstance.getState();
const processId = state.processId.substring(0, state.processId.lastIndexOf('-'));
const processVersion = state.processId.substring(processId.length + 1);
const processVersion = state.processId.substring(engine.definitionId.length + 1);

engine._instanceIdProcessMapping[newInstance.id] =
engine._versionProcessMapping[processVersion];
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,19 @@ const DeploymentsView = ({
}

const v = process.versions
.map((v) => v.id)
.sort()
.at(-1);
.map((v) => ({ id: v.id, creationTime: +v.createdOn }))
.sort((a, b) => {
return b.creationTime - a.creationTime;
})
.at(0);

await deployProcess(process.id, v as string, space.spaceId, 'dynamic');
if (!v) {
message.error('There is no version to deploy!');

return;
}

await deployProcess(process.id, v.id, space.spaceId, 'dynamic');
refetchDeployedProcesses();
} catch (e) {
message.error("Something wen't wrong");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,23 @@ import { Button as AntButton } from 'antd';
import { ReactNode } from 'react';

import { LuFormInput, LuImage, LuTable, LuText } from 'react-icons/lu';
import { MdCheckBox, MdRadioButtonChecked, MdTitle } from 'react-icons/md';
import { MdCheckBox, MdRadioButtonChecked, MdTitle, MdOutlineCheck } from 'react-icons/md';
import { RxGroup } from 'react-icons/rx';

import { useDraggable } from '@dnd-kit/core';

import styles from './index.module.scss';

import { Text, Container, Input, CheckBoxOrRadioGroup, Column, Table, Image } from '../elements';
import {
Text,
Container,
Input,
CheckBoxOrRadioGroup,
Column,
Table,
EditImage as Image,
SubmitButton,
} from '../elements';

import { createPortal } from 'react-dom';

Expand Down Expand Up @@ -92,6 +101,9 @@ const Toolbox = () => {
<CreationButton title="Image" icon={<LuImage />}>
<Image />
</CreationButton>
<CreationButton title="Submit" icon={<MdOutlineCheck />}>
<SubmitButton />
</CreationButton>
</div>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,20 +396,13 @@ export const CheckBoxOrRadioGroupSettings = () => {
<Setting
label="Variable"
control={
<Select
style={{ display: 'block' }}
options={[
{ value: 'var1', label: 'Var1' },
{ value: 'var2', label: 'Var2' },
{ value: 'var3', label: 'Var3' },
]}
<Input
value={variable}
disabled={!editingEnabled}
onChange={(val) =>
onChange={(e) => {
setProp((props: CheckBoxOrRadioGroupProps) => {
props.variable = val;
})
}
props.variable = e.target.value;
});
}}
/>
}
/>
Expand Down
Loading

0 comments on commit 5e698ff

Please sign in to comment.