Sequence diagram - donvadicastro/generator-xmi GitHub Wiki
-
inputState
is an process initial data - All actors injected into process through constructor injection
- Actions considered as async operations and returned
Promise
export class Flow {
constructor(
// Actor1
private cmpactor1: Actor1Contract,
// C1
private cmpc1: C1Contract,
// C2
private cmpc2: C2Contract) {}
/**
/* Execute process
*/
run(inputState: any) {
let flowAsync = Promise.resolve(inputState);
// Configure state storage
flowAsync = flowAsync.then((state: any) => {
return storage.init( /* options ... */ );
});
// actor1 call c1
flowAsync = flowAsync.then((state: any) => {
return this.cmpc1.fn1(state);
});
// c1 call c2
flowAsync = flowAsync.then((state: any) => {
return this.cmpc2.fn2(state);
});
// c2 call c1
flowAsync = flowAsync.then((state: any) => {
return this.cmpc1.ret1(state);
});
return flowAsync.catch(x => console.log(chalk.red('ERROR: '), x));
}
}
Loop condition is used to repeat certain sub-flow number of times based on loop condition check result.
When generated - component declaration is extended with additional properties:
-
loopCondition
- returns condition value to determine should be loop repeated or halted. -
loopDelay
- timeout between loop executions.
export abstract class C1Base extends ComponentBase implements C1Contract {
constructor() { super(); }
/**
* Loop condition.
* Check condition value to determine should be loop repeated or halted.
* When function returns TRUE - loop is going to be repeated.
*/
get loopCondition(): boolean {
return true;
}
/**
* Get loop delay in ms.
* This parameter is used to sleep between loop executions.
*/
get loopDelay(): number {
return 30 * 1000; //30 sec
}
/**
* op1 description.
*/
op1(state: any): Promise < any > {
...
}
}
"Alt condition" is used to choose execution flow based on specific condition(s). Many conditions can be applied to single "alt block", so on solution level condition block can be represented using "switch" pattern.
When generated - component declaration is extended with additional functions to check condition status
export abstract class ClassABase extends ComponentBase implements ClassAContract {
constructor() { super(); }
//# region Message conditions
'a >= b'(state: any) {
return true;
}
'a < b'(state: any) {
return true;
}
//# endregion
...
}
Sequence flow with check condition state to choose right flow
export class EaCollaboration1 {
constructor() { ... }
/**
/* Execute process
*/
run(inputState: any) {
let flowAsync = Promise.resolve(inputState);
// define flow
// Start call classA
flowAsync = flowAsync.then((state: any) => {
state.start = new Date();
return this.cmpclassA.afn1(state);
});
// classA call classB
flowAsync = flowAsync.then((state: any) => {
state.start = new Date();
return this.cmpclassB.bfn1(state);
});
// classA call classB
flowAsync = flowAsync.then((state: any) => {
state.start = new Date();
if (this.cmpclassA['a >= b'](state)) {
return this.cmpclassB.bfn2(state);
} else {
return state;
}
});
// classA call classB
flowAsync = flowAsync.then((state: any) => {
state.start = new Date();
if (this.cmpclassA['a < b'](state)) {
return this.cmpclassB.bfn3(state);
} else {
return state;
}
});
return flowAsync.catch(x => console.log(chalk.red('ERROR: '), x));
}
}
!!! Important "Alt condition" should be duplicated in message properties