From 84547d6aabdfa6ed96901ab652e811f637a107a6 Mon Sep 17 00:00:00 2001 From: Alexander Kantchev Date: Thu, 18 Jul 2024 11:30:21 +0300 Subject: [PATCH 01/67] [Task 340] Initial implementation of workflow error handler method decorator. Signed-off-by: Alexander Kantchev --- .../typescript/Components/Workflows.md | 56 +++++-- docs/versions/latest/Release.md | 143 +++++++++++----- .../e2e/cases/canvas-items/complex.wf.ts | 2 + .../cases/canvas-items/decision-edge-2.wf.ts | 5 +- .../cases/canvas-items/decision-edge.wf.ts | 5 +- .../cases/canvas-items/decision-happy.wf.ts | 5 +- .../default-error-handler-happy.wf.ts | 26 +++ .../canvas-items/root-default-first.wf.ts | 6 +- .../cases/canvas-items/root-when-set.wf.ts | 6 +- .../canvas-items/waiting-timer-edge-2.wf.ts | 6 +- .../canvas-items/waiting-timer-edge.wf.ts | 6 +- .../canvas-items/waiting-timer-happy.wf.ts | 6 +- .../e2e/cases/canvas-items/workflow.wf.ts | 16 +- .../@types/vrotsc-annotations/index.d.ts | 65 +++----- ...fault Error Handler Happy.element_info.xml | 9 ++ .../PSCoE/Default Error Handler Happy.xml | 1 + .../VMware/PSCoE/Waiting Timer Edge.xml | 2 +- .../workflows/VMware/PSCoE/Workflow Test.xml | 4 +- typescript/vrotsc/src/compiler/decorators.ts | 15 ++ .../fileTransformers/workflow/decorators.ts | 4 + .../defaultErrorHandlerDecoratorStrategy.ts | 152 ++++++++++++++++++ .../decorators/helpers/presentation.ts | 1 - vro-types/vrotsc-annotations/index.d.ts | 23 ++- 23 files changed, 447 insertions(+), 117 deletions(-) create mode 100644 typescript/vrotsc/e2e/cases/canvas-items/default-error-handler-happy.wf.ts create mode 100644 typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Default Error Handler Happy.element_info.xml create mode 100644 typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Default Error Handler Happy.xml create mode 100644 typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/defaultErrorHandlerDecoratorStrategy.ts diff --git a/docs/versions/latest/Components/Archetypes/typescript/Components/Workflows.md b/docs/versions/latest/Components/Archetypes/typescript/Components/Workflows.md index a9fc558fa..3ae86523e 100644 --- a/docs/versions/latest/Components/Archetypes/typescript/Components/Workflows.md +++ b/docs/versions/latest/Components/Archetypes/typescript/Components/Workflows.md @@ -12,6 +12,7 @@ How to use Aria Orchestrator Workflows and available decorators. - [`@WaitingTimerItem`](#waitingtimeritem) - [`@DecisionItem`](#decisionitem) - [`@RootItem`](#rootitem) + - [`@DefaultErrorHandler`](#defaultErrorHandler) 3. [Example Workflow](#example-workflow) ### Workflow Decorator @@ -20,6 +21,17 @@ Not implemented yet. ### Available Method Decorators +#### `@DefaultErrorHandler` + +The decorator is used to specify a default error handler within a workflow. + +##### Supported Parameters + +- `target` - **Not implemented yet** +- `exception` - Exception variable that will hold the exception data when triggered. + +In order to bind inputs and outputs, you do it with the `@In` and `@Out` decorators. This is the same way we do it for other items. + #### `@Item` This decorator is used to specify a scriptable task. @@ -64,28 +76,38 @@ This is a meta decorator. Add this to whichever function you want to be the entr ### Example Workflow ```ts -import { Workflow, Out, In, Item, RootItem, DecisionItem, WaitingTimerItem, WorkflowItem } from "vrotsc-annotations"; +import { + Workflow, + Out, + In, + Item, + RootItem, + DecisionItem, + WaitingTimerItem, + WorkflowItem, + DefaultErrorHandler, +} from "vrotsc-annotations"; @Workflow({ name: "Example Waiting Timer", path: "VMware/PSCoE", attributes: { waitingTimer: { - type: "Date" + type: "Date", }, counter: { - type: "number" + type: "number", }, first: { - type: "number" + type: "number", }, second: { - type: "number" + type: "number", }, result: { - type: "number" - } - } + type: "number", + }, + }, }) export class HandleNetworkConfigurationBackup { @DecisionItem({ target: "waitForEvent", else: "prepareItems" }) @@ -101,10 +123,13 @@ export class HandleNetworkConfigurationBackup { @WorkflowItem({ target: "print", - linkedItem: "9e4503db-cbaa-435a-9fad-144409c08df0" + linkedItem: "9e4503db-cbaa-435a-9fad-144409c08df0", }) - public callOtherWf(@In first: number, @In second: number, @Out result: number) { - } + public callOtherWf( + @In first: number, + @In second: number, + @Out result: number + ) {} @Item({ target: "end" }) public print(@In result: number) { @@ -118,7 +143,6 @@ export class HandleNetworkConfigurationBackup { } counter++; - if (counter < 2) { const tt = Date.now() + 5 * 1000; waitingTimer = new Date(tt); @@ -138,6 +162,14 @@ export class HandleNetworkConfigurationBackup { @WaitingTimerItem({ target: "execute" }) public waitForEvent(@In waitingTimer: Date) { + // NOOP + } + + @DefaultErrorHandler({ + exception: "errorMessage", + }) + public defaultErrorHandler(@Out errorMessage: string) { + // NOOP } } ``` diff --git a/docs/versions/latest/Release.md b/docs/versions/latest/Release.md index bc2f9cb59..0bacbdfdd 100644 --- a/docs/versions/latest/Release.md +++ b/docs/versions/latest/Release.md @@ -1,32 +1,78 @@ -[//]: # (VERSION_PLACEHOLDER DO NOT DELETE) -[//]: # (Used when working on a new release. Placed together with the Version.md) -[//]: # (Nothing here is optional. If a step must not be performed, it must be said so) -[//]: # (Do not fill the version, it will be done automatically) -[//]: # (Quick Intro to what is the focus of this release) +[//]: # "VERSION_PLACEHOLDER DO NOT DELETE" +[//]: # "Used when working on a new release. Placed together with the Version.md" +[//]: # "Nothing here is optional. If a step must not be performed, it must be said so" +[//]: # "Do not fill the version, it will be done automatically" +[//]: # "Quick Intro to what is the focus of this release" ## Breaking Changes -[//]: # (### *Breaking Change*) -[//]: # (Describe the breaking change AND explain how to resolve it) -[//]: # (You can utilize internal links /e.g. link to the upgrade procedure, link to the improvement|deprecation that introduced this/) +[//]: # "### *Breaking Change*" +[//]: # "Describe the breaking change AND explain how to resolve it" +[//]: # "You can utilize internal links /e.g. link to the upgrade procedure, link to the improvement|deprecation that introduced this/" ## Deprecations -[//]: # (### *Deprecation*) -[//]: # (Explain what is deprecated and suggest alternatives) - -[//]: # (Features -> New Functionality) +[//]: # "### *Deprecation*" +[//]: # "Explain what is deprecated and suggest alternatives" +[//]: # "Features -> New Functionality" ## Features -[//]: # (### *Feature Name*) -[//]: # (Describe the feature) -[//]: # (Optional But higlhy recommended Specify *NONE* if missing) -[//]: # (#### Relevant Documentation:) +[//]: # "### *Feature Name*" +[//]: # "Describe the feature" +[//]: # "Optional But highly recommended Specify *NONE* if missing" +[//]: # "#### Relevant Documentation:" +[//]: # "Improvements -> Bugfixes/hotfixes or general improvements" + +### \*New `DefaultErrorHandler` decorator for Workflows + +This decorator is used to specify a default error handler. Note that the default error handler will be generated +with its own end workflow item as it is required by the component. + +##### Supported Parameters + +- `target` - **Not implemented yet** +- `exception` - if set the variable will be bound to the error handler and its own end workflow component. + If set the end workflow component bound to the error handler will have exit code 1, otherwise the exit code will be 0. + +In order to bind inputs and outputs, you do it with the `@In` and `@Out` decorators. This is the same way we do it for other items. + +Example: + +```typescript +import { + Workflow, + Out, + RootItem, + DefaultErrorHandler, +} from "vrotsc-annotations"; + +@Workflow({ + name: "Default Error Handler Happy", + path: "VMware/PSCoE", + description: "Default error handler workflow", + attributes: { + errorMessage: { + type: "string", + }, + }, +}) +export class HandleDefaultError { + @RootItem() + public initiateWorkflow() { + // NOOP + } -[//]: # (Improvements -> Bugfixes/hotfixes or general improvements) + @DefaultErrorHandler({ + exception: "errorMessage", + }) + public defaultErrorHandler(@Out errorMessage: string) { + // NOOP + } +} +``` -### *New `WorkflowItem` decorator for Workflows +### \*New `WorkflowItem` decorator for Workflows The new Decorator gives you the ability to specify a canvas item that calls a Workflow. @@ -39,28 +85,37 @@ In order to bind inputs and outputs, you do it with the `@In` and `@Out` decorat Example: ```typescript -import { Workflow, Out, In, Item, RootItem, DecisionItem, WaitingTimerItem, WorkflowItem } from "vrotsc-annotations"; +import { + Workflow, + Out, + In, + Item, + RootItem, + DecisionItem, + WaitingTimerItem, + WorkflowItem, +} from "vrotsc-annotations"; @Workflow({ name: "Example Waiting Timer", path: "VMware/PSCoE", attributes: { waitingTimer: { - type: "Date" + type: "Date", }, counter: { - type: "number" + type: "number", }, first: { - type: "number" + type: "number", }, second: { - type: "number" + type: "number", }, result: { - type: "number" - } - } + type: "number", + }, + }, }) export class HandleNetworkConfigurationBackup { @DecisionItem({ target: "waitForEvent", else: "prepareItems" }) @@ -76,10 +131,13 @@ export class HandleNetworkConfigurationBackup { @WorkflowItem({ target: "print", - linkedItem: "9e4503db-cbaa-435a-9fad-144409c08df0" + linkedItem: "9e4503db-cbaa-435a-9fad-144409c08df0", }) - public callOtherWf(@In first: number, @In second: number, @Out result: number) { - } + public callOtherWf( + @In first: number, + @In second: number, + @Out result: number + ) {} @Item({ target: "end" }) public print(@In result: number) { @@ -112,25 +170,24 @@ export class HandleNetworkConfigurationBackup { } @WaitingTimerItem({ target: "execute" }) - public waitForEvent(@In waitingTimer: Date) { - } + public waitForEvent(@In waitingTimer: Date) {} } ``` ## Improvements -[//]: # (### *Improvement Name* ) -[//]: # (Talk ONLY regarding the improvement) -[//]: # (Optional But higlhy recommended) -[//]: # (#### Previous Behavior) -[//]: # (Explain how it used to behave, regarding to the change) -[//]: # (Optional But higlhy recommended) -[//]: # (#### New Behavior) -[//]: # (Explain how it behaves now, regarding to the change) -[//]: # (Optional But higlhy recommended Specify *NONE* if missing) -[//]: # (#### Relevant Documentation:) +[//]: # "### *Improvement Name* " +[//]: # "Talk ONLY regarding the improvement" +[//]: # "Optional But highly recommended" +[//]: # "#### Previous Behavior" +[//]: # "Explain how it used to behave, regarding to the change" +[//]: # "Optional But highly recommended" +[//]: # "#### New Behavior" +[//]: # "Explain how it behaves now, regarding to the change" +[//]: # "Optional But highly recommended Specify *NONE* if missing" +[//]: # "#### Relevant Documentation:" -### *ABX archetype build issue, cannot compile* +### _ABX archetype build issue, cannot compile_ Fixed an issue where the ABX archetype could not compile due to an old version of the `xmlbuilder2` package. @@ -174,4 +231,4 @@ The ABX archetype now compiles successfully. ## Upgrade procedure -[//]: # (Explain in details if something needs to be done) +[//]: # "Explain in details if something needs to be done" diff --git a/typescript/vrotsc/e2e/cases/canvas-items/complex.wf.ts b/typescript/vrotsc/e2e/cases/canvas-items/complex.wf.ts index b7b865815..a8a33e33e 100644 --- a/typescript/vrotsc/e2e/cases/canvas-items/complex.wf.ts +++ b/typescript/vrotsc/e2e/cases/canvas-items/complex.wf.ts @@ -13,6 +13,7 @@ import { Workflow, Out, In, Item, RootItem, DecisionItem, WaitingTimerItem } fro } }) export class Complex { + @DecisionItem({ target: "waitForEvent", else: null @@ -59,5 +60,6 @@ export class Complex { target: "execute" }) public waitForEvent(@In waitingTimer: Date) { + // NOOP } } diff --git a/typescript/vrotsc/e2e/cases/canvas-items/decision-edge-2.wf.ts b/typescript/vrotsc/e2e/cases/canvas-items/decision-edge-2.wf.ts index 67cbac9c5..f01c4e008 100644 --- a/typescript/vrotsc/e2e/cases/canvas-items/decision-edge-2.wf.ts +++ b/typescript/vrotsc/e2e/cases/canvas-items/decision-edge-2.wf.ts @@ -11,10 +11,13 @@ import { Workflow, DecisionItem } from "vrotsc-annotations"; } }) export class HandleNetworkConfigurationBackup { + @DecisionItem({}) public decisionElement(waitingTimer: Date) { return waitingTimer !== null; } - public shouldGoHere() { } + public shouldGoHere() { + // NOOP + } } diff --git a/typescript/vrotsc/e2e/cases/canvas-items/decision-edge.wf.ts b/typescript/vrotsc/e2e/cases/canvas-items/decision-edge.wf.ts index d3e0cfdcd..3b728a8ec 100644 --- a/typescript/vrotsc/e2e/cases/canvas-items/decision-edge.wf.ts +++ b/typescript/vrotsc/e2e/cases/canvas-items/decision-edge.wf.ts @@ -11,6 +11,7 @@ import { Workflow, DecisionItem } from "vrotsc-annotations"; } }) export class HandleNetworkConfigurationBackup { + @DecisionItem({ target: "waitForEvent", }) @@ -18,5 +19,7 @@ export class HandleNetworkConfigurationBackup { return waitingTimer !== null; } - public shouldGoHere() { } + public shouldGoHere() { + // NOOP + } } diff --git a/typescript/vrotsc/e2e/cases/canvas-items/decision-happy.wf.ts b/typescript/vrotsc/e2e/cases/canvas-items/decision-happy.wf.ts index ee81aa35b..9aec59374 100644 --- a/typescript/vrotsc/e2e/cases/canvas-items/decision-happy.wf.ts +++ b/typescript/vrotsc/e2e/cases/canvas-items/decision-happy.wf.ts @@ -11,6 +11,7 @@ import { Workflow, DecisionItem } from "vrotsc-annotations"; } }) export class HandleNetworkConfigurationBackup { + @DecisionItem({ target: "shouldGoHere", else: "end" @@ -20,5 +21,7 @@ export class HandleNetworkConfigurationBackup { } // This will point to end too, but no incoming - public shouldGoHere() { } + public shouldGoHere() { + // NOOP + } } diff --git a/typescript/vrotsc/e2e/cases/canvas-items/default-error-handler-happy.wf.ts b/typescript/vrotsc/e2e/cases/canvas-items/default-error-handler-happy.wf.ts new file mode 100644 index 000000000..4287ade41 --- /dev/null +++ b/typescript/vrotsc/e2e/cases/canvas-items/default-error-handler-happy.wf.ts @@ -0,0 +1,26 @@ +import { Workflow, Out, RootItem, DefaultErrorHandler } from "vrotsc-annotations"; + +@Workflow({ + name: "Default Error Handler Happy", + path: "VMware/PSCoE", + description: "Default error handler workflow", + attributes: { + errorMessage: { + type: "string" + } + } +}) +export class HandleDefaultError { + + @RootItem() + public initiateWorkflow() { + // NOOP + } + + @DefaultErrorHandler({ + exception: "errorMessage" + }) + public defaultErrorHandler(@Out errorMessage: string) { + // NOOP + } +} diff --git a/typescript/vrotsc/e2e/cases/canvas-items/root-default-first.wf.ts b/typescript/vrotsc/e2e/cases/canvas-items/root-default-first.wf.ts index 75e536c6a..a5c81dfb0 100644 --- a/typescript/vrotsc/e2e/cases/canvas-items/root-default-first.wf.ts +++ b/typescript/vrotsc/e2e/cases/canvas-items/root-default-first.wf.ts @@ -14,11 +14,15 @@ import { Workflow, In, Item } from "vrotsc-annotations"; } }) export class Complex { + @Item({ target: "end" }) public waitForEvent(@In waitingTimer: Date) { + // NOOP } - public shouldNotGoHere() { } + public shouldNotGoHere() { + // NOOP + } } diff --git a/typescript/vrotsc/e2e/cases/canvas-items/root-when-set.wf.ts b/typescript/vrotsc/e2e/cases/canvas-items/root-when-set.wf.ts index adb1f485f..2f323f2ff 100644 --- a/typescript/vrotsc/e2e/cases/canvas-items/root-when-set.wf.ts +++ b/typescript/vrotsc/e2e/cases/canvas-items/root-when-set.wf.ts @@ -14,12 +14,16 @@ import { Workflow, In, Item, RootItem } from "vrotsc-annotations"; } }) export class Complex { + @Item({ target: "end" }) public waitForEvent(@In waitingTimer: Date) { + // NOOP } @RootItem() - public shouldGoHere() { } + public shouldGoHere() { + // NOOP + } } diff --git a/typescript/vrotsc/e2e/cases/canvas-items/waiting-timer-edge-2.wf.ts b/typescript/vrotsc/e2e/cases/canvas-items/waiting-timer-edge-2.wf.ts index c008d9023..e8b2dfaff 100644 --- a/typescript/vrotsc/e2e/cases/canvas-items/waiting-timer-edge-2.wf.ts +++ b/typescript/vrotsc/e2e/cases/canvas-items/waiting-timer-edge-2.wf.ts @@ -14,9 +14,13 @@ import { Workflow, In, WaitingTimerItem } from "vrotsc-annotations"; } }) export class Complex { + @WaitingTimerItem({}) public waitForEvent(@In waitingTimer: Date) { + // NOOP } - public shouldGoHere() { } + public shouldGoHere() { + // NOOP + } } diff --git a/typescript/vrotsc/e2e/cases/canvas-items/waiting-timer-edge.wf.ts b/typescript/vrotsc/e2e/cases/canvas-items/waiting-timer-edge.wf.ts index ae891331b..936eede2e 100644 --- a/typescript/vrotsc/e2e/cases/canvas-items/waiting-timer-edge.wf.ts +++ b/typescript/vrotsc/e2e/cases/canvas-items/waiting-timer-edge.wf.ts @@ -14,11 +14,15 @@ import { Workflow, In, WaitingTimerItem } from "vrotsc-annotations"; } }) export class Complex { + @WaitingTimerItem({ target: "shouldGoHere", }) public waitForEvent(@In waitingTimer: Date) { + // NOOP } - public shoulNotdGoHere() { } + public shouldNotGoHere() { + // NOOP + } } diff --git a/typescript/vrotsc/e2e/cases/canvas-items/waiting-timer-happy.wf.ts b/typescript/vrotsc/e2e/cases/canvas-items/waiting-timer-happy.wf.ts index 100463595..8cb95fa1d 100644 --- a/typescript/vrotsc/e2e/cases/canvas-items/waiting-timer-happy.wf.ts +++ b/typescript/vrotsc/e2e/cases/canvas-items/waiting-timer-happy.wf.ts @@ -14,11 +14,15 @@ import { Workflow, In, WaitingTimerItem } from "vrotsc-annotations"; } }) export class Complex { + @WaitingTimerItem({ target: "shouldGoHere" }) public waitForEvent(@In waitingTimer: Date) { + // NOOP } - public shouldGoHere() { } + public shouldGoHere() { + // NOOP + } } diff --git a/typescript/vrotsc/e2e/cases/canvas-items/workflow.wf.ts b/typescript/vrotsc/e2e/cases/canvas-items/workflow.wf.ts index 65ac8bae9..1029645d9 100644 --- a/typescript/vrotsc/e2e/cases/canvas-items/workflow.wf.ts +++ b/typescript/vrotsc/e2e/cases/canvas-items/workflow.wf.ts @@ -1,4 +1,4 @@ -import { Workflow, Out, In, Item, RootItem, DecisionItem, WaitingTimerItem, WorkflowItem } from "vrotsc-annotations"; +import { Workflow, Out, In, Item, RootItem, DecisionItem, DefaultErrorHandler, WaitingTimerItem, WorkflowItem } from "vrotsc-annotations"; @Workflow({ name: "Workflow Test", @@ -19,10 +19,14 @@ import { Workflow, Out, In, Item, RootItem, DecisionItem, WaitingTimerItem, Work }, result: { type: "number" + }, + errorMessage: { + type: "string" } } }) export class HandleNetworkConfigurationBackup { + @DecisionItem({ target: "waitForEvent", else: "prepareItems" }) public decisionElement(waitingTimer: Date) { return waitingTimer !== null; @@ -39,6 +43,7 @@ export class HandleNetworkConfigurationBackup { linkedItem: "9e4503db-cbaa-435a-9fad-144409c08df0" }) public callOtherWf(@In first: number, @In second: number, @Out result: number) { + // NOOP } @Item({ target: "end" }) @@ -53,7 +58,6 @@ export class HandleNetworkConfigurationBackup { } counter++; - if (counter < 2) { const tt = Date.now() + 5 * 1000; waitingTimer = new Date(tt); @@ -73,5 +77,13 @@ export class HandleNetworkConfigurationBackup { @WaitingTimerItem({ target: "execute" }) public waitForEvent(@In waitingTimer: Date) { + // NOOP + } + + @DefaultErrorHandler({ + exception: "errorMessage" + }) + public defaultErrorHandler(@Out errorMessage: string) { + // NOOP } } diff --git a/typescript/vrotsc/e2e/cases/node_modules/@types/vrotsc-annotations/index.d.ts b/typescript/vrotsc/e2e/cases/node_modules/@types/vrotsc-annotations/index.d.ts index e284c0710..bc6604733 100644 --- a/typescript/vrotsc/e2e/cases/node_modules/@types/vrotsc-annotations/index.d.ts +++ b/typescript/vrotsc/e2e/cases/node_modules/@types/vrotsc-annotations/index.d.ts @@ -127,6 +127,8 @@ type CompositeType = { type AttributeValue = CompositeType | SupportedValues | SupportedValues[]; +type WorkflowEndMode = 0 | 1; + type Attribute = { type: string, value?: AttributeValue; @@ -186,15 +188,6 @@ interface VroWaitingTimerItemMethodDecorator { >(type: T): T; (target: Object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor): void; } -// -// -// -// -// -// -// -// -// // ---------------------------------------------- Workflow Canvas Decision Item ------------------------------------------------ @@ -215,17 +208,6 @@ interface VroDecisionItemMethodDecorator { (target: Object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor): void; } -// -// -// -// -// -// -// -// -// -// - // ---------------------------------------------- Workflow Canvas Root Item ------------------------------------------------ export declare const RootItem: VroRootItemDecorator; @@ -243,17 +225,6 @@ interface VroRootItemMethodDecorator { (target: Object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor): void; } -// -// -// -// -// -// -// -// -// -// - // ---------------------------------------------- Workflow Canvas Item ------------------------------------------------ export declare const WorkflowItem: VroWorkflowItemDecorator; @@ -273,19 +244,19 @@ interface VroWorkflowItemMethodDecorator { (target: Object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor): void; } -// -// -// -// -// -// -// -// -// -// -// -// -// +// ---------------------------------------------- Workflow Default Error Handler Canvas Item ------------------------------------------------ + +export declare const DefaultErrorHandler: VroWorkflowDefaultErrorHandlerDecorator; + +interface VroWorkflowDefaultErrorHandlerDecorator { + (obj?: VroItemConfiguration): VroWorkflowDefaultErrorHandlerMethodDecorator; + new(obj?: VroItemConfiguration): VroItemConfiguration; +} + +interface VroWorkflowDefaultErrorHandlerMethodDecorator { + >(type: T): T; + (target: Object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor): void; +} //--------------------------------------------- POLYGLOT ------------------------------------------------------------------------------- export declare const Polyglot: VroPolyglotDecorator; @@ -295,7 +266,11 @@ interface VroPolyglotDecorator { new(obj?: VroPolyglotConfiguration): VroPolyglotConfiguration; } -interface VroPolyglotConfiguration { package: string, method: string; } +interface VroPolyglotConfiguration { + package: string, + method: string; +} + interface PolyglotMethodDecorator { >(type: T): T; (target: Object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor): void; diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Default Error Handler Happy.element_info.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Default Error Handler Happy.element_info.xml new file mode 100644 index 000000000..9ba232839 --- /dev/null +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Default Error Handler Happy.element_info.xml @@ -0,0 +1,9 @@ + + + +Generated by vrotsc +VMware.PSCoE +Default Error Handler Happy +Workflow +e0145a6f-f13f-382f-aa56-674a70accad9 + diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Default Error Handler Happy.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Default Error Handler Happy.xml new file mode 100644 index 000000000..2d26875a1 --- /dev/null +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Default Error Handler Happy.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waiting Timer Edge.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waiting Timer Edge.xml index 2552e375b..86d7b7d16 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waiting Timer Edge.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waiting Timer Edge.xml @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow Test.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow Test.xml index 13d94b12e..c042c278c 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow Test.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow Test.xml @@ -1,4 +1,4 @@ - \ No newline at end of file +]]> \ No newline at end of file diff --git a/typescript/vrotsc/src/compiler/decorators.ts b/typescript/vrotsc/src/compiler/decorators.ts index 997d84e61..7747ab4f3 100644 --- a/typescript/vrotsc/src/compiler/decorators.ts +++ b/typescript/vrotsc/src/compiler/decorators.ts @@ -58,6 +58,7 @@ export interface WorkflowItemDescriptor { canvasItemPolymorphicBag: T; polyglot?: PolyglotDescriptor; parent: WorkflowDescriptor; + type?: WorkflowItemType; } export interface CanvasItemPolymorphicBagForItem { @@ -127,6 +128,20 @@ export enum WorkflowItemType { * It can target a specific item and accepts input and output bindings */ Workflow = "WorkflowItem", + + /** + * This item type represents a workflow end item + * + * It accepts input and output bindings. + */ + End = "WorkflowEndItem", + + /** + * This item type represents a default error handler item. + * + * It must target a workflow end item and accepts output bindings. + */ + DefaultErrorHandler = "DefaultErrorHandler", } /////////////////////////////////// Polyglot Decorator /////////////////////////////////// diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators.ts index 8f79f74dc..be09c1eb9 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators.ts @@ -23,6 +23,8 @@ import RootItemDecoratorStrategy from "./decorators/rootItemDecoratorStrategy"; import WaitingTimerItemDecoratorStrategy from "./decorators/waitingTimerItemDecoratorStrategy"; import DecisionItemDecoratorStrategy from "./decorators/decisionItemDecoratorStrategy"; import WorkflowItemDecoratorStrategy from "./decorators/workflowItemDecoratorStrategy"; +import DefaultErrorHandlerDecoratorStrategy from "./decorators/defaultErrorHandlerDecoratorStrategy"; + /** * Fetches details from the decorators for the methods and adds the information to the Descriptors @@ -84,6 +86,8 @@ function getItemStrategy(decoratorNode: ts.Decorator): CanvasItemDecoratorStrate return new WorkflowItemDecoratorStrategy(); case WorkflowItemType.RootItem: return new RootItemDecoratorStrategy(); + case WorkflowItemType.DefaultErrorHandler: + return new DefaultErrorHandlerDecoratorStrategy(); default: throw new Error(`Invalid decorator type: ${identifierText}`); } diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/defaultErrorHandlerDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/defaultErrorHandlerDecoratorStrategy.ts new file mode 100644 index 000000000..b4ef3bf25 --- /dev/null +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/defaultErrorHandlerDecoratorStrategy.ts @@ -0,0 +1,152 @@ +/*- + * #%L + * vrotsc + * %% + * Copyright (C) 2023 - 2024 VMware + * %% + * Build Tools for VMware Aria + * Copyright 2023 VMware, Inc. + * + * This product is licensed to you under the BSD-2 license (the "License"). You may not use this product except in compliance with the BSD-2 License. + * + * This product may include a number of subcomponents with separate copyright notices and license terms. Your use of these subcomponents is subject to the terms and conditions of the subcomponent's license, as noted in the LICENSE file. + * #L% + */ +import { Decorator, MethodDeclaration, SourceFile } from "typescript"; +import { StringBuilderClass } from "../../../../../utilities/stringBuilder"; +import { WorkflowItemDescriptor, WorkflowItemType } from "../../../../decorators"; +import { getDecoratorProps } from "../../../helpers/node"; +import { findTargetItem } from "../helpers/findTargetItem"; +import CanvasItemDecoratorStrategy from "./canvasItemDecoratorStrategy"; +import { buildItemParameterBindings, InputOutputBindings } from "./helpers/presentation"; + +// UI positioning constants in the output XML file. +const xBasePosition = 180; +const yBasePosition = 110; +const offSet = 20; + +/** + * Responsible for printing out a default error handler + * Important Note: The name of the error handler component should match the name of the end workflow element. + * @example + * ```xml + + + + + + + * ``` + */ +export default class DefaultErrorHandlerDecoratorStrategy implements CanvasItemDecoratorStrategy { + + /** + * Return XML tag for the error handler workflow item. + * + * @returns XML tag name. + */ + public getCanvasType(): string { + return "error-handler"; + } + + /** + * Return the workflow item type supported by this decorator. + * + * @returns type of the workflow element. + */ + public getDecoratorType(): WorkflowItemType { + return WorkflowItemType.DefaultErrorHandler; + } + + /** + * Register the canvas item arguments. For the default error handler only "target" and "exception" are supported. + * + * @param itemInfo item info for that properties should be fetched. + * @param decoratorNode decorator node handle. + */ + public registerItemArguments(itemInfo: WorkflowItemDescriptor, decoratorNode: Decorator): void { + const decoratorProperties: [string, any][] = getDecoratorProps(decoratorNode); + if (!decoratorProperties?.length) { + return; + } + decoratorProperties.forEach((propTuple) => { + const [propName, propValue] = propTuple; + switch (propName) { + case "target": { + itemInfo.target = propValue; + break; + } + case "exception": { + itemInfo.canvasItemPolymorphicBag.exception = propValue; + break; + } + default: { + throw new Error(`Item attribute '${propName}' is not supported for ${this.getDecoratorType()} item`); + } + } + }); + } + + /** + * There is no need to print the source file for the default error handler. + */ + public printSourceFile(methodNode: MethodDeclaration, sourceFile: SourceFile): string { + return ""; + } + + /** + * Prints out the default handler item. Note that it needs to be connected with an end item and + * both must have identical name. + * + * @param itemInfo The item to print. + * @param pos The position of the item in the workflow. + * + * @returns The string representation of the item. + */ + public printItem(itemInfo: WorkflowItemDescriptor, pos: number): string { + const stringBuilder = new StringBuilderClass("", ""); + + const targetItem = findTargetItem(itemInfo.target, pos, itemInfo); + if (targetItem === null) { + throw new Error(`Unable to find target item for ${this.getDecoratorType()} item`); + } + const exceptionVariable = itemInfo?.canvasItemPolymorphicBag?.exception; + // attach error handler with attaching of exception variable if defined + if (exceptionVariable !== null) { + stringBuilder.append(``).appendLine(); + } else { + stringBuilder.append(``).appendLine(); + } + stringBuilder.indent(); + stringBuilder.append(``).appendLine(); + stringBuilder.unindent(); + stringBuilder.append("").appendLine(); + + // attach a default end item to the error handler, note that the name of the end item and the error handler should be the same + const defaultEndItem = this.buildDefaultEndItem(itemInfo, pos, exceptionVariable); + stringBuilder.append(defaultEndItem); + stringBuilder.unindent(); + + return stringBuilder.toString(); + } + + private buildDefaultEndItem(itemInfo: WorkflowItemDescriptor, pos: number, exceptionVariable: string): string { + const stringBuilder = new StringBuilderClass("", ""); + + if (exceptionVariable !== null) { + stringBuilder.append(``).appendLine(); + } else { + stringBuilder.append(``).appendLine(); + } + stringBuilder.indent(); + stringBuilder.appendContent(buildItemParameterBindings(itemInfo, InputOutputBindings.IN_BINDINGS)); + stringBuilder.appendContent(buildItemParameterBindings(itemInfo, InputOutputBindings.OUT_BINDINGS)); + stringBuilder.unindent(); + stringBuilder.indent(); + stringBuilder.append(``).appendLine(); + stringBuilder.unindent(); + stringBuilder.append(``).appendLine(); + + return stringBuilder.toString(); + } +} diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/helpers/presentation.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/helpers/presentation.ts index d5eed7c8e..046a61061 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/helpers/presentation.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/helpers/presentation.ts @@ -46,7 +46,6 @@ export function buildItemParameterBindings( const param = itemInfo.parent.parameters.find((p: WorkflowParameter) => p.name === paramName); if (param) { const isWaitingTimer = itemInfo.strategy.getDecoratorType() === WorkflowItemType.WaitingTimer; - stringBuilder.append(``).appendLine(); } }); diff --git a/vro-types/vrotsc-annotations/index.d.ts b/vro-types/vrotsc-annotations/index.d.ts index 8ed98331a..bc6604733 100644 --- a/vro-types/vrotsc-annotations/index.d.ts +++ b/vro-types/vrotsc-annotations/index.d.ts @@ -127,6 +127,8 @@ type CompositeType = { type AttributeValue = CompositeType | SupportedValues | SupportedValues[]; +type WorkflowEndMode = 0 | 1; + type Attribute = { type: string, value?: AttributeValue; @@ -206,7 +208,6 @@ interface VroDecisionItemMethodDecorator { (target: Object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor): void; } - // ---------------------------------------------- Workflow Canvas Root Item ------------------------------------------------ export declare const RootItem: VroRootItemDecorator; @@ -224,7 +225,6 @@ interface VroRootItemMethodDecorator { (target: Object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor): void; } - // ---------------------------------------------- Workflow Canvas Item ------------------------------------------------ export declare const WorkflowItem: VroWorkflowItemDecorator; @@ -244,6 +244,19 @@ interface VroWorkflowItemMethodDecorator { (target: Object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor): void; } +// ---------------------------------------------- Workflow Default Error Handler Canvas Item ------------------------------------------------ + +export declare const DefaultErrorHandler: VroWorkflowDefaultErrorHandlerDecorator; + +interface VroWorkflowDefaultErrorHandlerDecorator { + (obj?: VroItemConfiguration): VroWorkflowDefaultErrorHandlerMethodDecorator; + new(obj?: VroItemConfiguration): VroItemConfiguration; +} + +interface VroWorkflowDefaultErrorHandlerMethodDecorator { + >(type: T): T; + (target: Object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor): void; +} //--------------------------------------------- POLYGLOT ------------------------------------------------------------------------------- export declare const Polyglot: VroPolyglotDecorator; @@ -253,7 +266,11 @@ interface VroPolyglotDecorator { new(obj?: VroPolyglotConfiguration): VroPolyglotConfiguration; } -interface VroPolyglotConfiguration { package: string, method: string; } +interface VroPolyglotConfiguration { + package: string, + method: string; +} + interface PolyglotMethodDecorator { >(type: T): T; (target: Object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor): void; From 3d222aaae221f76826cb9f055827ef68afa0ed41 Mon Sep 17 00:00:00 2001 From: Alexander Kantchev Date: Thu, 18 Jul 2024 11:48:43 +0300 Subject: [PATCH 02/67] [Task 340] style: Formatting. Signed-off-by: Alexander Kantchev --- .../Archetypes/typescript/Components/Workflows.md | 2 +- docs/versions/latest/Release.md | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/versions/latest/Components/Archetypes/typescript/Components/Workflows.md b/docs/versions/latest/Components/Archetypes/typescript/Components/Workflows.md index 3ae86523e..ff796c472 100644 --- a/docs/versions/latest/Components/Archetypes/typescript/Components/Workflows.md +++ b/docs/versions/latest/Components/Archetypes/typescript/Components/Workflows.md @@ -12,7 +12,7 @@ How to use Aria Orchestrator Workflows and available decorators. - [`@WaitingTimerItem`](#waitingtimeritem) - [`@DecisionItem`](#decisionitem) - [`@RootItem`](#rootitem) - - [`@DefaultErrorHandler`](#defaultErrorHandler) + - [`@DefaultErrorHandler`](#defaulterrorhandler) 3. [Example Workflow](#example-workflow) ### Workflow Decorator diff --git a/docs/versions/latest/Release.md b/docs/versions/latest/Release.md index 0bacbdfdd..b1dd75a37 100644 --- a/docs/versions/latest/Release.md +++ b/docs/versions/latest/Release.md @@ -24,12 +24,12 @@ [//]: # "#### Relevant Documentation:" [//]: # "Improvements -> Bugfixes/hotfixes or general improvements" -### \*New `DefaultErrorHandler` decorator for Workflows +### New `DefaultErrorHandler` decorator for Workflows This decorator is used to specify a default error handler. Note that the default error handler will be generated with its own end workflow item as it is required by the component. -##### Supported Parameters +#### Supported Parameters - `target` - **Not implemented yet** - `exception` - if set the variable will be bound to the error handler and its own end workflow component. @@ -72,7 +72,7 @@ export class HandleDefaultError { } ``` -### \*New `WorkflowItem` decorator for Workflows +### New `WorkflowItem` decorator for Workflows The new Decorator gives you the ability to specify a canvas item that calls a Workflow. From 40adf1a056e581d0ae2e0eb674b47fe93a1b8ef4 Mon Sep 17 00:00:00 2001 From: Alexander Kantchev Date: Thu, 18 Jul 2024 15:32:50 +0300 Subject: [PATCH 03/67] [Task 340] Initial implementation of workflow end item. Signed-off-by: Alexander Kantchev --- .../typescript/Components/Workflows.md | 59 +++++-- docs/versions/latest/Release.md | 145 +++++++++++++----- .../canvas-items/end-item-exception.wf.ts | 30 ++++ .../cases/canvas-items/end-item-happy.wf.ts | 26 ++++ .../e2e/cases/canvas-items/workflow.wf.ts | 16 +- .../@types/vrotsc-annotations/index.d.ts | 63 +++----- .../Workflow End Exception.element_info.xml | 9 ++ .../VMware/PSCoE/Workflow End Exception.xml | 1 + .../PSCoE/Workflow End Happy.element_info.xml | 9 ++ .../VMware/PSCoE/Workflow End Happy.xml | 1 + .../workflows/VMware/PSCoE/Workflow Test.xml | 4 +- typescript/vrotsc/src/compiler/decorators.ts | 6 + .../fileTransformers/workflow/decorators.ts | 9 +- .../decorators/endItemDecoratorStrategy.ts | 108 +++++++++++++ vro-types/vrotsc-annotations/index.d.ts | 21 +++ 15 files changed, 405 insertions(+), 102 deletions(-) create mode 100644 typescript/vrotsc/e2e/cases/canvas-items/end-item-exception.wf.ts create mode 100644 typescript/vrotsc/e2e/cases/canvas-items/end-item-happy.wf.ts create mode 100644 typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Exception.element_info.xml create mode 100644 typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Exception.xml create mode 100644 typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Happy.element_info.xml create mode 100644 typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Happy.xml create mode 100644 typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/endItemDecoratorStrategy.ts diff --git a/docs/versions/latest/Components/Archetypes/typescript/Components/Workflows.md b/docs/versions/latest/Components/Archetypes/typescript/Components/Workflows.md index a9fc558fa..0138d41f6 100644 --- a/docs/versions/latest/Components/Archetypes/typescript/Components/Workflows.md +++ b/docs/versions/latest/Components/Archetypes/typescript/Components/Workflows.md @@ -20,6 +20,17 @@ Not implemented yet. ### Available Method Decorators +#### `@WorkflowEndItem` + +The decorator is used to specify a custom workflow end item. + +##### Supported Parameters + +- `endMode` - End mode of the component, could be one of 0 or 1, where 0 is exit success and 1 is error. +- `exception` - Exception variable that will hold the exception data when triggered. + +In order to bind inputs and outputs, you do it with the `@Out` decorator. This is the same way we do it for other items. + #### `@Item` This decorator is used to specify a scriptable task. @@ -64,28 +75,41 @@ This is a meta decorator. Add this to whichever function you want to be the entr ### Example Workflow ```ts -import { Workflow, Out, In, Item, RootItem, DecisionItem, WaitingTimerItem, WorkflowItem } from "vrotsc-annotations"; +import { + Workflow, + Out, + In, + Item, + RootItem, + DecisionItem, + WaitingTimerItem, + WorkflowItem, + WorkflowEndItem, +} from "vrotsc-annotations"; @Workflow({ name: "Example Waiting Timer", path: "VMware/PSCoE", attributes: { waitingTimer: { - type: "Date" + type: "Date", }, counter: { - type: "number" + type: "number", }, first: { - type: "number" + type: "number", }, second: { - type: "number" + type: "number", }, result: { - type: "number" - } - } + type: "number", + }, + errorMessage: { + type: "string", + }, + }, }) export class HandleNetworkConfigurationBackup { @DecisionItem({ target: "waitForEvent", else: "prepareItems" }) @@ -101,9 +125,14 @@ export class HandleNetworkConfigurationBackup { @WorkflowItem({ target: "print", - linkedItem: "9e4503db-cbaa-435a-9fad-144409c08df0" + linkedItem: "9e4503db-cbaa-435a-9fad-144409c08df0", }) - public callOtherWf(@In first: number, @In second: number, @Out result: number) { + public callOtherWf( + @In first: number, + @In second: number, + @Out result: number + ) { + // NOOP } @Item({ target: "end" }) @@ -118,7 +147,6 @@ export class HandleNetworkConfigurationBackup { } counter++; - if (counter < 2) { const tt = Date.now() + 5 * 1000; waitingTimer = new Date(tt); @@ -138,6 +166,15 @@ export class HandleNetworkConfigurationBackup { @WaitingTimerItem({ target: "execute" }) public waitForEvent(@In waitingTimer: Date) { + // NOOP + } + + @WorkflowEndItem({ + endMode: 0, + exception: "errorMessage", + }) + public workflowEnd(@In endMode: number, @Out errorMessage: string) { + // NOOP } } ``` diff --git a/docs/versions/latest/Release.md b/docs/versions/latest/Release.md index bc2f9cb59..ba7d91ba9 100644 --- a/docs/versions/latest/Release.md +++ b/docs/versions/latest/Release.md @@ -1,32 +1,81 @@ -[//]: # (VERSION_PLACEHOLDER DO NOT DELETE) -[//]: # (Used when working on a new release. Placed together with the Version.md) -[//]: # (Nothing here is optional. If a step must not be performed, it must be said so) -[//]: # (Do not fill the version, it will be done automatically) -[//]: # (Quick Intro to what is the focus of this release) +[//]: # "VERSION_PLACEHOLDER DO NOT DELETE" +[//]: # "Used when working on a new release. Placed together with the Version.md" +[//]: # "Nothing here is optional. If a step must not be performed, it must be said so" +[//]: # "Do not fill the version, it will be done automatically" +[//]: # "Quick Intro to what is the focus of this release" ## Breaking Changes -[//]: # (### *Breaking Change*) -[//]: # (Describe the breaking change AND explain how to resolve it) -[//]: # (You can utilize internal links /e.g. link to the upgrade procedure, link to the improvement|deprecation that introduced this/) +[//]: # "### *Breaking Change*" +[//]: # "Describe the breaking change AND explain how to resolve it" +[//]: # "You can utilize internal links /e.g. link to the upgrade procedure, link to the improvement|deprecation that introduced this/" ## Deprecations -[//]: # (### *Deprecation*) -[//]: # (Explain what is deprecated and suggest alternatives) - -[//]: # (Features -> New Functionality) +[//]: # "### *Deprecation*" +[//]: # "Explain what is deprecated and suggest alternatives" +[//]: # "Features -> New Functionality" ## Features -[//]: # (### *Feature Name*) -[//]: # (Describe the feature) -[//]: # (Optional But higlhy recommended Specify *NONE* if missing) -[//]: # (#### Relevant Documentation:) +[//]: # "### *Feature Name*" +[//]: # "Describe the feature" +[//]: # "Optional But highly recommended Specify *NONE* if missing" +[//]: # "#### Relevant Documentation:" +[//]: # "Improvements -> Bugfixes/hotfixes or general improvements" + +#### \*New `@WorkflowEndItem` decorator for Workflows + +The decorator is used to specify a custom workflow end item. + +##### Supported Parameters + +- `endMode` - End mode of the component, could be one of 0 or 1, where 0 is exit success and 1 is error. +- `exception` - Exception variable that will hold the exception data when triggered. + +In order to bind inputs and outputs, you do it with the `@Out` decorator. This is the same way we do it for other items. + +Example: + +```typescript +import { + Workflow, + In, + Out, + RootItem, + WorkflowEndItem, +} from "vrotsc-annotations"; + +@Workflow({ + name: "Workflow End Happy", + path: "VMware/PSCoE", + description: "Workflow with root and end item", + attributes: { + errorMessage: { + type: "string", + }, + endMode: { + type: "number", + }, + }, +}) +export class WorkflowEnd { + @RootItem() + public initiateWorkflow() { + // NOOP + } -[//]: # (Improvements -> Bugfixes/hotfixes or general improvements) + @WorkflowEndItem({ + endMode: 0, + exception: "errorMessage", + }) + public workflowEnd(@In endMode: number, @Out errorMessage: string) { + // NOOP + } +} +``` -### *New `WorkflowItem` decorator for Workflows +### \*New `WorkflowItem` decorator for Workflows The new Decorator gives you the ability to specify a canvas item that calls a Workflow. @@ -39,28 +88,37 @@ In order to bind inputs and outputs, you do it with the `@In` and `@Out` decorat Example: ```typescript -import { Workflow, Out, In, Item, RootItem, DecisionItem, WaitingTimerItem, WorkflowItem } from "vrotsc-annotations"; +import { + Workflow, + Out, + In, + Item, + RootItem, + DecisionItem, + WaitingTimerItem, + WorkflowItem, +} from "vrotsc-annotations"; @Workflow({ name: "Example Waiting Timer", path: "VMware/PSCoE", attributes: { waitingTimer: { - type: "Date" + type: "Date", }, counter: { - type: "number" + type: "number", }, first: { - type: "number" + type: "number", }, second: { - type: "number" + type: "number", }, result: { - type: "number" - } - } + type: "number", + }, + }, }) export class HandleNetworkConfigurationBackup { @DecisionItem({ target: "waitForEvent", else: "prepareItems" }) @@ -76,10 +134,13 @@ export class HandleNetworkConfigurationBackup { @WorkflowItem({ target: "print", - linkedItem: "9e4503db-cbaa-435a-9fad-144409c08df0" + linkedItem: "9e4503db-cbaa-435a-9fad-144409c08df0", }) - public callOtherWf(@In first: number, @In second: number, @Out result: number) { - } + public callOtherWf( + @In first: number, + @In second: number, + @Out result: number + ) {} @Item({ target: "end" }) public print(@In result: number) { @@ -93,7 +154,6 @@ export class HandleNetworkConfigurationBackup { } counter++; - if (counter < 2) { const tt = Date.now() + 5 * 1000; waitingTimer = new Date(tt); @@ -113,24 +173,25 @@ export class HandleNetworkConfigurationBackup { @WaitingTimerItem({ target: "execute" }) public waitForEvent(@In waitingTimer: Date) { + // NOOP } } ``` ## Improvements -[//]: # (### *Improvement Name* ) -[//]: # (Talk ONLY regarding the improvement) -[//]: # (Optional But higlhy recommended) -[//]: # (#### Previous Behavior) -[//]: # (Explain how it used to behave, regarding to the change) -[//]: # (Optional But higlhy recommended) -[//]: # (#### New Behavior) -[//]: # (Explain how it behaves now, regarding to the change) -[//]: # (Optional But higlhy recommended Specify *NONE* if missing) -[//]: # (#### Relevant Documentation:) +[//]: # "### *Improvement Name* " +[//]: # "Talk ONLY regarding the improvement" +[//]: # "Optional But highly recommended" +[//]: # "#### Previous Behavior" +[//]: # "Explain how it used to behave, regarding to the change" +[//]: # "Optional But highly recommended" +[//]: # "#### New Behavior" +[//]: # "Explain how it behaves now, regarding to the change" +[//]: # "Optional But highly recommended Specify *NONE* if missing" +[//]: # "#### Relevant Documentation:" -### *ABX archetype build issue, cannot compile* +### _ABX archetype build issue, cannot compile_ Fixed an issue where the ABX archetype could not compile due to an old version of the `xmlbuilder2` package. @@ -174,4 +235,4 @@ The ABX archetype now compiles successfully. ## Upgrade procedure -[//]: # (Explain in details if something needs to be done) +[//]: # "Explain in details if something needs to be done" diff --git a/typescript/vrotsc/e2e/cases/canvas-items/end-item-exception.wf.ts b/typescript/vrotsc/e2e/cases/canvas-items/end-item-exception.wf.ts new file mode 100644 index 000000000..a314eb341 --- /dev/null +++ b/typescript/vrotsc/e2e/cases/canvas-items/end-item-exception.wf.ts @@ -0,0 +1,30 @@ +import { Workflow, In, Out, RootItem, WorkflowEndItem } from "vrotsc-annotations"; + +@Workflow({ + name: "Workflow End Exception", + path: "VMware/PSCoE", + description: "Workflow with root and end item with end mode 1", + attributes: { + errorMessage: { + type: "string" + }, + endMode: { + type: "number" + } + } +}) +export class WorkflowEnd { + + @RootItem() + public initiateWorkflow() { + // NOOP + } + + @WorkflowEndItem({ + endMode: 1, + exception: "errorMessage" + }) + public workflowEnd(@In endMode: number, @Out errorMessage: string) { + // NOOP + } +} diff --git a/typescript/vrotsc/e2e/cases/canvas-items/end-item-happy.wf.ts b/typescript/vrotsc/e2e/cases/canvas-items/end-item-happy.wf.ts new file mode 100644 index 000000000..0b23186fa --- /dev/null +++ b/typescript/vrotsc/e2e/cases/canvas-items/end-item-happy.wf.ts @@ -0,0 +1,26 @@ +import { Workflow, In, Out, RootItem, WorkflowEndItem } from "vrotsc-annotations"; + +@Workflow({ + name: "Workflow End Happy", + path: "VMware/PSCoE", + description: "Workflow with root and end item", + attributes: { + endMode: { + type: "number" + } + } +}) +export class WorkflowEnd { + + @RootItem() + public initiateWorkflow() { + // NOOP + } + + @WorkflowEndItem({ + endMode: 0 + }) + public workflowEnd(@In endMode: number) { + // NOOP + } +} diff --git a/typescript/vrotsc/e2e/cases/canvas-items/workflow.wf.ts b/typescript/vrotsc/e2e/cases/canvas-items/workflow.wf.ts index 65ac8bae9..525088bcb 100644 --- a/typescript/vrotsc/e2e/cases/canvas-items/workflow.wf.ts +++ b/typescript/vrotsc/e2e/cases/canvas-items/workflow.wf.ts @@ -1,4 +1,4 @@ -import { Workflow, Out, In, Item, RootItem, DecisionItem, WaitingTimerItem, WorkflowItem } from "vrotsc-annotations"; +import { Workflow, Out, In, Item, RootItem, DecisionItem, WorkflowEndItem, WaitingTimerItem, WorkflowItem } from "vrotsc-annotations"; @Workflow({ name: "Workflow Test", @@ -19,6 +19,9 @@ import { Workflow, Out, In, Item, RootItem, DecisionItem, WaitingTimerItem, Work }, result: { type: "number" + }, + errorMessage: { + type: "string" } } }) @@ -39,6 +42,7 @@ export class HandleNetworkConfigurationBackup { linkedItem: "9e4503db-cbaa-435a-9fad-144409c08df0" }) public callOtherWf(@In first: number, @In second: number, @Out result: number) { + // NOOP } @Item({ target: "end" }) @@ -53,7 +57,6 @@ export class HandleNetworkConfigurationBackup { } counter++; - if (counter < 2) { const tt = Date.now() + 5 * 1000; waitingTimer = new Date(tt); @@ -73,5 +76,14 @@ export class HandleNetworkConfigurationBackup { @WaitingTimerItem({ target: "execute" }) public waitForEvent(@In waitingTimer: Date) { + // NOOP + } + + @WorkflowEndItem({ + endMode: 0, + exception: "errorMessage" + }) + public workflowEnd(@In endMode: number, @Out errorMessage: string) { + // NOOP } } diff --git a/typescript/vrotsc/e2e/cases/node_modules/@types/vrotsc-annotations/index.d.ts b/typescript/vrotsc/e2e/cases/node_modules/@types/vrotsc-annotations/index.d.ts index e284c0710..4c896f55f 100644 --- a/typescript/vrotsc/e2e/cases/node_modules/@types/vrotsc-annotations/index.d.ts +++ b/typescript/vrotsc/e2e/cases/node_modules/@types/vrotsc-annotations/index.d.ts @@ -117,6 +117,8 @@ interface VroPolicyTemplateDecorator { new(obj?: VroPolicyTemplate): VroPolicyTemplate; } +type WorkflowEndMode = 0 | 1; + export declare const PolicyTemplate: VroPolicyTemplateDecorator; type SupportedValues = string | boolean | number; @@ -186,15 +188,6 @@ interface VroWaitingTimerItemMethodDecorator { >(type: T): T; (target: Object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor): void; } -// -// -// -// -// -// -// -// -// // ---------------------------------------------- Workflow Canvas Decision Item ------------------------------------------------ @@ -215,16 +208,6 @@ interface VroDecisionItemMethodDecorator { (target: Object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor): void; } -// -// -// -// -// -// -// -// -// -// // ---------------------------------------------- Workflow Canvas Root Item ------------------------------------------------ @@ -243,16 +226,6 @@ interface VroRootItemMethodDecorator { (target: Object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor): void; } -// -// -// -// -// -// -// -// -// -// // ---------------------------------------------- Workflow Canvas Item ------------------------------------------------ @@ -273,19 +246,25 @@ interface VroWorkflowItemMethodDecorator { (target: Object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor): void; } -// -// -// -// -// -// -// -// -// -// -// -// -// + +// ---------------------------------------------- Workflow Canvas End Item ------------------------------------------------ + +export declare const WorkflowEndItem: VroWorkflowEndItemDecorator; + +interface VroWorkflowEndItemDecorator { + (obj?: VroWorkflowEndItemConfiguration): VroWorkflowEndItemMethodDecorator; + new(obj?: VroWorkflowEndItemConfiguration): VroWorkflowEndItemConfiguration; +} + +interface VroWorkflowEndItemConfiguration { + endMode?: WorkflowEndMode; + exception?: string; +} + +interface VroWorkflowEndItemMethodDecorator { + >(type: T): T; + (target: Object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor): void; +} //--------------------------------------------- POLYGLOT ------------------------------------------------------------------------------- export declare const Polyglot: VroPolyglotDecorator; diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Exception.element_info.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Exception.element_info.xml new file mode 100644 index 000000000..4156c9d2c --- /dev/null +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Exception.element_info.xml @@ -0,0 +1,9 @@ + + + +Generated by vrotsc +VMware.PSCoE +Workflow End Exception +Workflow +52bdb90f-2e9c-3ee7-a290-aae3156e1a25 + diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Exception.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Exception.xml new file mode 100644 index 000000000..1a28b30df --- /dev/null +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Exception.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Happy.element_info.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Happy.element_info.xml new file mode 100644 index 000000000..c6130e86b --- /dev/null +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Happy.element_info.xml @@ -0,0 +1,9 @@ + + + +Generated by vrotsc +VMware.PSCoE +Workflow End Happy +Workflow +c30ea279-5670-385c-838f-63adb8fec45a + diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Happy.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Happy.xml new file mode 100644 index 000000000..a3fc2aa58 --- /dev/null +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Happy.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow Test.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow Test.xml index 13d94b12e..df7ef01b1 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow Test.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow Test.xml @@ -1,4 +1,4 @@ - \ No newline at end of file +]]> \ No newline at end of file diff --git a/typescript/vrotsc/src/compiler/decorators.ts b/typescript/vrotsc/src/compiler/decorators.ts index 997d84e61..830b97cc8 100644 --- a/typescript/vrotsc/src/compiler/decorators.ts +++ b/typescript/vrotsc/src/compiler/decorators.ts @@ -127,6 +127,12 @@ export enum WorkflowItemType { * It can target a specific item and accepts input and output bindings */ Workflow = "WorkflowItem", + + /** + * This item type represents a workflow end item. + * + */ + End = "WorkflowEndItem", } /////////////////////////////////// Polyglot Decorator /////////////////////////////////// diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators.ts index 8f79f74dc..04f678bc9 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators.ts @@ -13,15 +13,16 @@ * #L% */ import * as ts from "typescript"; -import { getDecoratorNames, getIdentifierTextOrNull, getPropertyName } from "../../helpers/node"; +import { DiagnosticCategory, FileTransformationContext } from "../../../../types"; import { PolyglotDescriptor, WorkflowDescriptor, WorkflowItemDescriptor, WorkflowItemType, WorkflowParameter, WorkflowParameterType } from "../../../decorators"; +import { getDecoratorNames, getIdentifierTextOrNull, getPropertyName } from "../../helpers/node"; import { getVroType } from "../../helpers/vro"; -import { DiagnosticCategory, FileTransformationContext } from "../../../../types"; import CanvasItemDecoratorStrategy from "./decorators/canvasItemDecoratorStrategy"; +import DecisionItemDecoratorStrategy from "./decorators/decisionItemDecoratorStrategy"; +import EndItemDecoratorStrategy from "./decorators/endItemDecoratorStrategy"; import ItemDecoratorStrategy from "./decorators/itemDecoratorStrategy"; import RootItemDecoratorStrategy from "./decorators/rootItemDecoratorStrategy"; import WaitingTimerItemDecoratorStrategy from "./decorators/waitingTimerItemDecoratorStrategy"; -import DecisionItemDecoratorStrategy from "./decorators/decisionItemDecoratorStrategy"; import WorkflowItemDecoratorStrategy from "./decorators/workflowItemDecoratorStrategy"; /** @@ -84,6 +85,8 @@ function getItemStrategy(decoratorNode: ts.Decorator): CanvasItemDecoratorStrate return new WorkflowItemDecoratorStrategy(); case WorkflowItemType.RootItem: return new RootItemDecoratorStrategy(); + case WorkflowItemType.End: + return new EndItemDecoratorStrategy(); default: throw new Error(`Invalid decorator type: ${identifierText}`); } diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/endItemDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/endItemDecoratorStrategy.ts new file mode 100644 index 000000000..e895eaaf7 --- /dev/null +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/endItemDecoratorStrategy.ts @@ -0,0 +1,108 @@ +/*- + * #%L + * vrotsc + * %% + * Copyright (C) 2023 - 2024 VMware + * %% + * Build Tools for VMware Aria + * Copyright 2023 VMware, Inc. + * + * This product is licensed to you under the BSD-2 license (the "License"). You may not use this product except in compliance with the BSD-2 License. + * + * This product may include a number of subcomponents with separate copyright notices and license terms. Your use of these subcomponents is subject to the terms and conditions of the subcomponent's license, as noted in the LICENSE file. + * #L% + */ +import { Decorator, MethodDeclaration, SourceFile } from "typescript"; +import { StringBuilderClass } from "../../../../../utilities/stringBuilder"; +import { WorkflowItemDescriptor, WorkflowItemType } from "../../../../decorators"; +import { getDecoratorProps } from "../../../helpers/node"; +import CanvasItemDecoratorStrategy from "./canvasItemDecoratorStrategy"; +import { buildItemParameterBindings, InputOutputBindings } from "./helpers/presentation"; + +// UI positioning constants in the output XML file. +const xBasePosition = 160; +const yBasePosition = 100; +const offSet = 20; + +export default class EndItemDecoratorStrategy implements CanvasItemDecoratorStrategy { + /** + * Return XML tag for the end workflow item. + * + * @returns XML tag name. + */ + getCanvasType(): string { + return "end"; + } + + /** + * Return the workflow item type supported by this decorator. + * + * @returns type of the workflow element. + */ + getDecoratorType(): WorkflowItemType { + return WorkflowItemType.End; + } + + /** + * Register the canvas item arguments. For the default error handler only "endMode" and "exception" are supported. + * + * @param itemInfo item info for that properties should be fetched. + * @param decoratorNode decorator node handle. + */ + registerItemArguments(itemInfo: WorkflowItemDescriptor, decoratorNode: Decorator): void { + const decoratorProperties: [string, any][] = getDecoratorProps(decoratorNode); + if (!decoratorProperties?.length) { + return; + } + decoratorProperties.forEach((propTuple) => { + const [propName, propValue] = propTuple; + switch (propName) { + case "endMode": { + itemInfo.canvasItemPolymorphicBag.endMode = propValue; + break; + } + case "exception": { + itemInfo.canvasItemPolymorphicBag.exception = propValue; + break; + } + default: { + throw new Error(`Item attribute '${propName}' is not supported for ${this.getDecoratorType()} item`); + } + } + }); + } + + /** + * There is no need to print the source file for the workflow item. + */ + printSourceFile(methodNode: MethodDeclaration, sourceFile: SourceFile): string { + return ""; + } + + /** + * Prints out the end item. + * + * @param itemInfo The item to print. + * @param pos The position of the item in the workflow. + * + * @returns The string representation of the item. + */ + printItem(itemInfo: WorkflowItemDescriptor, pos: number): string { + const stringBuilder = new StringBuilderClass("", ""); + + const endMode = itemInfo?.canvasItemPolymorphicBag?.endMode; + const exceptionVariable = itemInfo?.canvasItemPolymorphicBag?.exception; + if (exceptionVariable !== null && exceptionVariable !== undefined && exceptionVariable) { + stringBuilder.append(``).appendLine(); + } else { + stringBuilder.append(``).appendLine(); + } + stringBuilder.indent(); + stringBuilder.appendContent(buildItemParameterBindings(itemInfo, InputOutputBindings.OUT_BINDINGS)); + stringBuilder.append(``).appendLine(); + stringBuilder.unindent(); + stringBuilder.append(``).appendLine(); + + return stringBuilder.toString(); + } +} diff --git a/vro-types/vrotsc-annotations/index.d.ts b/vro-types/vrotsc-annotations/index.d.ts index 8ed98331a..4c896f55f 100644 --- a/vro-types/vrotsc-annotations/index.d.ts +++ b/vro-types/vrotsc-annotations/index.d.ts @@ -117,6 +117,8 @@ interface VroPolicyTemplateDecorator { new(obj?: VroPolicyTemplate): VroPolicyTemplate; } +type WorkflowEndMode = 0 | 1; + export declare const PolicyTemplate: VroPolicyTemplateDecorator; type SupportedValues = string | boolean | number; @@ -245,6 +247,25 @@ interface VroWorkflowItemMethodDecorator { } +// ---------------------------------------------- Workflow Canvas End Item ------------------------------------------------ + +export declare const WorkflowEndItem: VroWorkflowEndItemDecorator; + +interface VroWorkflowEndItemDecorator { + (obj?: VroWorkflowEndItemConfiguration): VroWorkflowEndItemMethodDecorator; + new(obj?: VroWorkflowEndItemConfiguration): VroWorkflowEndItemConfiguration; +} + +interface VroWorkflowEndItemConfiguration { + endMode?: WorkflowEndMode; + exception?: string; +} + +interface VroWorkflowEndItemMethodDecorator { + >(type: T): T; + (target: Object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor): void; +} + //--------------------------------------------- POLYGLOT ------------------------------------------------------------------------------- export declare const Polyglot: VroPolyglotDecorator; From 0f96880d029bbe9d3266f305a391bf141c941bba Mon Sep 17 00:00:00 2001 From: Alexander Kantchev Date: Thu, 18 Jul 2024 15:39:43 +0300 Subject: [PATCH 04/67] [Task 340] docs: Updated md files. Signed-off-by: Alexander Kantchev --- docs/versions/latest/Release.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/versions/latest/Release.md b/docs/versions/latest/Release.md index ba7d91ba9..fa809cb37 100644 --- a/docs/versions/latest/Release.md +++ b/docs/versions/latest/Release.md @@ -24,7 +24,7 @@ [//]: # "#### Relevant Documentation:" [//]: # "Improvements -> Bugfixes/hotfixes or general improvements" -#### \*New `@WorkflowEndItem` decorator for Workflows +### \*New `@WorkflowEndItem` decorator for Workflows The decorator is used to specify a custom workflow end item. @@ -66,7 +66,7 @@ export class WorkflowEnd { } @WorkflowEndItem({ - endMode: 0, + endMode: 1, exception: "errorMessage", }) public workflowEnd(@In endMode: number, @Out errorMessage: string) { From da113662220f14fea9840f115d86d5f15eba113a Mon Sep 17 00:00:00 2001 From: Alexander Kantchev Date: Thu, 18 Jul 2024 15:43:40 +0300 Subject: [PATCH 05/67] [Task 339] code: Added handling of corner cases. Signed-off-by: Alexander Kantchev --- .../decorators/defaultErrorHandlerDecoratorStrategy.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/defaultErrorHandlerDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/defaultErrorHandlerDecoratorStrategy.ts index b4ef3bf25..f667e5ae8 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/defaultErrorHandlerDecoratorStrategy.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/defaultErrorHandlerDecoratorStrategy.ts @@ -112,7 +112,7 @@ export default class DefaultErrorHandlerDecoratorStrategy implements CanvasItemD } const exceptionVariable = itemInfo?.canvasItemPolymorphicBag?.exception; // attach error handler with attaching of exception variable if defined - if (exceptionVariable !== null) { + if (exceptionVariable !== null && exceptionVariable !== undefined && exceptionVariable) { stringBuilder.append(``).appendLine(); } else { stringBuilder.append(``).appendLine(); @@ -133,7 +133,7 @@ export default class DefaultErrorHandlerDecoratorStrategy implements CanvasItemD private buildDefaultEndItem(itemInfo: WorkflowItemDescriptor, pos: number, exceptionVariable: string): string { const stringBuilder = new StringBuilderClass("", ""); - if (exceptionVariable !== null) { + if (exceptionVariable !== null && exceptionVariable !== undefined && exceptionVariable) { stringBuilder.append(``).appendLine(); } else { stringBuilder.append(``).appendLine(); From fadec02e0b8486acff40e651810067c369a0cb4d Mon Sep 17 00:00:00 2001 From: Alexander Kantchev Date: Thu, 18 Jul 2024 15:45:58 +0300 Subject: [PATCH 06/67] [Task 340] docs: Updated formatting. Signed-off-by: Alexander Kantchev --- docs/versions/latest/Release.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/versions/latest/Release.md b/docs/versions/latest/Release.md index fa809cb37..58962fbc2 100644 --- a/docs/versions/latest/Release.md +++ b/docs/versions/latest/Release.md @@ -28,7 +28,7 @@ The decorator is used to specify a custom workflow end item. -##### Supported Parameters +#### Supported Parameters - `endMode` - End mode of the component, could be one of 0 or 1, where 0 is exit success and 1 is error. - `exception` - Exception variable that will hold the exception data when triggered. From 23cc51e489a65109d218f10d61302995227f9b76 Mon Sep 17 00:00:00 2001 From: Alexander Kantchev Date: Thu, 18 Jul 2024 16:55:31 +0300 Subject: [PATCH 07/67] [Task 340] code: Added support for business status. Signed-off-by: Alexander Kantchev --- .../canvas-items/end-item-exception.wf.ts | 6 +++++- .../@types/vrotsc-annotations/index.d.ts | 1 + .../VMware/PSCoE/Workflow End Exception.xml | 2 +- .../VMware/PSCoE/Workflow End Happy.xml | 2 +- .../workflows/VMware/PSCoE/Workflow Test.xml | 2 +- .../decorators/endItemDecoratorStrategy.ts | 19 +++++++++++++++---- vro-types/vrotsc-annotations/index.d.ts | 1 + 7 files changed, 25 insertions(+), 8 deletions(-) diff --git a/typescript/vrotsc/e2e/cases/canvas-items/end-item-exception.wf.ts b/typescript/vrotsc/e2e/cases/canvas-items/end-item-exception.wf.ts index a314eb341..2032cf418 100644 --- a/typescript/vrotsc/e2e/cases/canvas-items/end-item-exception.wf.ts +++ b/typescript/vrotsc/e2e/cases/canvas-items/end-item-exception.wf.ts @@ -8,6 +8,9 @@ import { Workflow, In, Out, RootItem, WorkflowEndItem } from "vrotsc-annotations errorMessage: { type: "string" }, + businessStatus: { + type: "string" + }, endMode: { type: "number" } @@ -22,7 +25,8 @@ export class WorkflowEnd { @WorkflowEndItem({ endMode: 1, - exception: "errorMessage" + exception: "errorMessage", + businessStatus: "Bad" }) public workflowEnd(@In endMode: number, @Out errorMessage: string) { // NOOP diff --git a/typescript/vrotsc/e2e/cases/node_modules/@types/vrotsc-annotations/index.d.ts b/typescript/vrotsc/e2e/cases/node_modules/@types/vrotsc-annotations/index.d.ts index 4c896f55f..3e86ec928 100644 --- a/typescript/vrotsc/e2e/cases/node_modules/@types/vrotsc-annotations/index.d.ts +++ b/typescript/vrotsc/e2e/cases/node_modules/@types/vrotsc-annotations/index.d.ts @@ -259,6 +259,7 @@ interface VroWorkflowEndItemDecorator { interface VroWorkflowEndItemConfiguration { endMode?: WorkflowEndMode; exception?: string; + businessStatus?: string; } interface VroWorkflowEndItemMethodDecorator { diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Exception.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Exception.xml index 1a28b30df..5853b2d8b 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Exception.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Exception.xml @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Happy.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Happy.xml index a3fc2aa58..20fa56991 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Happy.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Happy.xml @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow Test.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow Test.xml index df7ef01b1..d41771283 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow Test.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow Test.xml @@ -15,4 +15,4 @@ else { System.log("Counter: " + counter); System.log("Waiting Timer: " + waitingTimer); ]]> \ No newline at end of file +]]> \ No newline at end of file diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/endItemDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/endItemDecoratorStrategy.ts index e895eaaf7..449b68824 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/endItemDecoratorStrategy.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/endItemDecoratorStrategy.ts @@ -65,6 +65,10 @@ export default class EndItemDecoratorStrategy implements CanvasItemDecoratorStra itemInfo.canvasItemPolymorphicBag.exception = propValue; break; } + case "businessStatus": { + itemInfo.canvasItemPolymorphicBag.businessStatus = propValue; + break; + } default: { throw new Error(`Item attribute '${propName}' is not supported for ${this.getDecoratorType()} item`); } @@ -92,11 +96,18 @@ export default class EndItemDecoratorStrategy implements CanvasItemDecoratorStra const endMode = itemInfo?.canvasItemPolymorphicBag?.endMode; const exceptionVariable = itemInfo?.canvasItemPolymorphicBag?.exception; - if (exceptionVariable !== null && exceptionVariable !== undefined && exceptionVariable) { - stringBuilder.append(``).appendLine(); - } else { - stringBuilder.append(``).appendLine(); + const businessStatus = itemInfo?.canvasItemPolymorphicBag?.businessStatus; + const hasException = (exceptionVariable !== null && exceptionVariable !== undefined && exceptionVariable); + const hasBusinessStatus = (businessStatus !== null && businessStatus !== undefined && businessStatus); + + stringBuilder.append(`").appendLine(); stringBuilder.indent(); stringBuilder.appendContent(buildItemParameterBindings(itemInfo, InputOutputBindings.OUT_BINDINGS)); stringBuilder.append(``).appendLine(); diff --git a/vro-types/vrotsc-annotations/index.d.ts b/vro-types/vrotsc-annotations/index.d.ts index 4c896f55f..3e86ec928 100644 --- a/vro-types/vrotsc-annotations/index.d.ts +++ b/vro-types/vrotsc-annotations/index.d.ts @@ -259,6 +259,7 @@ interface VroWorkflowEndItemDecorator { interface VroWorkflowEndItemConfiguration { endMode?: WorkflowEndMode; exception?: string; + businessStatus?: string; } interface VroWorkflowEndItemMethodDecorator { From 5db1f5bd1e35da6a3bac1c925c7e3ddf54e135a3 Mon Sep 17 00:00:00 2001 From: Alexander Kantchev Date: Thu, 18 Jul 2024 17:12:33 +0300 Subject: [PATCH 08/67] [Task 339] code: Improvements. Signed-off-by: Alexander Kantchev --- .../PSCoE/Default Error Handler Happy.xml | 2 +- .../workflows/VMware/PSCoE/Workflow Test.xml | 2 +- .../defaultErrorHandlerDecoratorStrategy.ts | 22 +++++++++++-------- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Default Error Handler Happy.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Default Error Handler Happy.xml index 2d26875a1..c4f8b5e96 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Default Error Handler Happy.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Default Error Handler Happy.xml @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow Test.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow Test.xml index c042c278c..e59d9af9d 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow Test.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow Test.xml @@ -15,4 +15,4 @@ else { System.log("Counter: " + counter); System.log("Waiting Timer: " + waitingTimer); ]]> \ No newline at end of file +]]> \ No newline at end of file diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/defaultErrorHandlerDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/defaultErrorHandlerDecoratorStrategy.ts index f667e5ae8..c154e989a 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/defaultErrorHandlerDecoratorStrategy.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/defaultErrorHandlerDecoratorStrategy.ts @@ -111,12 +111,14 @@ export default class DefaultErrorHandlerDecoratorStrategy implements CanvasItemD throw new Error(`Unable to find target item for ${this.getDecoratorType()} item`); } const exceptionVariable = itemInfo?.canvasItemPolymorphicBag?.exception; - // attach error handler with attaching of exception variable if defined - if (exceptionVariable !== null && exceptionVariable !== undefined && exceptionVariable) { - stringBuilder.append(``).appendLine(); - } else { - stringBuilder.append(``).appendLine(); + const hasException = (exceptionVariable !== null && exceptionVariable !== undefined && exceptionVariable); + + stringBuilder.append(`").appendLine(); stringBuilder.indent(); stringBuilder.append(``).appendLine(); stringBuilder.unindent(); @@ -132,12 +134,14 @@ export default class DefaultErrorHandlerDecoratorStrategy implements CanvasItemD private buildDefaultEndItem(itemInfo: WorkflowItemDescriptor, pos: number, exceptionVariable: string): string { const stringBuilder = new StringBuilderClass("", ""); - - if (exceptionVariable !== null && exceptionVariable !== undefined && exceptionVariable) { - stringBuilder.append(``).appendLine(); + const hasException = (exceptionVariable !== null && exceptionVariable !== undefined && exceptionVariable); + stringBuilder.append(``).appendLine(); + stringBuilder.append(`end-mode="0" `); } + stringBuilder.append(">").appendLine(); stringBuilder.indent(); stringBuilder.appendContent(buildItemParameterBindings(itemInfo, InputOutputBindings.IN_BINDINGS)); stringBuilder.appendContent(buildItemParameterBindings(itemInfo, InputOutputBindings.OUT_BINDINGS)); From 9d6cf9aada6a71ef245ee412a358c0790e56584b Mon Sep 17 00:00:00 2001 From: Alexander Kantchev Date: Fri, 19 Jul 2024 15:53:11 +0300 Subject: [PATCH 09/67] [Task 340] code: Updated annotation variable name. Signed-off-by: Alexander Kantchev --- .../typescript/Components/Workflows.md | 2 +- docs/versions/latest/Release.md | 2 +- .../canvas-items/end-item-exception.wf.ts | 2 +- .../cases/canvas-items/end-item-happy.wf.ts | 2 +- .../e2e/cases/canvas-items/workflow.wf.ts | 2 +- .../@types/vrotsc-annotations/index.d.ts | 2 +- .../VMware/PSCoE/Workflow End Happy.xml | 2 +- .../decorators/endItemDecoratorStrategy.ts | 27 ++++++++++++++----- vro-types/vrotsc-annotations/index.d.ts | 2 +- 9 files changed, 28 insertions(+), 15 deletions(-) diff --git a/docs/versions/latest/Components/Archetypes/typescript/Components/Workflows.md b/docs/versions/latest/Components/Archetypes/typescript/Components/Workflows.md index 0138d41f6..ebb7a21fb 100644 --- a/docs/versions/latest/Components/Archetypes/typescript/Components/Workflows.md +++ b/docs/versions/latest/Components/Archetypes/typescript/Components/Workflows.md @@ -27,7 +27,7 @@ The decorator is used to specify a custom workflow end item. ##### Supported Parameters - `endMode` - End mode of the component, could be one of 0 or 1, where 0 is exit success and 1 is error. -- `exception` - Exception variable that will hold the exception data when triggered. +- `exceptionVariable` - Exception variable that will hold the exception data when triggered. In order to bind inputs and outputs, you do it with the `@Out` decorator. This is the same way we do it for other items. diff --git a/docs/versions/latest/Release.md b/docs/versions/latest/Release.md index 58962fbc2..dacea39fa 100644 --- a/docs/versions/latest/Release.md +++ b/docs/versions/latest/Release.md @@ -31,7 +31,7 @@ The decorator is used to specify a custom workflow end item. #### Supported Parameters - `endMode` - End mode of the component, could be one of 0 or 1, where 0 is exit success and 1 is error. -- `exception` - Exception variable that will hold the exception data when triggered. +- `exceptionVariable` - Exception variable that will hold the exception data when triggered. In order to bind inputs and outputs, you do it with the `@Out` decorator. This is the same way we do it for other items. diff --git a/typescript/vrotsc/e2e/cases/canvas-items/end-item-exception.wf.ts b/typescript/vrotsc/e2e/cases/canvas-items/end-item-exception.wf.ts index 2032cf418..445fcaabd 100644 --- a/typescript/vrotsc/e2e/cases/canvas-items/end-item-exception.wf.ts +++ b/typescript/vrotsc/e2e/cases/canvas-items/end-item-exception.wf.ts @@ -25,7 +25,7 @@ export class WorkflowEnd { @WorkflowEndItem({ endMode: 1, - exception: "errorMessage", + exceptionVariable: "errorMessage", businessStatus: "Bad" }) public workflowEnd(@In endMode: number, @Out errorMessage: string) { diff --git a/typescript/vrotsc/e2e/cases/canvas-items/end-item-happy.wf.ts b/typescript/vrotsc/e2e/cases/canvas-items/end-item-happy.wf.ts index 0b23186fa..68f66c93a 100644 --- a/typescript/vrotsc/e2e/cases/canvas-items/end-item-happy.wf.ts +++ b/typescript/vrotsc/e2e/cases/canvas-items/end-item-happy.wf.ts @@ -20,7 +20,7 @@ export class WorkflowEnd { @WorkflowEndItem({ endMode: 0 }) - public workflowEnd(@In endMode: number) { + public workflowEnd() { // NOOP } } diff --git a/typescript/vrotsc/e2e/cases/canvas-items/workflow.wf.ts b/typescript/vrotsc/e2e/cases/canvas-items/workflow.wf.ts index 525088bcb..109401b64 100644 --- a/typescript/vrotsc/e2e/cases/canvas-items/workflow.wf.ts +++ b/typescript/vrotsc/e2e/cases/canvas-items/workflow.wf.ts @@ -81,7 +81,7 @@ export class HandleNetworkConfigurationBackup { @WorkflowEndItem({ endMode: 0, - exception: "errorMessage" + exceptionVariable: "errorMessage" }) public workflowEnd(@In endMode: number, @Out errorMessage: string) { // NOOP diff --git a/typescript/vrotsc/e2e/cases/node_modules/@types/vrotsc-annotations/index.d.ts b/typescript/vrotsc/e2e/cases/node_modules/@types/vrotsc-annotations/index.d.ts index 3e86ec928..ace17b31a 100644 --- a/typescript/vrotsc/e2e/cases/node_modules/@types/vrotsc-annotations/index.d.ts +++ b/typescript/vrotsc/e2e/cases/node_modules/@types/vrotsc-annotations/index.d.ts @@ -258,7 +258,7 @@ interface VroWorkflowEndItemDecorator { interface VroWorkflowEndItemConfiguration { endMode?: WorkflowEndMode; - exception?: string; + exceptionVariable?: string; businessStatus?: string; } diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Happy.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Happy.xml index 20fa56991..ffb430d66 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Happy.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Happy.xml @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/endItemDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/endItemDecoratorStrategy.ts index 449b68824..b6da079bb 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/endItemDecoratorStrategy.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/endItemDecoratorStrategy.ts @@ -24,6 +24,21 @@ const xBasePosition = 160; const yBasePosition = 100; const offSet = 20; +/** + * + * Responsible for printing out the workflow end item. + * The following decorator properties are supported + * 1. exception - exception variable + * 2. endMode - end mode of the component (0 means success, 1 means error). + * 3. businessStatus - business status of the end component. + * @example + * ```xml + + + + + * ``` + */ export default class EndItemDecoratorStrategy implements CanvasItemDecoratorStrategy { /** * Return XML tag for the end workflow item. @@ -61,8 +76,8 @@ export default class EndItemDecoratorStrategy implements CanvasItemDecoratorStra itemInfo.canvasItemPolymorphicBag.endMode = propValue; break; } - case "exception": { - itemInfo.canvasItemPolymorphicBag.exception = propValue; + case "exceptionVariable": { + itemInfo.canvasItemPolymorphicBag.exceptionVariable = propValue; break; } case "businessStatus": { @@ -95,16 +110,14 @@ export default class EndItemDecoratorStrategy implements CanvasItemDecoratorStra const stringBuilder = new StringBuilderClass("", ""); const endMode = itemInfo?.canvasItemPolymorphicBag?.endMode; - const exceptionVariable = itemInfo?.canvasItemPolymorphicBag?.exception; + const exceptionVariable = itemInfo?.canvasItemPolymorphicBag?.exceptionVariable; const businessStatus = itemInfo?.canvasItemPolymorphicBag?.businessStatus; - const hasException = (exceptionVariable !== null && exceptionVariable !== undefined && exceptionVariable); - const hasBusinessStatus = (businessStatus !== null && businessStatus !== undefined && businessStatus); stringBuilder.append(`").appendLine(); diff --git a/vro-types/vrotsc-annotations/index.d.ts b/vro-types/vrotsc-annotations/index.d.ts index 3e86ec928..ace17b31a 100644 --- a/vro-types/vrotsc-annotations/index.d.ts +++ b/vro-types/vrotsc-annotations/index.d.ts @@ -258,7 +258,7 @@ interface VroWorkflowEndItemDecorator { interface VroWorkflowEndItemConfiguration { endMode?: WorkflowEndMode; - exception?: string; + exceptionVariable?: string; businessStatus?: string; } From 7bdb504ebac3c6036e078e539cff8b6b8901f893 Mon Sep 17 00:00:00 2001 From: Stefan Genov Date: Fri, 19 Jul 2024 16:33:52 +0300 Subject: [PATCH 10/67] feat: Added the new decorator for scheduled workflows Signed-off-by: Stefan Genov --- typescript/vrotsc/src/compiler/decorators.ts | 8 ++++++++ .../decorators/itemDecoratorStrategy.ts | 1 + .../waitingTimerItemDecoratorStrategy.ts | 2 -- vro-types/vrotsc-annotations/index.d.ts | 19 +++++++++++++++++++ 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/typescript/vrotsc/src/compiler/decorators.ts b/typescript/vrotsc/src/compiler/decorators.ts index 997d84e61..f4e9be554 100644 --- a/typescript/vrotsc/src/compiler/decorators.ts +++ b/typescript/vrotsc/src/compiler/decorators.ts @@ -127,6 +127,14 @@ export enum WorkflowItemType { * It can target a specific item and accepts input and output bindings */ Workflow = "WorkflowItem", + + /** + * This item type represents a scheduled workflow item + * + * It can target a specific item and accepts input bindings + * There is only one outputBinding if you want to get the scheduledTask information + */ + ScheduledWorkflow = "ScheduledWorkflowItem" } /////////////////////////////////// Polyglot Decorator /////////////////////////////////// diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/itemDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/itemDecoratorStrategy.ts index ef3a43849..1b14ccc9c 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/itemDecoratorStrategy.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/itemDecoratorStrategy.ts @@ -77,6 +77,7 @@ export default class ItemDecoratorStrategy implements CanvasItemDecoratorStrateg + ` out-name="${targetItem}"` + ` type="${this.getCanvasType()}"` + ">").appendLine(); + stringBuilder.indent(); stringBuilder.append(``).appendLine(); diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/waitingTimerItemDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/waitingTimerItemDecoratorStrategy.ts index 6ab322b0f..1b5c333b7 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/waitingTimerItemDecoratorStrategy.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/waitingTimerItemDecoratorStrategy.ts @@ -38,8 +38,6 @@ import { InputOutputBindings, buildItemParameterBindings } from "./helpers/prese * ``` */ export default class WaitingTimerItemDecoratorStrategy implements CanvasItemDecoratorStrategy { - constructor(private readonly sourceFilePrinter: SourceFilePrinter = new DefaultSourceFilePrinter()) { } - getCanvasType(): string { return "waiting-timer"; } diff --git a/vro-types/vrotsc-annotations/index.d.ts b/vro-types/vrotsc-annotations/index.d.ts index 8ed98331a..fccf2c465 100644 --- a/vro-types/vrotsc-annotations/index.d.ts +++ b/vro-types/vrotsc-annotations/index.d.ts @@ -245,6 +245,25 @@ interface VroWorkflowItemMethodDecorator { } +// ---------------------------------------------- Scheduled Workflow Canvas Item ------------------------------------------------ + +export declare const ScheduledWorkflowItem: VroScheduledWorkflowItemDecorator; + +interface VroScheduledWorkflowItemDecorator { + (obj?: VroScheduledWorkflowItemConfiguration): VroScheduledWorkflowItemMethodDecorator; + new(obj?: VroScheduledWorkflowItemConfiguration): VroScheduledWorkflowItemConfiguration; +} + +interface VroScheduledWorkflowItemConfiguration { + target?: string; + linkedItem: string; +} + +interface VroScheduledWorkflowItemMethodDecorator { + >(type: T): T; + (target: Object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor): void; +} + //--------------------------------------------- POLYGLOT ------------------------------------------------------------------------------- export declare const Polyglot: VroPolyglotDecorator; From b37156fa18c9468c4802e63c5be10520204533ac Mon Sep 17 00:00:00 2001 From: Stefan Genov Date: Fri, 19 Jul 2024 16:34:08 +0300 Subject: [PATCH 11/67] feat: Add the ScheduledWorkflowItemDecoratorStrategy source file pending Signed-off-by: Stefan Genov --- .../workflow/decorators/helpers/sourceFile.ts | 8 + .../scheduledWorkflowItemDecoratorStrategy.ts | 162 ++++++++++++++++++ 2 files changed, 170 insertions(+) create mode 100644 typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/scheduledWorkflowItemDecoratorStrategy.ts diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/helpers/sourceFile.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/helpers/sourceFile.ts index e4ece20b4..886641050 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/helpers/sourceFile.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/helpers/sourceFile.ts @@ -68,3 +68,11 @@ export class WrapperSourceFilePrinter implements SourceFilePrinter { ); } } + +export class ScheduledWorkflowItemSourceFilePrinter extends DefaultSourceFilePrinter { + public printSourceFile(methodNode: MethodDeclaration, sourceFile: SourceFile): string { + // return printSourceFile( + // ); + return ""; + } +} diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/scheduledWorkflowItemDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/scheduledWorkflowItemDecoratorStrategy.ts new file mode 100644 index 000000000..cb8237671 --- /dev/null +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/scheduledWorkflowItemDecoratorStrategy.ts @@ -0,0 +1,162 @@ +/*- + * #%L + * vrotsc + * %% + * Copyright (C) 2023 - 2024 VMware + * %% + * Build Tools for VMware Aria + * Copyright 2023 VMware, Inc. + * + * This product is licensed to you under the BSD-2 license (the "License"). You may not use this product except in compliance with the BSD-2 License. + * + * This product may include a number of subcomponents with separate copyright notices and license terms. Your use of these subcomponents is subject to the terms and conditions of the subcomponent's license, as noted in the LICENSE file. + * #L% + */ +import { Decorator, MethodDeclaration, SourceFile } from "typescript"; +import { WorkflowItemDescriptor, WorkflowItemType } from "../../../../decorators"; +import { getDecoratorProps } from "../../../helpers/node"; +import CanvasItemDecoratorStrategy from "./canvasItemDecoratorStrategy"; +import { InputOutputBindings, buildItemParameterBindings } from "./helpers/presentation"; +import { findTargetItem } from "../helpers/findTargetItem"; +import { StringBuilderClass } from "../../../../../utilities/stringBuilder"; +import { ScheduledWorkflowItemSourceFilePrinter, SourceFilePrinter } from "./helpers/sourceFile"; + +/** + * + * Responsible for printing out the workflow item: + * @example + * ```xml + + + + + + + + + + + + + + + * ``` + */ +export default class ScheduledWorkflowItemDecoratorStrategy implements CanvasItemDecoratorStrategy { + constructor(private readonly sourceFilePrinter: SourceFilePrinter = new ScheduledWorkflowItemSourceFilePrinter()) { } + + getCanvasType(): string { + return "task"; + } + + getDecoratorType(): WorkflowItemType { + return WorkflowItemType.ScheduledWorkflow; + } + + registerItemArguments(itemInfo: WorkflowItemDescriptor, decoratorNode: Decorator): void { + getDecoratorProps(decoratorNode).forEach((propTuple) => { + const [propName, propValue] = propTuple; + switch (propName) { + case "target": + itemInfo.target = propValue; + break; + + case "exception": + itemInfo.canvasItemPolymorphicBag.exception = propValue; + break; + + case "linkedItem": + itemInfo.canvasItemPolymorphicBag.linkedItem = propValue; + break; + + default: + throw new Error(`Item attribute '${propName}' is not supported for ${this.getDecoratorType()} item`); + } + }); + } + + /** + * There is no need to print the source file for the workflow item + */ + printSourceFile(methodNode: MethodDeclaration, sourceFile: SourceFile): string { return ""; } + + /** + * Prints out the item + * + * - `out-name` is the target canvas item to be called after the item is executed + * + * @param itemInfo The item to print + * @param pos The position of the item in the workflow + * + * @returns The string representation of the item + */ + printItem(itemInfo: WorkflowItemDescriptor, pos: number): string { + const stringBuilder = new StringBuilderClass("", ""); + + this.validateNeededParameters(itemInfo); + + const targetItem = findTargetItem(itemInfo.target, pos, itemInfo); + if (targetItem === null) { + throw new Error(`Unable to find target item for ${this.getDecoratorType()} item`); + } + + stringBuilder.append(`").appendLine(); + + stringBuilder.indent(); + stringBuilder.append(``).appendLine(); + + stringBuilder.append(``).appendLine(); + stringBuilder.appendContent(buildItemParameterBindings(itemInfo, InputOutputBindings.IN_BINDINGS)); + stringBuilder.appendContent(buildItemParameterBindings(itemInfo, InputOutputBindings.OUT_BINDINGS)); + stringBuilder.append(``).appendLine(); + stringBuilder.unindent(); + stringBuilder.append(``).appendLine(); + + return stringBuilder.toString(); + } + + /** + * Validates that the item has all the required parameters + * + * Inputs: + * - workflowScheduleDate + * + * Outputs: + * - scheduledTask (optional) but if present, it should be the only output + * + * @param itemInfo The item to validate + * @throws Error if the item is missing required parameters + * @returns void + */ + private validateNeededParameters(itemInfo: WorkflowItemDescriptor): void { + const inputs = itemInfo.input; + + ["workflowScheduleDate"].forEach((input) => { + if (!inputs.includes(input)) { + throw new Error(`Decorator ${this.getDecoratorType()} is missing required input: ${input}`); + } + }); + + const outputs = itemInfo.output; + + if (outputs.length && outputs.length !== 1 && !outputs.includes("scheduledTask")) { + throw new Error(`Decorator ${this.getDecoratorType()} has an invalid output: ${outputs}, expected: scheduledTask`); + } + } +} + From 68a86cc54b4e6a19d4e3c314f6dfb986c9785e89 Mon Sep 17 00:00:00 2001 From: Stefan Genov Date: Fri, 19 Jul 2024 17:04:30 +0300 Subject: [PATCH 12/67] fix: Add the missing strategy to the list of possible decorators Signed-off-by: Stefan Genov --- .../transformer/fileTransformers/workflow/decorators.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators.ts index 8f79f74dc..2cf30f3a0 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators.ts @@ -23,6 +23,7 @@ import RootItemDecoratorStrategy from "./decorators/rootItemDecoratorStrategy"; import WaitingTimerItemDecoratorStrategy from "./decorators/waitingTimerItemDecoratorStrategy"; import DecisionItemDecoratorStrategy from "./decorators/decisionItemDecoratorStrategy"; import WorkflowItemDecoratorStrategy from "./decorators/workflowItemDecoratorStrategy"; +import ScheduledWorkflowItemDecoratorStrategy from "./decorators/scheduledWorkflowItemDecoratorStrategy"; /** * Fetches details from the decorators for the methods and adds the information to the Descriptors @@ -84,6 +85,8 @@ function getItemStrategy(decoratorNode: ts.Decorator): CanvasItemDecoratorStrate return new WorkflowItemDecoratorStrategy(); case WorkflowItemType.RootItem: return new RootItemDecoratorStrategy(); + case WorkflowItemType.ScheduledWorkflow: + return new ScheduledWorkflowItemDecoratorStrategy(); default: throw new Error(`Invalid decorator type: ${identifierText}`); } From c2fee0b0c2a602690f07db0faab815c07672616d Mon Sep 17 00:00:00 2001 From: Stefan Genov Date: Fri, 19 Jul 2024 17:07:08 +0300 Subject: [PATCH 13/67] fix: Added `itemInfo` to be passed in the `printSourceFile` Signed-off-by: Stefan Genov --- .../decorators/canvasItemDecoratorStrategy.ts | 2 +- .../decisionItemDecoratorStrategy.ts | 4 +- .../workflow/decorators/helpers/sourceFile.ts | 85 +++++++++++++++++-- .../decorators/itemDecoratorStrategy.ts | 4 +- .../decorators/rootItemDecoratorStrategy.ts | 2 +- .../scheduledWorkflowItemDecoratorStrategy.ts | 8 +- .../waitingTimerItemDecoratorStrategy.ts | 2 +- .../workflowItemDecoratorStrategy.ts | 2 +- .../fileTransformers/workflow/workflow.ts | 2 +- 9 files changed, 91 insertions(+), 20 deletions(-) diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/canvasItemDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/canvasItemDecoratorStrategy.ts index 7f06f8564..86dde7073 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/canvasItemDecoratorStrategy.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/canvasItemDecoratorStrategy.ts @@ -36,7 +36,7 @@ export default interface CanvasItemDecoratorStrategy { * * The rest can return an empty string. */ - printSourceFile(methodNode: ts.MethodDeclaration, sourceFile: ts.SourceFile): string; + printSourceFile(methodNode: ts.MethodDeclaration, sourceFile: ts.SourceFile, itemInfo: WorkflowItemDescriptor): string; printItem(itemInfo: WorkflowItemDescriptor, pos: number): string; } diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/decisionItemDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/decisionItemDecoratorStrategy.ts index ae80fb692..0dd9beb89 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/decisionItemDecoratorStrategy.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/decisionItemDecoratorStrategy.ts @@ -66,8 +66,8 @@ export default class DecisionItemDecoratorStrategy implements CanvasItemDecorato }); } - printSourceFile(methodNode: MethodDeclaration, sourceFile: SourceFile): string { - return this.sourceFilePrinter.printSourceFile(methodNode, sourceFile); + printSourceFile(methodNode: MethodDeclaration, sourceFile: SourceFile, itemInfo: WorkflowItemDescriptor): string { + return this.sourceFilePrinter.printSourceFile(methodNode, sourceFile, itemInfo); } /** diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/helpers/sourceFile.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/helpers/sourceFile.ts index 886641050..cda4ad766 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/helpers/sourceFile.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/helpers/sourceFile.ts @@ -15,16 +15,17 @@ import { MethodDeclaration, SourceFile, SyntaxKind, factory } from "typescript"; import { printSourceFile } from "../../../../helpers/source"; import { createWorkflowItemPrologueStatements } from "../../../../codeTransformers/prologueStatements"; +import { WorkflowItemDescriptor } from "../../../../../decorators"; export interface SourceFilePrinter { - printSourceFile(methodNode: MethodDeclaration, sourceFile: SourceFile): string; + printSourceFile(methodNode: MethodDeclaration, sourceFile: SourceFile, itemInfo?: WorkflowItemDescriptor): string; } /** * Default source file printer will directly print the source file with the method node body statements. */ export class DefaultSourceFilePrinter implements SourceFilePrinter { - public printSourceFile(methodNode: MethodDeclaration, sourceFile: SourceFile): string { + public printSourceFile(methodNode: MethodDeclaration, sourceFile: SourceFile, itemInfo: WorkflowItemDescriptor): string { return printSourceFile( factory.updateSourceFile( sourceFile, @@ -46,7 +47,7 @@ export class DefaultSourceFilePrinter implements SourceFilePrinter { * @NOTE: This is 100% due to a typescript limitation, and not a vRO limitation. */ export class WrapperSourceFilePrinter implements SourceFilePrinter { - public printSourceFile(methodNode: MethodDeclaration, sourceFile: SourceFile): string { + public printSourceFile(methodNode: MethodDeclaration, sourceFile: SourceFile, itemInfo: WorkflowItemDescriptor): string { const wrapperFunction = factory.createFunctionDeclaration( undefined, undefined, @@ -69,10 +70,78 @@ export class WrapperSourceFilePrinter implements SourceFilePrinter { } } -export class ScheduledWorkflowItemSourceFilePrinter extends DefaultSourceFilePrinter { - public printSourceFile(methodNode: MethodDeclaration, sourceFile: SourceFile): string { - // return printSourceFile( - // ); - return ""; + +// +// +// +// +// +// +// +// +// +// +// +// +// +// +export class ScheduledWorkflowItemSourceFilePrinter implements SourceFilePrinter { + public printSourceFile(methodNode: MethodDeclaration, sourceFile: SourceFile, itemInfo: WorkflowItemDescriptor): string { + const segments = []; + + segments.push( + factory.createVariableDeclaration( + "workflowToLaunch", + undefined, + undefined, + factory.createCallExpression( + factory.createPropertyAccessExpression( + factory.createIdentifier("Server"), + factory.createIdentifier("getWorkflowWithId") + ), + undefined, + [factory.createStringLiteral(itemInfo.canvasItemPolymorphicBag.linkedItem)] + ) + ) + ); + + segments.push( + factory.createIfStatement( + factory.createBinaryExpression( + factory.createIdentifier("workflowToLaunch"), + factory.createToken(SyntaxKind.ExclamationEqualsToken), + factory.createNull() + ), + factory.createBlock( + [ + factory.createThrowStatement( + factory.createStringLiteral("Workflow not found") + ) + ], + true + ) + ) + ); + + return printSourceFile( + factory.updateSourceFile( + sourceFile, + [ + ...sourceFile.statements.filter(n => n.kind !== SyntaxKind.ClassDeclaration), + ...createWorkflowItemPrologueStatements(methodNode), + ...segments, + ] + ) + ); } } diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/itemDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/itemDecoratorStrategy.ts index 1b14ccc9c..032083df8 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/itemDecoratorStrategy.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/itemDecoratorStrategy.ts @@ -50,8 +50,8 @@ export default class ItemDecoratorStrategy implements CanvasItemDecoratorStrateg }); } - printSourceFile(methodNode: MethodDeclaration, sourceFile: SourceFile): string { - return this.sourceFilePrinter.printSourceFile(methodNode, sourceFile); + printSourceFile(methodNode: MethodDeclaration, sourceFile: SourceFile, itemInfo: WorkflowItemDescriptor): string { + return this.sourceFilePrinter.printSourceFile(methodNode, sourceFile, itemInfo); } /** diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/rootItemDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/rootItemDecoratorStrategy.ts index cb64ddb6d..0e0de2a9e 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/rootItemDecoratorStrategy.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/rootItemDecoratorStrategy.ts @@ -34,7 +34,7 @@ export default class RootItemDecoratorStrategy implements CanvasItemDecoratorStr itemInfo.parent.rootItem = methodNode.name.escapedText as string; } - printSourceFile(methodNode: MethodDeclaration, sourceFile: SourceFile): string { return this.throwDoNotCallError(); } + printSourceFile(methodNode: MethodDeclaration, sourceFile: SourceFile, itemInfo: WorkflowItemDescriptor): string { return this.throwDoNotCallError(); } getCanvasType(): string { return this.throwDoNotCallError(); } printItem(itemInfo: WorkflowItemDescriptor, pos: number): string { return this.throwDoNotCallError(); } diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/scheduledWorkflowItemDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/scheduledWorkflowItemDecoratorStrategy.ts index cb8237671..19e62c266 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/scheduledWorkflowItemDecoratorStrategy.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/scheduledWorkflowItemDecoratorStrategy.ts @@ -88,7 +88,9 @@ export default class ScheduledWorkflowItemDecoratorStrategy implements CanvasIte /** * There is no need to print the source file for the workflow item */ - printSourceFile(methodNode: MethodDeclaration, sourceFile: SourceFile): string { return ""; } + printSourceFile(methodNode: MethodDeclaration, sourceFile: SourceFile, itemInfo: WorkflowItemDescriptor): string { + return this.sourceFilePrinter.printSourceFile(methodNode, sourceFile, itemInfo); + } /** * Prints out the item @@ -134,10 +136,10 @@ export default class ScheduledWorkflowItemDecoratorStrategy implements CanvasIte * Validates that the item has all the required parameters * * Inputs: - * - workflowScheduleDate + * - {Date} workflowScheduleDate * * Outputs: - * - scheduledTask (optional) but if present, it should be the only output + * - {Task} scheduledTask (optional) but if present, it should be the only output * * @param itemInfo The item to validate * @throws Error if the item is missing required parameters diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/waitingTimerItemDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/waitingTimerItemDecoratorStrategy.ts index 1b5c333b7..69eb9d6ed 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/waitingTimerItemDecoratorStrategy.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/waitingTimerItemDecoratorStrategy.ts @@ -64,7 +64,7 @@ export default class WaitingTimerItemDecoratorStrategy implements CanvasItemDeco /** * There is no need to print the source file for a waiting timer item */ - printSourceFile(methodNode: MethodDeclaration, sourceFile: SourceFile): string { return ""; } + printSourceFile(methodNode: MethodDeclaration, sourceFile: SourceFile, itemInfo: WorkflowItemDescriptor): string { return ""; } /** * Prints the waiting timer to the workflow file diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/workflowItemDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/workflowItemDecoratorStrategy.ts index 53b628123..de8f936d1 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/workflowItemDecoratorStrategy.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/workflowItemDecoratorStrategy.ts @@ -74,7 +74,7 @@ export default class WorkflowItemDecoratorStrategy implements CanvasItemDecorato /** * There is no need to print the source file for the workflow item */ - printSourceFile(methodNode: MethodDeclaration, sourceFile: SourceFile): string { return ""; } + printSourceFile(methodNode: MethodDeclaration, sourceFile: SourceFile, itemInfo: WorkflowItemDescriptor): string { return ""; } /** * Prints out the item diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/workflow.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/workflow.ts index d1c66380c..86cdf8598 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/workflow.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/workflow.ts @@ -97,7 +97,7 @@ export function getWorkflowTransformer(file: FileDescriptor, context: FileTransf registerWorkflowItem(itemInfo, methodNode); const actionSourceFilePath = system.changeFileExt(sourceFile.fileName, `.${itemInfo.name}.wf.ts`, [".wf.ts"]); - let actionSourceText = itemInfo.strategy.printSourceFile(methodNode, sourceFile); + let actionSourceText = itemInfo.strategy.printSourceFile(methodNode, sourceFile, itemInfo); // @TODO: "Unstupify" me if (itemInfo.polyglot) { actionSourceText = decorateSourceFileTextWithPolyglot(actionSourceText, itemInfo.polyglot, itemInfo); From 2dde4a145a4a06c23ed118fca7c99ec996da08a4 Mon Sep 17 00:00:00 2001 From: Stefan Genov Date: Fri, 19 Jul 2024 17:48:48 +0300 Subject: [PATCH 14/67] fix: Wrong format for the linked workflow xml prop Signed-off-by: Stefan Genov --- .../decorators/scheduledWorkflowItemDecoratorStrategy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/scheduledWorkflowItemDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/scheduledWorkflowItemDecoratorStrategy.ts index 19e62c266..1ce28b9d8 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/scheduledWorkflowItemDecoratorStrategy.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/scheduledWorkflowItemDecoratorStrategy.ts @@ -116,7 +116,7 @@ export default class ScheduledWorkflowItemDecoratorStrategy implements CanvasIte + ` name="item${pos}"` + ` out-name="${targetItem}"` + ` type="${this.getCanvasType()}"` - + ` linked-workflow-id="${itemInfo.canvasItemPolymorphicBag.linkedItem}"` + + ` launched-workflow-id="${itemInfo.canvasItemPolymorphicBag.linkedItem}"` + ">").appendLine(); stringBuilder.indent(); From e9a8a2076cb704bc579c34bdf0b616f83fc8af94 Mon Sep 17 00:00:00 2001 From: Stefan Genov Date: Fri, 19 Jul 2024 17:49:07 +0300 Subject: [PATCH 15/67] refactor: Moved the printing away from a block and into the print file Signed-off-by: Stefan Genov --- .../workflow/decorators/helpers/sourceFile.ts | 154 ++++++++++++------ 1 file changed, 100 insertions(+), 54 deletions(-) diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/helpers/sourceFile.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/helpers/sourceFile.ts index cda4ad766..d3c8d2c6f 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/helpers/sourceFile.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/helpers/sourceFile.ts @@ -12,7 +12,7 @@ * This product may include a number of subcomponents with separate copyright notices and license terms. Your use of these subcomponents is subject to the terms and conditions of the subcomponent's license, as noted in the LICENSE file. * #L% */ -import { MethodDeclaration, SourceFile, SyntaxKind, factory } from "typescript"; +import { MethodDeclaration, SourceFile, SyntaxKind, addSyntheticLeadingComment, factory } from "typescript"; import { printSourceFile } from "../../../../helpers/source"; import { createWorkflowItemPrologueStatements } from "../../../../codeTransformers/prologueStatements"; import { WorkflowItemDescriptor } from "../../../../../decorators"; @@ -70,10 +70,12 @@ export class WrapperSourceFilePrinter implements SourceFilePrinter { } } - -// -// -// -// -// -// -// -// -// -// -// -// -// -// + * + */ export class ScheduledWorkflowItemSourceFilePrinter implements SourceFilePrinter { public printSourceFile(methodNode: MethodDeclaration, sourceFile: SourceFile, itemInfo: WorkflowItemDescriptor): string { - const segments = []; - - segments.push( - factory.createVariableDeclaration( - "workflowToLaunch", - undefined, - undefined, - factory.createCallExpression( - factory.createPropertyAccessExpression( - factory.createIdentifier("Server"), - factory.createIdentifier("getWorkflowWithId") - ), - undefined, - [factory.createStringLiteral(itemInfo.canvasItemPolymorphicBag.linkedItem)] - ) - ) - ); - - segments.push( - factory.createIfStatement( - factory.createBinaryExpression( - factory.createIdentifier("workflowToLaunch"), - factory.createToken(SyntaxKind.ExclamationEqualsToken), - factory.createNull() - ), - factory.createBlock( - [ - factory.createThrowStatement( - factory.createStringLiteral("Workflow not found") - ) - ], - true - ) - ) - ); - return printSourceFile( factory.updateSourceFile( sourceFile, [ ...sourceFile.statements.filter(n => n.kind !== SyntaxKind.ClassDeclaration), ...createWorkflowItemPrologueStatements(methodNode), - ...segments, + // Variable declarations are on top + factory.createVariableStatement( + undefined, + // A list of declarations + factory.createVariableDeclarationList( + [ + // `var workflowParameters = new Properties();` + factory.createVariableDeclaration( + "workflowParameters", + undefined, + undefined, + factory.createNewExpression( + factory.createIdentifier("Properties"), + undefined, + [] + ) + ), + // `, workflowToLaunch = Server.getWorkflowWithId("some id here");` + factory.createVariableDeclaration( + "workflowToLaunch", + undefined, + undefined, + factory.createCallExpression( + factory.createPropertyAccessExpression( + factory.createIdentifier("Server"), + factory.createIdentifier("getWorkflowWithId") + ), + undefined, + [factory.createStringLiteral(itemInfo.canvasItemPolymorphicBag.linkedItem)] + ) + ) + ], + undefined + ) + ), + + // `if (workflowToLaunch == null) { throw "Workflow not found"; }` + factory.createIfStatement( + factory.createBinaryExpression( + factory.createIdentifier("workflowToLaunch"), + factory.createToken(SyntaxKind.EqualsEqualsToken), + factory.createNull() + ), + factory.createBlock( + [ + factory.createThrowStatement( + factory.createStringLiteral("Workflow not found") + ) + ], + true + ) + ), + + // `workflowParameters.put("first",first);` + // `workflowParameters.put("second",second);` + // ...... etc + ...itemInfo.input.filter(i => i !== "workflowScheduleDate").map((input) => { + return factory.createExpressionStatement( + factory.createCallExpression( + factory.createPropertyAccessExpression( + factory.createIdentifier("workflowParameters"), + factory.createIdentifier("put") + ), + undefined, + [ + factory.createStringLiteral(input), + factory.createIdentifier(input) + ] + ) + ); + }), + + // `scheduledTask = workflowToLaunch.schedule(workflowParameters, workflowScheduleDate);` + factory.createExpressionStatement( + factory.createAssignment( + factory.createIdentifier("scheduledTask"), + factory.createCallExpression( + factory.createPropertyAccessExpression( + factory.createIdentifier("workflowToLaunch"), + factory.createIdentifier("schedule") + ), + undefined, + [ + factory.createIdentifier("workflowParameters"), + factory.createIdentifier("workflowScheduleDate"), + factory.createIdentifier("undefined"), + factory.createIdentifier("undefined") + ] + ) + ) + ) ] ) ); From b687935e2e3d770633d9bf369142c4c07ff6c0e8 Mon Sep 17 00:00:00 2001 From: Stefan Genov Date: Fri, 19 Jul 2024 18:10:11 +0300 Subject: [PATCH 16/67] test: Add e2e tests for scheduled workflow Signed-off-by: Stefan Genov --- .../canvas-items/scheduled-workflow.wf.ts | 54 ++++++++++++++++ .../@types/vrotsc-annotations/index.d.ts | 61 ++++++------------- .../Scheduled Workflow Test.element_info.xml | 9 +++ .../VMware/PSCoE/Scheduled Workflow Test.xml | 13 ++++ 4 files changed, 95 insertions(+), 42 deletions(-) create mode 100644 typescript/vrotsc/e2e/cases/canvas-items/scheduled-workflow.wf.ts create mode 100644 typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Scheduled Workflow Test.element_info.xml create mode 100644 typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Scheduled Workflow Test.xml diff --git a/typescript/vrotsc/e2e/cases/canvas-items/scheduled-workflow.wf.ts b/typescript/vrotsc/e2e/cases/canvas-items/scheduled-workflow.wf.ts new file mode 100644 index 000000000..d5792ed84 --- /dev/null +++ b/typescript/vrotsc/e2e/cases/canvas-items/scheduled-workflow.wf.ts @@ -0,0 +1,54 @@ +import { Workflow, Out, In, Item, RootItem, ScheduledWorkflowItem } from "vrotsc-annotations"; + +@Workflow({ + name: "Scheduled Workflow Test", + path: "VMware/PSCoE", + description: "Scheduling another workflow and binding values correctly", + attributes: { + waitingTimer: { + type: "Date" + }, + counter: { + type: "number" + }, + first: { + type: "number" + }, + second: { + type: "number" + }, + workflowScheduleDate: { + type: "Date" + }, + scheduledTask: { + type: "Task" + } + } +}) +export class HandleNetworkConfigurationBackup { + @ScheduledWorkflowItem({ + target: "printScheduledDetails", + linkedItem: "9e4503db-cbaa-435a-9fad-144409c08df0" + }) + public scheduleOtherWf(@In first: number, @In second: number, @In workflowScheduleDate: Date, @Out scheduledTask: Task) { + } + + @Item({ target: "scheduleOtherWf" }) + public prepareItems(@In @Out first: number, @In @Out second: number, @In @Out workflowScheduleDate: Date) { + first = 1; + second = 2; + workflowScheduleDate = System.getDate("1 minute from now", undefined); + } + + @Item({ target: "end" }) + public printScheduledDetails(@In scheduledTask: Task) { + System.log(`Scheduled task: ${scheduledTask.id}, [${scheduledTask.state}]`); + } + + + @Item({ target: "prepareItems", exception: "" }) + @RootItem() + public start() { + System.log("Starting workflow"); + } +} diff --git a/typescript/vrotsc/e2e/cases/node_modules/@types/vrotsc-annotations/index.d.ts b/typescript/vrotsc/e2e/cases/node_modules/@types/vrotsc-annotations/index.d.ts index e284c0710..fccf2c465 100644 --- a/typescript/vrotsc/e2e/cases/node_modules/@types/vrotsc-annotations/index.d.ts +++ b/typescript/vrotsc/e2e/cases/node_modules/@types/vrotsc-annotations/index.d.ts @@ -186,15 +186,6 @@ interface VroWaitingTimerItemMethodDecorator { >(type: T): T; (target: Object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor): void; } -// -// -// -// -// -// -// -// -// // ---------------------------------------------- Workflow Canvas Decision Item ------------------------------------------------ @@ -215,16 +206,6 @@ interface VroDecisionItemMethodDecorator { (target: Object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor): void; } -// -// -// -// -// -// -// -// -// -// // ---------------------------------------------- Workflow Canvas Root Item ------------------------------------------------ @@ -243,16 +224,6 @@ interface VroRootItemMethodDecorator { (target: Object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor): void; } -// -// -// -// -// -// -// -// -// -// // ---------------------------------------------- Workflow Canvas Item ------------------------------------------------ @@ -273,19 +244,25 @@ interface VroWorkflowItemMethodDecorator { (target: Object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor): void; } -// -// -// -// -// -// -// -// -// -// -// -// -// + +// ---------------------------------------------- Scheduled Workflow Canvas Item ------------------------------------------------ + +export declare const ScheduledWorkflowItem: VroScheduledWorkflowItemDecorator; + +interface VroScheduledWorkflowItemDecorator { + (obj?: VroScheduledWorkflowItemConfiguration): VroScheduledWorkflowItemMethodDecorator; + new(obj?: VroScheduledWorkflowItemConfiguration): VroScheduledWorkflowItemConfiguration; +} + +interface VroScheduledWorkflowItemConfiguration { + target?: string; + linkedItem: string; +} + +interface VroScheduledWorkflowItemMethodDecorator { + >(type: T): T; + (target: Object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor): void; +} //--------------------------------------------- POLYGLOT ------------------------------------------------------------------------------- export declare const Polyglot: VroPolyglotDecorator; diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Scheduled Workflow Test.element_info.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Scheduled Workflow Test.element_info.xml new file mode 100644 index 000000000..b742e43c9 --- /dev/null +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Scheduled Workflow Test.element_info.xml @@ -0,0 +1,9 @@ + + + +Generated by vrotsc +VMware.PSCoE +Scheduled Workflow Test +Workflow +18b56581-f9ac-30cb-8df2-8c1c7e5dba37 + diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Scheduled Workflow Test.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Scheduled Workflow Test.xml new file mode 100644 index 000000000..594b0523a --- /dev/null +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Scheduled Workflow Test.xml @@ -0,0 +1,13 @@ + \ No newline at end of file From 28eb00c2aa4b9773991ca6868f97b67de2282124 Mon Sep 17 00:00:00 2001 From: Stefan Genov Date: Fri, 19 Jul 2024 18:18:51 +0300 Subject: [PATCH 17/67] docs: Added docs for scheduled Workflows Signed-off-by: Stefan Genov --- .../typescript/Components/Workflows.md | 185 +++++++++++------- docs/versions/latest/Release.md | 83 +++++++- 2 files changed, 196 insertions(+), 72 deletions(-) diff --git a/docs/versions/latest/Components/Archetypes/typescript/Components/Workflows.md b/docs/versions/latest/Components/Archetypes/typescript/Components/Workflows.md index a9fc558fa..fa70a0449 100644 --- a/docs/versions/latest/Components/Archetypes/typescript/Components/Workflows.md +++ b/docs/versions/latest/Components/Archetypes/typescript/Components/Workflows.md @@ -57,6 +57,29 @@ The decorator is used to specify a workflow item that will be called. In order to bind inputs and outputs, you do it with the `@In` and `@Out` decorators. This is the same way we do it for other items. +#### `@ScheduledWorkflowItem` + +The decorator is used to specify a scheduled workflow item that will be called. + +##### Supported Parameters + +- `target` - The name of the next in line item. Same as `@Item`. +- `linkedItem` - The ID of the workflow to schedule. + +In order to bind inputs and outputs, you do it with the `@In` and `@Out` decorators. This is the same way we do it for other items. + +##### Inputs + +Special input is needed for the ScheduledWorkflowItem. + +- `workflowScheduleDate` - {Date} is required. The name **must** be `workflowScheduleDate`. If this is missing an error is thrown. We don't check if the type is `Date` but Aria Orchestrator will complain. + +##### Outputs + +Special output is needed for the ScheduledWorkflowItem. + +- `scheduledTask` - {Task} is optional. If it's missing nothing will happen, if it's added, then the name **must** be `scheduledTask`. This is the task that is scheduled. + #### `@RootItem` This is a meta decorator. Add this to whichever function you want to be the entry point of the workflow. @@ -64,80 +87,100 @@ This is a meta decorator. Add this to whichever function you want to be the entr ### Example Workflow ```ts -import { Workflow, Out, In, Item, RootItem, DecisionItem, WaitingTimerItem, WorkflowItem } from "vrotsc-annotations"; +import { Workflow, Out, In, Item, RootItem, DecisionItem, WaitingTimerItem, WorkflowItem, ScheduledWorkflowItem } from "vrotsc-annotations"; @Workflow({ - name: "Example Waiting Timer", - path: "VMware/PSCoE", - attributes: { - waitingTimer: { - type: "Date" - }, - counter: { - type: "number" - }, - first: { - type: "number" - }, - second: { - type: "number" - }, - result: { - type: "number" - } - } + name: "Example Waiting Timer", + path: "VMware/PSCoE", + attributes: { + waitingTimer: { + type: "Date" + }, + counter: { + type: "number" + }, + first: { + type: "number" + }, + second: { + type: "number" + }, + result: { + type: "number" + }, + workflowScheduleDate: { + type: "Date" + }, + scheduledTask: { + type: "Task" + } + } }) export class HandleNetworkConfigurationBackup { - @DecisionItem({ target: "waitForEvent", else: "prepareItems" }) - public decisionElement(waitingTimer: Date) { - return waitingTimer !== null; - } - - @Item({ target: "callOtherWf" }) - public prepareItems(@In @Out first: number, @In @Out second: number) { - first = 1; - second = 2; - } - - @WorkflowItem({ - target: "print", - linkedItem: "9e4503db-cbaa-435a-9fad-144409c08df0" - }) - public callOtherWf(@In first: number, @In second: number, @Out result: number) { - } - - @Item({ target: "end" }) - public print(@In result: number) { - System.log("Result: " + result); - } - - @Item({ target: "decisionElement", exception: "" }) - public execute(@Out @In waitingTimer: Date, @Out @In counter: number): void { - if (!counter) { - counter = 0; - } - - counter++; - - if (counter < 2) { - const tt = Date.now() + 5 * 1000; - waitingTimer = new Date(tt); - } else { - waitingTimer = null; - } - - System.log("Counter: " + counter); - System.log("Waiting Timer: " + waitingTimer); - } - - @Item({ target: "execute", exception: "" }) - @RootItem() - public start() { - System.log("Starting workflow"); - } - - @WaitingTimerItem({ target: "execute" }) - public waitForEvent(@In waitingTimer: Date) { - } + @DecisionItem({ target: "waitForEvent", else: "prepareItems" }) + public decisionElement(waitingTimer: Date) { + return waitingTimer !== null; + } + + @Item({ target: "callOtherWf" }) + public prepareItems(@In @Out first: number, @In @Out second: number, @In @Out workflowScheduleDate: Date) { + first = 1; + second = 2; + workflowScheduleDate = System.getDate("1 minute from now", undefined); + } + + @WorkflowItem({ + target: "print", + linkedItem: "9e4503db-cbaa-435a-9fad-144409c08df0" + }) + public callOtherWf(@In first: number, @In second: number, @Out result: number) { + } + + + @Item({ target: "scheduleOtherWf" }) + public print(@In result: number) { + System.log("Result: " + result); + } + + @ScheduledWorkflowItem({ + target: "printScheduledDetails", + linkedItem: "9e4503db-cbaa-435a-9fad-144409c08df0" + }) + public scheduleOtherWf(@In first: number, @In second: number, @In workflowScheduleDate: Date, @Out scheduledTask: Task) { + } + + @Item({ target: "end" }) + public printScheduledDetails(@In scheduledTask: Task) { + System.log(`Scheduled task: ${scheduledTask.id}, [${scheduledTask.state}]`); + } + + @Item({ target: "decisionElement", exception: "" }) + public execute(@Out @In waitingTimer: Date, @Out @In counter: number): void { + if (!counter) { + counter = 0; + } + + counter++; + + if (counter < 2) { + const tt = Date.now() + 5 * 1000; + waitingTimer = new Date(tt); + } else { + waitingTimer = null; + } + + System.log("Counter: " + counter); + System.log("Waiting Timer: " + waitingTimer); + } + + @Item({ target: "execute", exception: "" }) + @RootItem() + public start() { + System.log("Starting workflow"); + } + + @WaitingTimerItem({ target: "execute" }) + public waitForEvent(@In waitingTimer: Date) { + } } ``` diff --git a/docs/versions/latest/Release.md b/docs/versions/latest/Release.md index bc2f9cb59..feba88e08 100644 --- a/docs/versions/latest/Release.md +++ b/docs/versions/latest/Release.md @@ -26,7 +26,88 @@ [//]: # (Improvements -> Bugfixes/hotfixes or general improvements) -### *New `WorkflowItem` decorator for Workflows +### *New `ScheduledWorkflowItem` decorator for Workflows* + +The new decorator gives you the ability to specify a canvas item that schedules a Workflow. + +- `@ScheduledWorkflowItem({target: "", linkedItem: "" })` + - `target` - The name of the next in line item. + - `linkedItem` - The ID of the workflow to schedule + +In order to bind inputs and outputs, you do it with the `@In` and `@Out` decorators. This is the same way we do it for other items. + +#### Inputs + +Special input is needed for the ScheduledWorkflowItem. + +- `workflowScheduleDate` - {Date} is required. The name **must** be `workflowScheduleDate`. If this is missing an error is thrown. We don't check if the type is `Date` but Aria Orchestrator will complain. + +#### Outputs + +Special output is needed for the ScheduledWorkflowItem. + +- `scheduledTask` - {Task} is optional. If it's missing nothing will happen, if it's added, then the name **must** be `scheduledTask`. This is the task that is scheduled. + +#### Example + +```ts +import { Workflow, Out, In, Item, RootItem, ScheduledWorkflowItem } from "vrotsc-annotations"; + +@Workflow({ + name: "Scheduled Workflow Test", + path: "VMware/PSCoE", + description: "Scheduling another workflow and binding values correctly", + attributes: { + waitingTimer: { + type: "Date" + }, + counter: { + type: "number" + }, + first: { + type: "number" + }, + second: { + type: "number" + }, + workflowScheduleDate: { + type: "Date" + }, + scheduledTask: { + type: "Task" + } + } +}) +export class HandleNetworkConfigurationBackup { + @ScheduledWorkflowItem({ + target: "printScheduledDetails", + linkedItem: "9e4503db-cbaa-435a-9fad-144409c08df0" + }) + public scheduleOtherWf(@In first: number, @In second: number, @In workflowScheduleDate: Date, @Out scheduledTask: Task) { + } + + @Item({ target: "scheduleOtherWf" }) + public prepareItems(@In @Out first: number, @In @Out second: number, @In @Out workflowScheduleDate: Date) { + first = 1; + second = 2; + workflowScheduleDate = System.getDate("1 minute from now", undefined); + } + + @Item({ target: "end" }) + public printScheduledDetails(@In scheduledTask: Task) { + System.log(`Scheduled task: ${scheduledTask.id}, [${scheduledTask.state}]`); + } + + + @Item({ target: "prepareItems", exception: "" }) + @RootItem() + public start() { + System.log("Starting workflow"); + } +} +``` + +### *New `WorkflowItem` decorator for Workflows* The new Decorator gives you the ability to specify a canvas item that calls a Workflow. From f1465102f70fc1ac7a5a83d6a513a76f7749ad90 Mon Sep 17 00:00:00 2001 From: Stefan Genov Date: Fri, 19 Jul 2024 18:23:39 +0300 Subject: [PATCH 18/67] style: linting errors Signed-off-by: Stefan Genov --- .../typescript/Components/Workflows.md | 180 +++++++++--------- docs/versions/latest/Release.md | 96 +++++----- 2 files changed, 138 insertions(+), 138 deletions(-) diff --git a/docs/versions/latest/Components/Archetypes/typescript/Components/Workflows.md b/docs/versions/latest/Components/Archetypes/typescript/Components/Workflows.md index fa70a0449..5868b86bb 100644 --- a/docs/versions/latest/Components/Archetypes/typescript/Components/Workflows.md +++ b/docs/versions/latest/Components/Archetypes/typescript/Components/Workflows.md @@ -90,97 +90,97 @@ This is a meta decorator. Add this to whichever function you want to be the entr import { Workflow, Out, In, Item, RootItem, DecisionItem, WaitingTimerItem, WorkflowItem, ScheduledWorkflowItem } from "vrotsc-annotations"; @Workflow({ - name: "Example Waiting Timer", - path: "VMware/PSCoE", - attributes: { - waitingTimer: { - type: "Date" - }, - counter: { - type: "number" - }, - first: { - type: "number" - }, - second: { - type: "number" - }, - result: { - type: "number" - }, - workflowScheduleDate: { - type: "Date" - }, - scheduledTask: { - type: "Task" - } - } + name: "Example Waiting Timer", + path: "VMware/PSCoE", + attributes: { + waitingTimer: { + type: "Date" + }, + counter: { + type: "number" + }, + first: { + type: "number" + }, + second: { + type: "number" + }, + result: { + type: "number" + }, + workflowScheduleDate: { + type: "Date" + }, + scheduledTask: { + type: "Task" + } + } }) export class HandleNetworkConfigurationBackup { - @DecisionItem({ target: "waitForEvent", else: "prepareItems" }) - public decisionElement(waitingTimer: Date) { - return waitingTimer !== null; - } - - @Item({ target: "callOtherWf" }) - public prepareItems(@In @Out first: number, @In @Out second: number, @In @Out workflowScheduleDate: Date) { - first = 1; - second = 2; - workflowScheduleDate = System.getDate("1 minute from now", undefined); - } - - @WorkflowItem({ - target: "print", - linkedItem: "9e4503db-cbaa-435a-9fad-144409c08df0" - }) - public callOtherWf(@In first: number, @In second: number, @Out result: number) { - } - - - @Item({ target: "scheduleOtherWf" }) - public print(@In result: number) { - System.log("Result: " + result); - } - - @ScheduledWorkflowItem({ - target: "printScheduledDetails", - linkedItem: "9e4503db-cbaa-435a-9fad-144409c08df0" - }) - public scheduleOtherWf(@In first: number, @In second: number, @In workflowScheduleDate: Date, @Out scheduledTask: Task) { - } - - @Item({ target: "end" }) - public printScheduledDetails(@In scheduledTask: Task) { - System.log(`Scheduled task: ${scheduledTask.id}, [${scheduledTask.state}]`); - } - - @Item({ target: "decisionElement", exception: "" }) - public execute(@Out @In waitingTimer: Date, @Out @In counter: number): void { - if (!counter) { - counter = 0; - } - - counter++; - - if (counter < 2) { - const tt = Date.now() + 5 * 1000; - waitingTimer = new Date(tt); - } else { - waitingTimer = null; - } - - System.log("Counter: " + counter); - System.log("Waiting Timer: " + waitingTimer); - } - - @Item({ target: "execute", exception: "" }) - @RootItem() - public start() { - System.log("Starting workflow"); - } - - @WaitingTimerItem({ target: "execute" }) - public waitForEvent(@In waitingTimer: Date) { - } + @DecisionItem({ target: "waitForEvent", else: "prepareItems" }) + public decisionElement(waitingTimer: Date) { + return waitingTimer !== null; + } + + @Item({ target: "callOtherWf" }) + public prepareItems(@In @Out first: number, @In @Out second: number, @In @Out workflowScheduleDate: Date) { + first = 1; + second = 2; + workflowScheduleDate = System.getDate("1 minute from now", undefined); + } + + @WorkflowItem({ + target: "print", + linkedItem: "9e4503db-cbaa-435a-9fad-144409c08df0" + }) + public callOtherWf(@In first: number, @In second: number, @Out result: number) { + } + + + @Item({ target: "scheduleOtherWf" }) + public print(@In result: number) { + System.log("Result: " + result); + } + + @ScheduledWorkflowItem({ + target: "printScheduledDetails", + linkedItem: "9e4503db-cbaa-435a-9fad-144409c08df0" + }) + public scheduleOtherWf(@In first: number, @In second: number, @In workflowScheduleDate: Date, @Out scheduledTask: Task) { + } + + @Item({ target: "end" }) + public printScheduledDetails(@In scheduledTask: Task) { + System.log(`Scheduled task: ${scheduledTask.id}, [${scheduledTask.state}]`); + } + + @Item({ target: "decisionElement", exception: "" }) + public execute(@Out @In waitingTimer: Date, @Out @In counter: number): void { + if (!counter) { + counter = 0; + } + + counter++; + + if (counter < 2) { + const tt = Date.now() + 5 * 1000; + waitingTimer = new Date(tt); + } else { + waitingTimer = null; + } + + System.log("Counter: " + counter); + System.log("Waiting Timer: " + waitingTimer); + } + + @Item({ target: "execute", exception: "" }) + @RootItem() + public start() { + System.log("Starting workflow"); + } + + @WaitingTimerItem({ target: "execute" }) + public waitForEvent(@In waitingTimer: Date) { + } } ``` diff --git a/docs/versions/latest/Release.md b/docs/versions/latest/Release.md index feba88e08..340fcfd23 100644 --- a/docs/versions/latest/Release.md +++ b/docs/versions/latest/Release.md @@ -54,56 +54,56 @@ Special output is needed for the ScheduledWorkflowItem. import { Workflow, Out, In, Item, RootItem, ScheduledWorkflowItem } from "vrotsc-annotations"; @Workflow({ - name: "Scheduled Workflow Test", - path: "VMware/PSCoE", - description: "Scheduling another workflow and binding values correctly", - attributes: { - waitingTimer: { - type: "Date" - }, - counter: { - type: "number" - }, - first: { - type: "number" - }, - second: { - type: "number" - }, - workflowScheduleDate: { - type: "Date" - }, - scheduledTask: { - type: "Task" - } - } + name: "Scheduled Workflow Test", + path: "VMware/PSCoE", + description: "Scheduling another workflow and binding values correctly", + attributes: { + waitingTimer: { + type: "Date" + }, + counter: { + type: "number" + }, + first: { + type: "number" + }, + second: { + type: "number" + }, + workflowScheduleDate: { + type: "Date" + }, + scheduledTask: { + type: "Task" + } + } }) export class HandleNetworkConfigurationBackup { - @ScheduledWorkflowItem({ - target: "printScheduledDetails", - linkedItem: "9e4503db-cbaa-435a-9fad-144409c08df0" - }) - public scheduleOtherWf(@In first: number, @In second: number, @In workflowScheduleDate: Date, @Out scheduledTask: Task) { - } - - @Item({ target: "scheduleOtherWf" }) - public prepareItems(@In @Out first: number, @In @Out second: number, @In @Out workflowScheduleDate: Date) { - first = 1; - second = 2; - workflowScheduleDate = System.getDate("1 minute from now", undefined); - } - - @Item({ target: "end" }) - public printScheduledDetails(@In scheduledTask: Task) { - System.log(`Scheduled task: ${scheduledTask.id}, [${scheduledTask.state}]`); - } - - - @Item({ target: "prepareItems", exception: "" }) - @RootItem() - public start() { - System.log("Starting workflow"); - } + @ScheduledWorkflowItem({ + target: "printScheduledDetails", + linkedItem: "9e4503db-cbaa-435a-9fad-144409c08df0" + }) + public scheduleOtherWf(@In first: number, @In second: number, @In workflowScheduleDate: Date, @Out scheduledTask: Task) { + } + + @Item({ target: "scheduleOtherWf" }) + public prepareItems(@In @Out first: number, @In @Out second: number, @In @Out workflowScheduleDate: Date) { + first = 1; + second = 2; + workflowScheduleDate = System.getDate("1 minute from now", undefined); + } + + @Item({ target: "end" }) + public printScheduledDetails(@In scheduledTask: Task) { + System.log(`Scheduled task: ${scheduledTask.id}, [${scheduledTask.state}]`); + } + + + @Item({ target: "prepareItems", exception: "" }) + @RootItem() + public start() { + System.log("Starting workflow"); + } } ``` From 3c61a766af83ade9d5f2c41a363dc3a195b6f198 Mon Sep 17 00:00:00 2001 From: Alexander Kantchev Date: Mon, 22 Jul 2024 11:55:07 +0300 Subject: [PATCH 19/67] [Task 340] code: Updated test workflows methods not to contain parameters. Signed-off-by: Alexander Kantchev --- .../vrotsc/e2e/cases/canvas-items/end-item-exception.wf.ts | 2 +- typescript/vrotsc/e2e/cases/canvas-items/workflow.wf.ts | 5 +++-- .../workflows/VMware/PSCoE/Workflow End Exception.xml | 2 +- .../canvas-items/workflows/VMware/PSCoE/Workflow Test.xml | 4 ++-- .../workflow/decorators/endItemDecoratorStrategy.ts | 7 +++---- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/typescript/vrotsc/e2e/cases/canvas-items/end-item-exception.wf.ts b/typescript/vrotsc/e2e/cases/canvas-items/end-item-exception.wf.ts index 445fcaabd..c723de7e9 100644 --- a/typescript/vrotsc/e2e/cases/canvas-items/end-item-exception.wf.ts +++ b/typescript/vrotsc/e2e/cases/canvas-items/end-item-exception.wf.ts @@ -28,7 +28,7 @@ export class WorkflowEnd { exceptionVariable: "errorMessage", businessStatus: "Bad" }) - public workflowEnd(@In endMode: number, @Out errorMessage: string) { + public workflowEnd() { // NOOP } } diff --git a/typescript/vrotsc/e2e/cases/canvas-items/workflow.wf.ts b/typescript/vrotsc/e2e/cases/canvas-items/workflow.wf.ts index 109401b64..42006c1e3 100644 --- a/typescript/vrotsc/e2e/cases/canvas-items/workflow.wf.ts +++ b/typescript/vrotsc/e2e/cases/canvas-items/workflow.wf.ts @@ -81,9 +81,10 @@ export class HandleNetworkConfigurationBackup { @WorkflowEndItem({ endMode: 0, - exceptionVariable: "errorMessage" + exceptionVariable: "errorMessage", + businessStatus: "Bad" }) - public workflowEnd(@In endMode: number, @Out errorMessage: string) { + public workflowEnd() { // NOOP } } diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Exception.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Exception.xml index 5853b2d8b..bb352e32e 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Exception.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Exception.xml @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow Test.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow Test.xml index d41771283..d256e6a7f 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow Test.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow Test.xml @@ -1,4 +1,4 @@ - \ No newline at end of file +]]> \ No newline at end of file diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/endItemDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/endItemDecoratorStrategy.ts index b6da079bb..040de72fa 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/endItemDecoratorStrategy.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/endItemDecoratorStrategy.ts @@ -25,10 +25,9 @@ const yBasePosition = 100; const offSet = 20; /** - * * Responsible for printing out the workflow end item. - * The following decorator properties are supported - * 1. exception - exception variable + * The following decorator properties are supported: + * 1. exceptionVariable - exception variable used within the component. * 2. endMode - end mode of the component (0 means success, 1 means error). * 3. businessStatus - business status of the end component. * @example @@ -109,7 +108,7 @@ export default class EndItemDecoratorStrategy implements CanvasItemDecoratorStra printItem(itemInfo: WorkflowItemDescriptor, pos: number): string { const stringBuilder = new StringBuilderClass("", ""); - const endMode = itemInfo?.canvasItemPolymorphicBag?.endMode; + const endMode = itemInfo?.canvasItemPolymorphicBag?.endMode ?? 0; const exceptionVariable = itemInfo?.canvasItemPolymorphicBag?.exceptionVariable; const businessStatus = itemInfo?.canvasItemPolymorphicBag?.businessStatus; From 3932ea34d1ef888f515767a9756ccfa27b4704ee Mon Sep 17 00:00:00 2001 From: Alexander Kantchev Date: Mon, 22 Jul 2024 11:57:54 +0300 Subject: [PATCH 20/67] [Task 340] code: Removed unused imports in test workflows. Signed-off-by: Alexander Kantchev --- .../vrotsc/e2e/cases/canvas-items/end-item-exception.wf.ts | 2 +- typescript/vrotsc/e2e/cases/canvas-items/end-item-happy.wf.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/typescript/vrotsc/e2e/cases/canvas-items/end-item-exception.wf.ts b/typescript/vrotsc/e2e/cases/canvas-items/end-item-exception.wf.ts index c723de7e9..d03ab535f 100644 --- a/typescript/vrotsc/e2e/cases/canvas-items/end-item-exception.wf.ts +++ b/typescript/vrotsc/e2e/cases/canvas-items/end-item-exception.wf.ts @@ -1,4 +1,4 @@ -import { Workflow, In, Out, RootItem, WorkflowEndItem } from "vrotsc-annotations"; +import { Workflow, RootItem, WorkflowEndItem } from "vrotsc-annotations"; @Workflow({ name: "Workflow End Exception", diff --git a/typescript/vrotsc/e2e/cases/canvas-items/end-item-happy.wf.ts b/typescript/vrotsc/e2e/cases/canvas-items/end-item-happy.wf.ts index 68f66c93a..42bb8e811 100644 --- a/typescript/vrotsc/e2e/cases/canvas-items/end-item-happy.wf.ts +++ b/typescript/vrotsc/e2e/cases/canvas-items/end-item-happy.wf.ts @@ -1,4 +1,4 @@ -import { Workflow, In, Out, RootItem, WorkflowEndItem } from "vrotsc-annotations"; +import { Workflow, RootItem, WorkflowEndItem } from "vrotsc-annotations"; @Workflow({ name: "Workflow End Happy", From 18c4e1c217f32feed82830e646ca050cba0afab8 Mon Sep 17 00:00:00 2001 From: Alexander Kantchev Date: Mon, 22 Jul 2024 12:07:27 +0300 Subject: [PATCH 21/67] [Task 340] docs: Updated examples, added parameter docs. Signed-off-by: Alexander Kantchev --- .../typescript/Components/Workflows.md | 7 +++--- docs/versions/latest/Release.md | 23 ++++++++----------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/docs/versions/latest/Components/Archetypes/typescript/Components/Workflows.md b/docs/versions/latest/Components/Archetypes/typescript/Components/Workflows.md index ebb7a21fb..11184903a 100644 --- a/docs/versions/latest/Components/Archetypes/typescript/Components/Workflows.md +++ b/docs/versions/latest/Components/Archetypes/typescript/Components/Workflows.md @@ -12,6 +12,7 @@ How to use Aria Orchestrator Workflows and available decorators. - [`@WaitingTimerItem`](#waitingtimeritem) - [`@DecisionItem`](#decisionitem) - [`@RootItem`](#rootitem) + - [`@WorkflowEndItem`](#workflowenditem) 3. [Example Workflow](#example-workflow) ### Workflow Decorator @@ -28,8 +29,7 @@ The decorator is used to specify a custom workflow end item. - `endMode` - End mode of the component, could be one of 0 or 1, where 0 is exit success and 1 is error. - `exceptionVariable` - Exception variable that will hold the exception data when triggered. - -In order to bind inputs and outputs, you do it with the `@Out` decorator. This is the same way we do it for other items. +- `businessStatus` - Value of the business status in the end component. #### `@Item` @@ -172,8 +172,9 @@ export class HandleNetworkConfigurationBackup { @WorkflowEndItem({ endMode: 0, exception: "errorMessage", + businessStatus: "Bad" }) - public workflowEnd(@In endMode: number, @Out errorMessage: string) { + public workflowEnd() { // NOOP } } diff --git a/docs/versions/latest/Release.md b/docs/versions/latest/Release.md index dacea39fa..3eefe4de2 100644 --- a/docs/versions/latest/Release.md +++ b/docs/versions/latest/Release.md @@ -32,28 +32,24 @@ The decorator is used to specify a custom workflow end item. - `endMode` - End mode of the component, could be one of 0 or 1, where 0 is exit success and 1 is error. - `exceptionVariable` - Exception variable that will hold the exception data when triggered. - -In order to bind inputs and outputs, you do it with the `@Out` decorator. This is the same way we do it for other items. +- `businessStatus` - Value of the business status in the end component. Example: ```typescript -import { - Workflow, - In, - Out, - RootItem, - WorkflowEndItem, -} from "vrotsc-annotations"; +import { Workflow, RootItem, WorkflowEndItem } from "vrotsc-annotations"; @Workflow({ - name: "Workflow End Happy", + name: "Workflow End Exception", path: "VMware/PSCoE", - description: "Workflow with root and end item", + description: "Workflow with root and end item with end mode 1", attributes: { errorMessage: { type: "string", }, + businessStatus: { + type: "string", + }, endMode: { type: "number", }, @@ -67,9 +63,10 @@ export class WorkflowEnd { @WorkflowEndItem({ endMode: 1, - exception: "errorMessage", + exceptionVariable: "errorMessage", + businessStatus: "Bad", }) - public workflowEnd(@In endMode: number, @Out errorMessage: string) { + public workflowEnd() { // NOOP } } From 65e1e9068bbd3ec3bed1ccf82c21b4bfd445e7ec Mon Sep 17 00:00:00 2001 From: Alexander Kantchev Date: Mon, 22 Jul 2024 15:18:50 +0300 Subject: [PATCH 22/67] [Task 339] docs: Updated examples. Signed-off-by: Alexander Kantchev --- .../typescript/Components/Workflows.md | 35 ++++++++++++++---- docs/versions/latest/Release.md | 37 ++++++++++++++----- 2 files changed, 55 insertions(+), 17 deletions(-) diff --git a/docs/versions/latest/Components/Archetypes/typescript/Components/Workflows.md b/docs/versions/latest/Components/Archetypes/typescript/Components/Workflows.md index d1d3ce0bb..96aa08584 100644 --- a/docs/versions/latest/Components/Archetypes/typescript/Components/Workflows.md +++ b/docs/versions/latest/Components/Archetypes/typescript/Components/Workflows.md @@ -35,15 +35,19 @@ Example: ```typescript import { Workflow, - Out, RootItem, + In, + Out, + Item, DefaultErrorHandler, + WorkflowEndItem, } from "vrotsc-annotations"; @Workflow({ - name: "Default Error Handler" + name: "Default Error Handler Custom Item", path: "VMware/PSCoE", - description: "Default error handler workflow", + description: + "Default error handler workflow with error handler redirecting to a workflow item", attributes: { errorMessage: { type: "string", @@ -53,16 +57,33 @@ import { export class HandleDefaultError { @RootItem() public initiateWorkflow() { - // NOOP + System.log("Initiating workflow execution"); + } + + @Item({ + target: "workflowEnd", + }) + public processError(@In errorMessage: string) { + System.log( + `Processing error using custom task with message '${errorMessage}'` + ); } @DefaultErrorHandler({ exceptionVariable: "errorMessage", - target: "end" + target: "processError", }) - public defaultErrorHandler() { + public defaultErrorHandler(@Out errorMessage: string) { // NOOP } + + @WorkflowEndItem({ + endMode: 0, + exceptionVariable: "errorMessage", + }) + public workflowEnd(@Out errorMessage: string) { + System.log(`Terminating workflow with error ${errorMessage}`); + } } ``` @@ -219,7 +240,7 @@ export class HandleNetworkConfigurationBackup { @WorkflowEndItem({ endMode: 0, exception: "errorMessage", - businessStatus: "Bad" + businessStatus: "Bad", }) public workflowEnd() { // NOOP diff --git a/docs/versions/latest/Release.md b/docs/versions/latest/Release.md index 0d6c937be..06cc2b160 100644 --- a/docs/versions/latest/Release.md +++ b/docs/versions/latest/Release.md @@ -40,15 +40,19 @@ Example: ```typescript import { Workflow, - Out, RootItem, + In, + Out, + Item, DefaultErrorHandler, + WorkflowEndItem, } from "vrotsc-annotations"; @Workflow({ - name: "Default Error Handler" + name: "Default Error Handler Custom Item", path: "VMware/PSCoE", - description: "Default error handler workflow", + description: + "Default error handler workflow with error handler redirecting to a workflow item", attributes: { errorMessage: { type: "string", @@ -58,16 +62,33 @@ import { export class HandleDefaultError { @RootItem() public initiateWorkflow() { - // NOOP + System.log("Initiating workflow execution"); + } + + @Item({ + target: "workflowEnd", + }) + public processError(@In errorMessage: string) { + System.log( + `Processing error using custom task with message '${errorMessage}'` + ); } @DefaultErrorHandler({ exceptionVariable: "errorMessage", - target: "end" + target: "processError", }) - public defaultErrorHandler() { + public defaultErrorHandler(@Out errorMessage: string) { // NOOP } + + @WorkflowEndItem({ + endMode: 0, + exceptionVariable: "errorMessage", + }) + public workflowEnd(@Out errorMessage: string) { + System.log(`Terminating workflow with error ${errorMessage}`); + } } ``` @@ -216,13 +237,9 @@ export class HandleNetworkConfigurationBackup { } @WaitingTimerItem({ target: "execute" }) -<<<<<<< HEAD - public waitForEvent(@In waitingTimer: Date) {} -======= public waitForEvent(@In waitingTimer: Date) { // NOOP } ->>>>>>> main } ``` From c9b453b31c721d2304360592a0bcfafea6b80fea Mon Sep 17 00:00:00 2001 From: Alexander Kantchev Date: Mon, 22 Jul 2024 15:21:31 +0300 Subject: [PATCH 23/67] [Task 339] docs: Updated links. Signed-off-by: Alexander Kantchev --- .../Components/Archetypes/typescript/Components/Workflows.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/versions/latest/Components/Archetypes/typescript/Components/Workflows.md b/docs/versions/latest/Components/Archetypes/typescript/Components/Workflows.md index 96aa08584..23e3d82a7 100644 --- a/docs/versions/latest/Components/Archetypes/typescript/Components/Workflows.md +++ b/docs/versions/latest/Components/Archetypes/typescript/Components/Workflows.md @@ -12,6 +12,7 @@ How to use Aria Orchestrator Workflows and available decorators. - [`@WaitingTimerItem`](#waitingtimeritem) - [`@DecisionItem`](#decisionitem) - [`@RootItem`](#rootitem) + - [`@DefaultErrorHandler`](#defaulterrorhandler) - [`@WorkflowEndItem`](#workflowenditem) 3. [Example Workflow](#example-workflow) @@ -19,7 +20,7 @@ How to use Aria Orchestrator Workflows and available decorators. Not implemented yet. -### \*New `DefaultErrorHandler` decorator for Workflows +#### `@DefaultErrorHandler` This decorator is used to specify a default error handler. It can be bound either to a workflow item component or workflow end. From 236cb2e3b9a099590c70fc58dcc74cc4e0b2c39a Mon Sep 17 00:00:00 2001 From: Stefan Genov Date: Mon, 22 Jul 2024 17:24:48 +0300 Subject: [PATCH 24/67] fix: Pr fixes Signed-off-by: Stefan Genov --- docs/versions/latest/Release.md | 117 +++++++----------- typescript/vrotsc/src/compiler/decorators.ts | 1 - .../workflow/decorators/helpers/sourceFile.ts | 2 +- .../scheduledWorkflowItemDecoratorStrategy.ts | 18 +++ 4 files changed, 67 insertions(+), 71 deletions(-) diff --git a/docs/versions/latest/Release.md b/docs/versions/latest/Release.md index 9f222c12c..40a0c2409 100644 --- a/docs/versions/latest/Release.md +++ b/docs/versions/latest/Release.md @@ -165,12 +165,11 @@ Special output is needed for the ScheduledWorkflowItem. #### Example ```ts -import { Workflow, Out, In, Item, RootItem, ScheduledWorkflowItem } from "vrotsc-annotations"; +import { Workflow, Out, In, Item, RootItem, DecisionItem, WaitingTimerItem, WorkflowItem, ScheduledWorkflowItem } from "vrotsc-annotations"; @Workflow({ - name: "Scheduled Workflow Test", + name: "Example Waiting Timer", path: "VMware/PSCoE", - description: "Scheduling another workflow and binding values correctly", attributes: { waitingTimer: { type: "Date" @@ -184,6 +183,9 @@ import { Workflow, Out, In, Item, RootItem, ScheduledWorkflowItem } from "vrotsc second: { type: "number" }, + result: { + type: "number" + }, workflowScheduleDate: { type: "Date" }, @@ -193,93 +195,70 @@ import { Workflow, Out, In, Item, RootItem, ScheduledWorkflowItem } from "vrotsc } }) export class HandleNetworkConfigurationBackup { - @ScheduledWorkflowItem({ - target: "printScheduledDetails", - linkedItem: "9e4503db-cbaa-435a-9fad-144409c08df0" - }) - public scheduleOtherWf(@In first: number, @In second: number, @In workflowScheduleDate: Date, @Out scheduledTask: Task) { + @DecisionItem({ target: "waitForEvent", else: "prepareItems" }) + public decisionElement(waitingTimer: Date) { + return waitingTimer !== null; } - @Item({ target: "scheduleOtherWf" }) + @Item({ target: "callOtherWf" }) public prepareItems(@In @Out first: number, @In @Out second: number, @In @Out workflowScheduleDate: Date) { first = 1; second = 2; workflowScheduleDate = System.getDate("1 minute from now", undefined); } - @Item({ target: "end" }) - public printScheduledDetails(@In scheduledTask: Task) { - System.log(`Scheduled task: ${scheduledTask.id}, [${scheduledTask.state}]`); + @WorkflowItem({ + target: "print", + linkedItem: "9e4503db-cbaa-435a-9fad-144409c08df0" + }) + public callOtherWf(@In first: number, @In second: number, @Out result: number) { } - @Item({ target: "prepareItems", exception: "" }) - @RootItem() - public start() { - System.log("Starting workflow"); -======= -This decorator is used to specify a default error handler. It can be bound either to a workflow item component or workflow end. - -#### Supported Parameters + @Item({ target: "scheduleOtherWf" }) + public print(@In result: number) { + System.log("Result: " + result); + } -- `target` - target item to be attached to the default error handler, could be one of workflow item or workflow end. -- `exceptionVariable` - Exception variable that will hold the exception data when triggered. + @ScheduledWorkflowItem({ + target: "printScheduledDetails", + linkedItem: "9e4503db-cbaa-435a-9fad-144409c08df0" + }) + public scheduleOtherWf(@In first: number, @In second: number, @In workflowScheduleDate: Date, @Out scheduledTask: Task) { + } -In order to bind inputs and outputs, you do it with the `@In` and `@Out` decorators. This is the same way we do it for other items. + @Item({ target: "end" }) + public printScheduledDetails(@In scheduledTask: Task) { + System.log(`Scheduled task: ${scheduledTask.id}, [${scheduledTask.state}]`); + } -Example: + @Item({ target: "decisionElement", exception: "" }) + public execute(@Out @In waitingTimer: Date, @Out @In counter: number): void { + if (!counter) { + counter = 0; + } -```typescript -import { - Workflow, - RootItem, - In, - Out, - Item, - DefaultErrorHandler, - WorkflowEndItem, -} from "vrotsc-annotations"; + counter++; -@Workflow({ - name: "Default Error Handler Custom Item", - path: "VMware/PSCoE", - description: - "Default error handler workflow with error handler redirecting to a workflow item", - attributes: { - errorMessage: { - type: "string", - }, - }, -}) -export class HandleDefaultError { - @RootItem() - public initiateWorkflow() { - System.log("Initiating workflow execution"); - } + if (counter < 2) { + const tt = Date.now() + 5 * 1000; + waitingTimer = new Date(tt); + } else { + waitingTimer = null; + } - @Item({ - target: "workflowEnd", - }) - public processError(@In errorMessage: string) { - System.log( - `Processing error using custom task with message '${errorMessage}'` - ); + System.log("Counter: " + counter); + System.log("Waiting Timer: " + waitingTimer); } - @DefaultErrorHandler({ - exceptionVariable: "errorMessage", - target: "processError", - }) - public defaultErrorHandler(@Out errorMessage: string) { - // NOOP + @Item({ target: "execute", exception: "" }) + @RootItem() + public start() { + System.log("Starting workflow"); } - @WorkflowEndItem({ - endMode: 0, - exceptionVariable: "errorMessage", - }) - public workflowEnd(@Out errorMessage: string) { - System.log(`Terminating workflow with error ${errorMessage}`); + @WaitingTimerItem({ target: "execute" }) + public waitForEvent(@In waitingTimer: Date) { } } ``` diff --git a/typescript/vrotsc/src/compiler/decorators.ts b/typescript/vrotsc/src/compiler/decorators.ts index 362f56789..9597051c3 100644 --- a/typescript/vrotsc/src/compiler/decorators.ts +++ b/typescript/vrotsc/src/compiler/decorators.ts @@ -148,7 +148,6 @@ export enum WorkflowItemType { * It can target a workflow item or workflow end and accepts input and output bindings. */ DefaultErrorHandler = "DefaultErrorHandler", - } /////////////////////////////////// Polyglot Decorator /////////////////////////////////// diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/helpers/sourceFile.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/helpers/sourceFile.ts index d3c8d2c6f..3acd5c69a 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/helpers/sourceFile.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/helpers/sourceFile.ts @@ -18,7 +18,7 @@ import { createWorkflowItemPrologueStatements } from "../../../../codeTransforme import { WorkflowItemDescriptor } from "../../../../../decorators"; export interface SourceFilePrinter { - printSourceFile(methodNode: MethodDeclaration, sourceFile: SourceFile, itemInfo?: WorkflowItemDescriptor): string; + printSourceFile(methodNode: MethodDeclaration, sourceFile: SourceFile, itemInfo: WorkflowItemDescriptor): string; } /** diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/scheduledWorkflowItemDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/scheduledWorkflowItemDecoratorStrategy.ts index 1ce28b9d8..3e3002b3b 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/scheduledWorkflowItemDecoratorStrategy.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/scheduledWorkflowItemDecoratorStrategy.ts @@ -55,14 +55,32 @@ scheduledTask = workflowToLaunch.schedule(workflowParameters, workflowScheduleDa export default class ScheduledWorkflowItemDecoratorStrategy implements CanvasItemDecoratorStrategy { constructor(private readonly sourceFilePrinter: SourceFilePrinter = new ScheduledWorkflowItemSourceFilePrinter()) { } + /** + * @returns The type of canvas item + */ getCanvasType(): string { return "task"; } + /** + * @returns The type of decorator + */ getDecoratorType(): WorkflowItemType { return WorkflowItemType.ScheduledWorkflow; } + /** + * Registers the item arguments + * + * - `target` is the name of the item to call after the item is executed + * - `exception` is the exception to throw if the item fails + * - `linkedItem` is the id of the workflow to schedule + * + * @param itemInfo The item to register + * @param decoratorNode The decorator node + * @returns void + * @throws Error if an unsupported attribute is found + */ registerItemArguments(itemInfo: WorkflowItemDescriptor, decoratorNode: Decorator): void { getDecoratorProps(decoratorNode).forEach((propTuple) => { const [propName, propValue] = propTuple; From 50cc0ac982731830391b3f251abb171a1a80078b Mon Sep 17 00:00:00 2001 From: Stefan Genov Date: Mon, 22 Jul 2024 17:25:19 +0300 Subject: [PATCH 25/67] fix: Remove unused case for `exception` Signed-off-by: Stefan Genov --- .../decorators/scheduledWorkflowItemDecoratorStrategy.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/scheduledWorkflowItemDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/scheduledWorkflowItemDecoratorStrategy.ts index 3e3002b3b..f8babf6c4 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/scheduledWorkflowItemDecoratorStrategy.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/scheduledWorkflowItemDecoratorStrategy.ts @@ -89,10 +89,6 @@ export default class ScheduledWorkflowItemDecoratorStrategy implements CanvasIte itemInfo.target = propValue; break; - case "exception": - itemInfo.canvasItemPolymorphicBag.exception = propValue; - break; - case "linkedItem": itemInfo.canvasItemPolymorphicBag.linkedItem = propValue; break; From 8fc1d4f2a264c9caf92659a54dd9a40f3a1bae19 Mon Sep 17 00:00:00 2001 From: Alexander Kantchev Date: Tue, 23 Jul 2024 10:42:09 +0300 Subject: [PATCH 26/67] [Task 337] fix: Add itemInfo parameter to decorators. Signed-off-by: Alexander Kantchev --- .../workflow/decorators/defaultErrorHandlerDecoratorStrategy.ts | 2 +- .../workflow/decorators/endItemDecoratorStrategy.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/defaultErrorHandlerDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/defaultErrorHandlerDecoratorStrategy.ts index 1115b2cb6..81a368459 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/defaultErrorHandlerDecoratorStrategy.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/defaultErrorHandlerDecoratorStrategy.ts @@ -90,7 +90,7 @@ export default class DefaultErrorHandlerDecoratorStrategy implements CanvasItemD /** * There is no need to print the source file for the default error handler. */ - public printSourceFile(methodNode: MethodDeclaration, sourceFile: SourceFile): string { + public printSourceFile(methodNode: MethodDeclaration, sourceFile: SourceFile, itemInfo: WorkflowItemDescriptor): string { return ""; } diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/endItemDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/endItemDecoratorStrategy.ts index 040de72fa..f01124c63 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/endItemDecoratorStrategy.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/endItemDecoratorStrategy.ts @@ -93,7 +93,7 @@ export default class EndItemDecoratorStrategy implements CanvasItemDecoratorStra /** * There is no need to print the source file for the workflow item. */ - printSourceFile(methodNode: MethodDeclaration, sourceFile: SourceFile): string { + printSourceFile(methodNode: MethodDeclaration, sourceFile: SourceFile, itemInfo: WorkflowItemDescriptor): string { return ""; } From 0b383c4ee99e80e2c721ca5467aad3b3aab39085 Mon Sep 17 00:00:00 2001 From: Alexander Kantchev Date: Tue, 23 Jul 2024 10:48:32 +0300 Subject: [PATCH 27/67] [Task 337] fix: Remove unused imports. Signed-off-by: Alexander Kantchev --- .../workflow/decorators/decisionItemDecoratorStrategy.ts | 6 +++--- .../decorators/defaultErrorHandlerDecoratorStrategy.ts | 1 - .../workflow/decorators/itemDecoratorStrategy.ts | 6 +++--- .../decorators/scheduledWorkflowItemDecoratorStrategy.ts | 4 ++-- .../decorators/waitingTimerItemDecoratorStrategy.ts | 5 ++--- .../workflow/decorators/workflowItemDecoratorStrategy.ts | 4 ++-- 6 files changed, 12 insertions(+), 14 deletions(-) diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/decisionItemDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/decisionItemDecoratorStrategy.ts index 0dd9beb89..2dd3a5e51 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/decisionItemDecoratorStrategy.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/decisionItemDecoratorStrategy.ts @@ -13,13 +13,13 @@ * #L% */ import { Decorator, MethodDeclaration, SourceFile } from "typescript"; +import { StringBuilderClass } from "../../../../../utilities/stringBuilder"; import { CanvasItemPolymorphicBagForDecision, WorkflowItemDescriptor, WorkflowItemType } from "../../../../decorators"; import { getDecoratorProps } from "../../../helpers/node"; -import CanvasItemDecoratorStrategy from "./canvasItemDecoratorStrategy"; -import { SourceFilePrinter, WrapperSourceFilePrinter } from "./helpers/sourceFile"; -import { StringBuilderClass } from "../../../../../utilities/stringBuilder"; import { findTargetItem } from "../helpers/findTargetItem"; +import CanvasItemDecoratorStrategy from "./canvasItemDecoratorStrategy"; import { InputOutputBindings, buildItemParameterBindings } from "./helpers/presentation"; +import { SourceFilePrinter, WrapperSourceFilePrinter } from "./helpers/sourceFile"; /** * Responsible for printing out decision items diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/defaultErrorHandlerDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/defaultErrorHandlerDecoratorStrategy.ts index 81a368459..215762bd2 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/defaultErrorHandlerDecoratorStrategy.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/defaultErrorHandlerDecoratorStrategy.ts @@ -18,7 +18,6 @@ import { WorkflowItemDescriptor, WorkflowItemType } from "../../../../decorators import { getDecoratorProps } from "../../../helpers/node"; import { findTargetItem } from "../helpers/findTargetItem"; import CanvasItemDecoratorStrategy from "./canvasItemDecoratorStrategy"; -import { buildItemParameterBindings, InputOutputBindings } from "./helpers/presentation"; // UI positioning constants in the output XML file. const xBasePosition = 180; diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/itemDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/itemDecoratorStrategy.ts index 032083df8..74794a5f0 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/itemDecoratorStrategy.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/itemDecoratorStrategy.ts @@ -13,13 +13,13 @@ * #L% */ import { Decorator, MethodDeclaration, SourceFile } from "typescript"; +import { StringBuilderClass } from "../../../../../utilities/stringBuilder"; import { WorkflowItemDescriptor, WorkflowItemType } from "../../../../decorators"; import { getDecoratorProps } from "../../../helpers/node"; +import { findTargetItem } from "../helpers/findTargetItem"; import CanvasItemDecoratorStrategy from "./canvasItemDecoratorStrategy"; -import { DefaultSourceFilePrinter, SourceFilePrinter } from "./helpers/sourceFile"; import { InputOutputBindings, buildItemParameterBindings } from "./helpers/presentation"; -import { findTargetItem } from "../helpers/findTargetItem"; -import { StringBuilderClass } from "../../../../../utilities/stringBuilder"; +import { DefaultSourceFilePrinter, SourceFilePrinter } from "./helpers/sourceFile"; export default class ItemDecoratorStrategy implements CanvasItemDecoratorStrategy { constructor(private readonly sourceFilePrinter: SourceFilePrinter = new DefaultSourceFilePrinter()) { } diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/scheduledWorkflowItemDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/scheduledWorkflowItemDecoratorStrategy.ts index f8babf6c4..4afe08bf7 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/scheduledWorkflowItemDecoratorStrategy.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/scheduledWorkflowItemDecoratorStrategy.ts @@ -13,12 +13,12 @@ * #L% */ import { Decorator, MethodDeclaration, SourceFile } from "typescript"; +import { StringBuilderClass } from "../../../../../utilities/stringBuilder"; import { WorkflowItemDescriptor, WorkflowItemType } from "../../../../decorators"; import { getDecoratorProps } from "../../../helpers/node"; +import { findTargetItem } from "../helpers/findTargetItem"; import CanvasItemDecoratorStrategy from "./canvasItemDecoratorStrategy"; import { InputOutputBindings, buildItemParameterBindings } from "./helpers/presentation"; -import { findTargetItem } from "../helpers/findTargetItem"; -import { StringBuilderClass } from "../../../../../utilities/stringBuilder"; import { ScheduledWorkflowItemSourceFilePrinter, SourceFilePrinter } from "./helpers/sourceFile"; /** diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/waitingTimerItemDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/waitingTimerItemDecoratorStrategy.ts index 69eb9d6ed..b9d75c5c5 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/waitingTimerItemDecoratorStrategy.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/waitingTimerItemDecoratorStrategy.ts @@ -13,12 +13,11 @@ * #L% */ import { Decorator, MethodDeclaration, SourceFile } from "typescript"; +import { StringBuilderClass } from "../../../../../utilities/stringBuilder"; import { WorkflowItemDescriptor, WorkflowItemType } from "../../../../decorators"; import { getDecoratorProps } from "../../../helpers/node"; -import CanvasItemDecoratorStrategy from "./canvasItemDecoratorStrategy"; -import { DefaultSourceFilePrinter, SourceFilePrinter } from "./helpers/sourceFile"; -import { StringBuilderClass } from "../../../../../utilities/stringBuilder"; import { findTargetItem } from "../helpers/findTargetItem"; +import CanvasItemDecoratorStrategy from "./canvasItemDecoratorStrategy"; import { InputOutputBindings, buildItemParameterBindings } from "./helpers/presentation"; /** diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/workflowItemDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/workflowItemDecoratorStrategy.ts index de8f936d1..f0ec1db81 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/workflowItemDecoratorStrategy.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/workflowItemDecoratorStrategy.ts @@ -13,12 +13,12 @@ * #L% */ import { Decorator, MethodDeclaration, SourceFile } from "typescript"; +import { StringBuilderClass } from "../../../../../utilities/stringBuilder"; import { WorkflowItemDescriptor, WorkflowItemType } from "../../../../decorators"; import { getDecoratorProps } from "../../../helpers/node"; +import { findTargetItem } from "../helpers/findTargetItem"; import CanvasItemDecoratorStrategy from "./canvasItemDecoratorStrategy"; import { InputOutputBindings, buildItemParameterBindings } from "./helpers/presentation"; -import { findTargetItem } from "../helpers/findTargetItem"; -import { StringBuilderClass } from "../../../../../utilities/stringBuilder"; /** * From 140c472328f67225f1c44b794ab9b8d2881a08c1 Mon Sep 17 00:00:00 2001 From: Stefan Genov Date: Tue, 23 Jul 2024 16:02:40 +0300 Subject: [PATCH 28/67] feat: New Decorator definitions Signed-off-by: Stefan Genov --- .../@types/vrotsc-annotations/index.d.ts | 57 ++++++++++++------- vro-types/vrotsc-annotations/index.d.ts | 19 +++++++ 2 files changed, 57 insertions(+), 19 deletions(-) diff --git a/typescript/vrotsc/e2e/cases/node_modules/@types/vrotsc-annotations/index.d.ts b/typescript/vrotsc/e2e/cases/node_modules/@types/vrotsc-annotations/index.d.ts index e2a2968b9..dc7f3a68f 100644 --- a/typescript/vrotsc/e2e/cases/node_modules/@types/vrotsc-annotations/index.d.ts +++ b/typescript/vrotsc/e2e/cases/node_modules/@types/vrotsc-annotations/index.d.ts @@ -244,25 +244,6 @@ interface VroWorkflowItemMethodDecorator { (target: Object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor): void; } -// ---------------------------------------------- Scheduled Workflow Canvas Item ------------------------------------------------ - -export declare const ScheduledWorkflowItem: VroScheduledWorkflowItemDecorator; - -interface VroScheduledWorkflowItemDecorator { - (obj?: VroScheduledWorkflowItemConfiguration): VroScheduledWorkflowItemMethodDecorator; - new(obj?: VroScheduledWorkflowItemConfiguration): VroScheduledWorkflowItemConfiguration; -} - -interface VroScheduledWorkflowItemConfiguration { - target?: string; - linkedItem: string; -} - -interface VroScheduledWorkflowItemMethodDecorator { - >(type: T): T; - (target: Object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor): void; -} - // ---------------------------------------------- Workflow Default Error Handler Canvas Item ------------------------------------------------ export declare const DefaultErrorHandler: VroWorkflowDefaultErrorHandlerDecorator; @@ -302,6 +283,44 @@ interface VroWorkflowEndItemMethodDecorator { (target: Object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor): void; } +// ---------------------------------------------- Scheduled Workflow Canvas Item ------------------------------------------------ + +export declare const ScheduledWorkflowItem: VroScheduledWorkflowItemDecorator; + +interface VroScheduledWorkflowItemDecorator { + (obj?: VroScheduledWorkflowItemConfiguration): VroScheduledWorkflowItemMethodDecorator; + new(obj?: VroScheduledWorkflowItemConfiguration): VroScheduledWorkflowItemConfiguration; +} + +interface VroScheduledWorkflowItemConfiguration { + target?: string; + linkedItem: string; +} + +interface VroScheduledWorkflowItemMethodDecorator { + >(type: T): T; + (target: Object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor): void; +} + +// ---------------------------------------------- Async Workflow Canvas Item ------------------------------------------------ + +export declare const AsyncWorkflowItem: VroAsyncWorkflowItemDecorator; + +interface VroAsyncWorkflowItemDecorator { + (obj?: VroAsyncWorkflowItemConfiguration): VroAsyncWorkflowItemMethodDecorator; + new(obj?: VroAsyncWorkflowItemConfiguration): VroAsyncWorkflowItemConfiguration; +} + +interface VroAsyncWorkflowItemConfiguration { + target?: string; + linkedItem: string; +} + +interface VroAsyncWorkflowItemMethodDecorator { + >(type: T): T; + (target: Object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor): void; +} + //--------------------------------------------- POLYGLOT ------------------------------------------------------------------------------- export declare const Polyglot: VroPolyglotDecorator; diff --git a/vro-types/vrotsc-annotations/index.d.ts b/vro-types/vrotsc-annotations/index.d.ts index d7207647f..dc7f3a68f 100644 --- a/vro-types/vrotsc-annotations/index.d.ts +++ b/vro-types/vrotsc-annotations/index.d.ts @@ -302,6 +302,25 @@ interface VroScheduledWorkflowItemMethodDecorator { (target: Object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor): void; } +// ---------------------------------------------- Async Workflow Canvas Item ------------------------------------------------ + +export declare const AsyncWorkflowItem: VroAsyncWorkflowItemDecorator; + +interface VroAsyncWorkflowItemDecorator { + (obj?: VroAsyncWorkflowItemConfiguration): VroAsyncWorkflowItemMethodDecorator; + new(obj?: VroAsyncWorkflowItemConfiguration): VroAsyncWorkflowItemConfiguration; +} + +interface VroAsyncWorkflowItemConfiguration { + target?: string; + linkedItem: string; +} + +interface VroAsyncWorkflowItemMethodDecorator { + >(type: T): T; + (target: Object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor): void; +} + //--------------------------------------------- POLYGLOT ------------------------------------------------------------------------------- export declare const Polyglot: VroPolyglotDecorator; From 390233cecd67695be59b2c5df774c180b6afc467 Mon Sep 17 00:00:00 2001 From: Stefan Genov Date: Tue, 23 Jul 2024 16:02:52 +0300 Subject: [PATCH 29/67] feat: New Source File Printer Signed-off-by: Stefan Genov --- .../workflow/decorators/helpers/sourceFile.ts | 121 ++++++++++++++++++ 1 file changed, 121 insertions(+) diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/helpers/sourceFile.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/helpers/sourceFile.ts index 3acd5c69a..6c2b274d7 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/helpers/sourceFile.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/helpers/sourceFile.ts @@ -191,3 +191,124 @@ export class ScheduledWorkflowItemSourceFilePrinter implements SourceFilePrinter ); } } + +/** + * This is used to print the source file for an async workflow item. + * + * The Async workflow is essentially just a normal task with special representation. + * + * @Example of what is printed: + * ```js +var workflowToLaunch = Server.getWorkflowWithId("9e4503db-cbaa-435a-9fad-144409c08df0"); +if (workflowToLaunch == null) { + throw "Workflow not found"; +} + +var workflowParameters = new Properties(); +workflowParameters.put("first",first); +workflowParameters.put("second",second); +wfToken = workflowToLaunch.execute(workflowParameters); + * ``` + */ +export class AsyncWorkflowItemSourceFilePrinter implements SourceFilePrinter { + printSourceFile(methodNode: MethodDeclaration, sourceFile: SourceFile, itemInfo: WorkflowItemDescriptor): string { + return printSourceFile( + factory.updateSourceFile( + sourceFile, + [ + ...sourceFile.statements.filter(n => n.kind !== SyntaxKind.ClassDeclaration), + ...createWorkflowItemPrologueStatements(methodNode), + // Variable declarations are on top + factory.createVariableStatement( + undefined, + // A list of declarations + factory.createVariableDeclarationList( + [ + // `var workflowParameters = new Properties();` + factory.createVariableDeclaration( + "workflowParameters", + undefined, + undefined, + factory.createNewExpression( + factory.createIdentifier("Properties"), + undefined, + [] + ) + ), + // `, workflowToLaunch = Server.getWorkflowWithId("some id here");` + factory.createVariableDeclaration( + "workflowToLaunch", + undefined, + undefined, + factory.createCallExpression( + factory.createPropertyAccessExpression( + factory.createIdentifier("Server"), + factory.createIdentifier("getWorkflowWithId") + ), + undefined, + [factory.createStringLiteral(itemInfo.canvasItemPolymorphicBag.linkedItem)] + ) + ) + ], + undefined + ) + ), + + // `if (workflowToLaunch == null) { throw "Workflow not found"; }` + factory.createIfStatement( + factory.createBinaryExpression( + factory.createIdentifier("workflowToLaunch"), + factory.createToken(SyntaxKind.EqualsEqualsToken), + factory.createNull() + ), + factory.createBlock( + [ + factory.createThrowStatement( + factory.createStringLiteral("Workflow not found") + ) + ], + true + ) + ), + + // `workflowParameters.put("first",first);` + // `workflowParameters.put("second",second);` + // ...... etc + ...itemInfo.input.map((input) => { + return factory.createExpressionStatement( + factory.createCallExpression( + factory.createPropertyAccessExpression( + factory.createIdentifier("workflowParameters"), + factory.createIdentifier("put") + ), + undefined, + [ + factory.createStringLiteral(input), + factory.createIdentifier(input) + ] + ) + ); + }), + + // `wfToken = workflowToLaunch.execute(workflowParameters);` + factory.createExpressionStatement( + factory.createAssignment( + factory.createIdentifier("wfToken"), + factory.createCallExpression( + factory.createPropertyAccessExpression( + factory.createIdentifier("workflowToLaunch"), + factory.createIdentifier("execute") + ), + undefined, + [ + factory.createIdentifier("workflowParameters") + ] + ) + ) + ) + ] + ) + ); + } +} + From cb3d913fb6ce2b5c7538e3cdc2ffd08285728e08 Mon Sep 17 00:00:00 2001 From: Stefan Genov Date: Tue, 23 Jul 2024 16:03:02 +0300 Subject: [PATCH 30/67] feat: New decorator Signed-off-by: Stefan Genov --- typescript/vrotsc/src/compiler/decorators.ts | 8 + .../fileTransformers/workflow/decorators.ts | 3 + .../asyncWorkflowItemDecoratorStrategy.ts | 167 ++++++++++++++++++ 3 files changed, 178 insertions(+) create mode 100644 typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/asyncWorkflowItemDecoratorStrategy.ts diff --git a/typescript/vrotsc/src/compiler/decorators.ts b/typescript/vrotsc/src/compiler/decorators.ts index 9597051c3..0f25f8592 100644 --- a/typescript/vrotsc/src/compiler/decorators.ts +++ b/typescript/vrotsc/src/compiler/decorators.ts @@ -136,6 +136,14 @@ export enum WorkflowItemType { */ ScheduledWorkflow = "ScheduledWorkflowItem", + + /** + * This item type represents an async workflow item. + * + * It can target a specific item and accepts input and output bindings. + */ + AsyncWorkflow = "AsyncWorkflowItem", + /** * This item type represents a workflow end item. * diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators.ts index bf8f057e2..036f0b31f 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators.ts @@ -26,6 +26,7 @@ import RootItemDecoratorStrategy from "./decorators/rootItemDecoratorStrategy"; import WaitingTimerItemDecoratorStrategy from "./decorators/waitingTimerItemDecoratorStrategy"; import WorkflowItemDecoratorStrategy from "./decorators/workflowItemDecoratorStrategy"; import ScheduledWorkflowItemDecoratorStrategy from "./decorators/scheduledWorkflowItemDecoratorStrategy"; +import AsyncWorkflowItemDecoratorStrategy from "./decorators/asyncWorkflowItemDecoratorStrategy"; /** * Fetches details from the decorators for the methods and adds the information to the Descriptors @@ -89,6 +90,8 @@ function getItemStrategy(decoratorNode: ts.Decorator): CanvasItemDecoratorStrate return new RootItemDecoratorStrategy(); case WorkflowItemType.ScheduledWorkflow: return new ScheduledWorkflowItemDecoratorStrategy(); + case WorkflowItemType.AsyncWorkflow: + return new AsyncWorkflowItemDecoratorStrategy(); case WorkflowItemType.DefaultErrorHandler: return new DefaultErrorHandlerDecoratorStrategy(); case WorkflowItemType.End: diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/asyncWorkflowItemDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/asyncWorkflowItemDecoratorStrategy.ts new file mode 100644 index 000000000..a467502ef --- /dev/null +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/asyncWorkflowItemDecoratorStrategy.ts @@ -0,0 +1,167 @@ +/*- + * #%L + * vrotsc + * %% + * Copyright (C) 2023 - 2024 VMware + * %% + * Build Tools for VMware Aria + * Copyright 2023 VMware, Inc. + * + * This product is licensed to you under the BSD-2 license (the "License"). You may not use this product except in compliance with the BSD-2 License. + * + * This product may include a number of subcomponents with separate copyright notices and license terms. Your use of these subcomponents is subject to the terms and conditions of the subcomponent's license, as noted in the LICENSE file. + * #L% + */ +import { Decorator, MethodDeclaration, SourceFile } from "typescript"; +import { StringBuilderClass } from "../../../../../utilities/stringBuilder"; +import { WorkflowItemDescriptor, WorkflowItemType } from "../../../../decorators"; +import { getDecoratorProps } from "../../../helpers/node"; +import { findTargetItem } from "../helpers/findTargetItem"; +import CanvasItemDecoratorStrategy from "./canvasItemDecoratorStrategy"; +import { InputOutputBindings, buildItemParameterBindings } from "./helpers/presentation"; +import { AsyncWorkflowItemSourceFilePrinter, SourceFilePrinter } from "./helpers/sourceFile"; + +/** + * + * Responsible for printing out the workflow item: + * @example + * ```xml + + + + + + + + + + + + + + * ``` + */ +export default class AsyncWorkflowItemDecoratorStrategy implements CanvasItemDecoratorStrategy { + constructor(private readonly sourceFilePrinter: SourceFilePrinter = new AsyncWorkflowItemSourceFilePrinter()) { } + + /** + * @returns The type of canvas item + */ + getCanvasType(): string { + return "task"; + } + + /** + * @returns The type of decorator + */ + getDecoratorType(): WorkflowItemType { + return WorkflowItemType.AsyncWorkflow; + } + + /** + * Registers the item arguments + * + * - `target` is the name of the item to call after the item is executed + * - `exception` is the exception to throw if the item fails + * - `linkedItem` is the id of the workflow to schedule + * + * @param itemInfo The item to register + * @param decoratorNode The decorator node + * @returns void + * @throws Error if an unsupported attribute is found + */ + registerItemArguments(itemInfo: WorkflowItemDescriptor, decoratorNode: Decorator): void { + getDecoratorProps(decoratorNode).forEach((propTuple) => { + const [propName, propValue] = propTuple; + switch (propName) { + case "target": + itemInfo.target = propValue; + break; + + case "linkedItem": + itemInfo.canvasItemPolymorphicBag.linkedItem = propValue; + break; + + default: + throw new Error(`Item attribute '${propName}' is not supported for ${this.getDecoratorType()} item`); + } + }); + } + + /** + * There is no need to print the source file for the workflow item + */ + printSourceFile(methodNode: MethodDeclaration, sourceFile: SourceFile, itemInfo: WorkflowItemDescriptor): string { + return this.sourceFilePrinter.printSourceFile(methodNode, sourceFile, itemInfo); + } + + /** + * Prints out the item + * + * - `out-name` is the target canvas item to be called after the item is executed + * - `launched-workflow-id` - the id of the workflow that will be launched asynchronously + * + * @param itemInfo The item to print + * @param pos The position of the item in the workflow + * + * @returns The string representation of the item + */ + printItem(itemInfo: WorkflowItemDescriptor, pos: number): string { + const stringBuilder = new StringBuilderClass("", ""); + + this.validateNeededParameters(itemInfo); + + const targetItem = findTargetItem(itemInfo.target, pos, itemInfo); + if (targetItem === null) { + throw new Error(`Unable to find target item for ${this.getDecoratorType()} item`); + } + + stringBuilder.append(`").appendLine(); + + stringBuilder.indent(); + stringBuilder.append(``).appendLine(); + + stringBuilder.append(``).appendLine(); + stringBuilder.appendContent(buildItemParameterBindings(itemInfo, InputOutputBindings.IN_BINDINGS)); + stringBuilder.appendContent(buildItemParameterBindings(itemInfo, InputOutputBindings.OUT_BINDINGS)); + stringBuilder.append(``).appendLine(); + stringBuilder.unindent(); + stringBuilder.append(``).appendLine(); + + return stringBuilder.toString(); + } + + /** + * Validates that the item has all the required parameters + * + * Outputs: + * - {WorkflowToken} wfToken (optional) but if present, it should be the only output + * + * @param itemInfo The item to validate + * @throws Error if the item is missing required parameters + * @returns void + */ + private validateNeededParameters(itemInfo: WorkflowItemDescriptor): void { + const outputs = itemInfo.output; + + if (outputs.length && outputs.length !== 1 && !outputs.includes("wfToken")) { + throw new Error(`Decorator ${this.getDecoratorType()} has an invalid output: ${outputs}, expected: wfToken`); + } + } +} + From b3e7a71b5b53b6f56408d79cbfc9fd8fe65cd049 Mon Sep 17 00:00:00 2001 From: Stefan Genov Date: Tue, 23 Jul 2024 16:34:20 +0300 Subject: [PATCH 31/67] test: Added unit tests for the async workflow item Signed-off-by: Stefan Genov --- .../cases/canvas-items/async-workflow.wf.ts | 49 +++++++++++++++++++ .../Async Workflow Test.element_info.xml | 9 ++++ .../VMware/PSCoE/Async Workflow Test.xml | 13 +++++ 3 files changed, 71 insertions(+) create mode 100644 typescript/vrotsc/e2e/cases/canvas-items/async-workflow.wf.ts create mode 100644 typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Async Workflow Test.element_info.xml create mode 100644 typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Async Workflow Test.xml diff --git a/typescript/vrotsc/e2e/cases/canvas-items/async-workflow.wf.ts b/typescript/vrotsc/e2e/cases/canvas-items/async-workflow.wf.ts new file mode 100644 index 000000000..cd092e8ab --- /dev/null +++ b/typescript/vrotsc/e2e/cases/canvas-items/async-workflow.wf.ts @@ -0,0 +1,49 @@ +import { Workflow, Out, In, Item, RootItem, AsyncWorkflowItem } from "vrotsc-annotations"; + +@Workflow({ + name: "Async Workflow Test", + path: "VMware/PSCoE", + description: "Calling another workflow asynchronously and binding values correctly", + attributes: { + waitingTimer: { + type: "Date" + }, + counter: { + type: "number" + }, + first: { + type: "number" + }, + second: { + type: "number" + }, + wfToken: { + type: "WorkflowToken" + } + } +}) +export class HandleNetworkConfigurationBackup { + @AsyncWorkflowItem({ + target: "printAsync", + linkedItem: "9e4503db-cbaa-435a-9fad-144409c08df0" + }) + public asyncCall(@In first: number, @In second: number, @Out wfToken: WorkflowToken) { } + + @Item({ target: "callAsyncWf" }) + public prepareItems(@In @Out first: number, @In @Out second: number) { + first = 1; + second = 2; + } + + @Item({ target: "end" }) + public printAsync(@In wfToken: WorkflowToken) { + System.log(`Workflow token: ${wfToken.id} and state: ${wfToken.state}`); + System.log("Workflow finished"); + } + + @Item({ target: "prepareItems", exception: "" }) + @RootItem() + public start() { + System.log("Starting workflow"); + } +} diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Async Workflow Test.element_info.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Async Workflow Test.element_info.xml new file mode 100644 index 000000000..71723fe5c --- /dev/null +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Async Workflow Test.element_info.xml @@ -0,0 +1,9 @@ + + + +Generated by vrotsc +VMware.PSCoE +Async Workflow Test +Workflow +4b483071-6bbc-34e5-a554-f0476933f6ed + diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Async Workflow Test.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Async Workflow Test.xml new file mode 100644 index 000000000..3a0fb67fa --- /dev/null +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Async Workflow Test.xml @@ -0,0 +1,13 @@ + \ No newline at end of file From 5e9ec414b41c2806216ab4bb696e117efff0a094 Mon Sep 17 00:00:00 2001 From: Stefan Genov Date: Tue, 23 Jul 2024 16:45:28 +0300 Subject: [PATCH 32/67] docs: Added docs for the AsyncWorkflowItem Signed-off-by: Stefan Genov --- .../typescript/Components/Workflows.md | 41 +++++++++- docs/versions/latest/Release.md | 75 +++++++++++++++++++ 2 files changed, 115 insertions(+), 1 deletion(-) diff --git a/docs/versions/latest/Components/Archetypes/typescript/Components/Workflows.md b/docs/versions/latest/Components/Archetypes/typescript/Components/Workflows.md index 60f8587dc..b11ed21ca 100644 --- a/docs/versions/latest/Components/Archetypes/typescript/Components/Workflows.md +++ b/docs/versions/latest/Components/Archetypes/typescript/Components/Workflows.md @@ -164,6 +164,27 @@ Special output is needed for the ScheduledWorkflowItem. This is a meta decorator. Add this to whichever function you want to be the entry point of the workflow. + +#### `@AsyncWorkflowItem` + +##### Supported Parameters + +- `@AsyncWorkflowItem({target: "", linkedItem: "" })` + - `target` - The name of the next in line item. + - `linkedItem` - The ID of the workflow to call + + +##### Outputs + +Special output is needed for the AsyncWorkflowItem. + +- `wfToken` - {WorkflowToken} is required. The name **must** be `wfToken`. If this is missing an error is thrown. We don't check if the type is `WorkflowToken` but Aria Orchestrator will complain. + +##### Inputs + +No special inputs are needed for the AsyncWorkflowItem. + + ### Example Workflow ```ts @@ -208,6 +229,9 @@ import { errorMessage: { type: "string", }, + wfToken: { + type: "WorkflowToken" + } }, }) export class HandleNetworkConfigurationBackup { @@ -248,11 +272,26 @@ export class HandleNetworkConfigurationBackup { public scheduleOtherWf(@In first: number, @In second: number, @In workflowScheduleDate: Date, @Out scheduledTask: Task) { } - @Item({ target: "end" }) + @Item({ target: "asyncCall" }) public printScheduledDetails(@In scheduledTask: Task) { System.log(`Scheduled task: ${scheduledTask.id}, [${scheduledTask.state}]`); } + + @AsyncWorkflowItem({ + target: "printAsync", + linkedItem: "9e4503db-cbaa-435a-9fad-144409c08df0" + }) + public asyncCall(@In first: number, @In second: number, @Out wfToken: WorkflowToken) { + } + + @Item({ target: "end" }) + public printAsync(@In wfToken: WorkflowToken) { + System.log(`Workflow token: ${wfToken.id} and state: ${wfToken.state}`); + System.log("Workflow finished"); + } + + @Item({ target: "decisionElement", exception: "" }) public execute(@Out @In waitingTimer: Date, @Out @In counter: number): void { if (!counter) { diff --git a/docs/versions/latest/Release.md b/docs/versions/latest/Release.md index 40a0c2409..72c51f893 100644 --- a/docs/versions/latest/Release.md +++ b/docs/versions/latest/Release.md @@ -140,6 +140,81 @@ export class WorkflowEnd { } ``` +### *New `AsyncWorkflowItem` decorator for Workflows* + +The decorator is used to specify a canvas item that calls an asynchronous workflow. + +- `@AsyncWorkflowItem({target: "", linkedItem: "" })` + - `target` - The name of the next in line item. + - `linkedItem` - The ID of the workflow to call + +In order to bind inputs and outputs, you do it with the `@In` and `@Out` decorators. This is the same way we do it for other items. + +#### Outputs + +Special output is needed for the AsyncWorkflowItem. + +- `wfToken` - {WorkflowToken} is required. The name **must** be `wfToken`. If this is missing an error is thrown. We don't check if the type is `WorkflowToken` but Aria Orchestrator will complain. + +#### Inputs + +No special inputs are needed for the AsyncWorkflowItem. + + +#### Example + +```typescript +import { Workflow, Out, In, Item, RootItem, AsyncWorkflowItem } from "vrotsc-annotations"; + +@Workflow({ + name: "Async Workflow Test", + path: "VMware/PSCoE", + description: "Calling another workflow asynchronously and binding values correctly", + attributes: { + waitingTimer: { + type: "Date" + }, + counter: { + type: "number" + }, + first: { + type: "number" + }, + second: { + type: "number" + }, + wfToken: { + type: "WorkflowToken" + } + } +}) +export class HandleNetworkConfigurationBackup { + @AsyncWorkflowItem({ + target: "printAsync", + linkedItem: "9e4503db-cbaa-435a-9fad-144409c08df0" + }) + public asyncCall(@In first: number, @In second: number, @Out wfToken: WorkflowToken) { } + + @Item({ target: "callAsyncWf" }) + public prepareItems(@In @Out first: number, @In @Out second: number) { + first = 1; + second = 2; + } + + @Item({ target: "end" }) + public printAsync(@In wfToken: WorkflowToken) { + System.log(`Workflow token: ${wfToken.id} and state: ${wfToken.state}`); + System.log("Workflow finished"); + } + + @Item({ target: "prepareItems", exception: "" }) + @RootItem() + public start() { + System.log("Starting workflow"); + } +} +``` + ### *New `ScheduledWorkflowItem` decorator for Workflows* The new decorator gives you the ability to specify a canvas item that schedules a Workflow. From 821f80db3bdb2dfdb0bc449a83f27db0634e39be Mon Sep 17 00:00:00 2001 From: Stefan Genov Date: Wed, 24 Jul 2024 08:23:21 +0300 Subject: [PATCH 33/67] fix: Add check if decorator props are 0 length even tho .forEach does this natively Signed-off-by: Stefan Genov --- .../decorators/asyncWorkflowItemDecoratorStrategy.ts | 6 +++++- .../workflow/decorators/decisionItemDecoratorStrategy.ts | 6 +++++- .../decorators/defaultErrorHandlerDecoratorStrategy.ts | 8 ++++---- .../workflow/decorators/endItemDecoratorStrategy.ts | 8 ++++---- .../workflow/decorators/itemDecoratorStrategy.ts | 6 +++++- .../decorators/scheduledWorkflowItemDecoratorStrategy.ts | 6 +++++- .../decorators/waitingTimerItemDecoratorStrategy.ts | 6 +++++- .../workflow/decorators/workflowItemDecoratorStrategy.ts | 6 +++++- 8 files changed, 38 insertions(+), 14 deletions(-) diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/asyncWorkflowItemDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/asyncWorkflowItemDecoratorStrategy.ts index a467502ef..d99cd1035 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/asyncWorkflowItemDecoratorStrategy.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/asyncWorkflowItemDecoratorStrategy.ts @@ -81,7 +81,11 @@ export default class AsyncWorkflowItemDecoratorStrategy implements CanvasItemDec * @throws Error if an unsupported attribute is found */ registerItemArguments(itemInfo: WorkflowItemDescriptor, decoratorNode: Decorator): void { - getDecoratorProps(decoratorNode).forEach((propTuple) => { + const decoratorProperties = getDecoratorProps(decoratorNode); + if (!decoratorProperties?.length) { + return; + } + decoratorProperties.forEach((propTuple) => { const [propName, propValue] = propTuple; switch (propName) { case "target": diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/decisionItemDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/decisionItemDecoratorStrategy.ts index 2dd3a5e51..8ae654ae4 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/decisionItemDecoratorStrategy.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/decisionItemDecoratorStrategy.ts @@ -48,7 +48,11 @@ export default class DecisionItemDecoratorStrategy implements CanvasItemDecorato } registerItemArguments(itemInfo: WorkflowItemDescriptor, decoratorNode: Decorator): void { - getDecoratorProps(decoratorNode).forEach((propTuple) => { + const decoratorProperties = getDecoratorProps(decoratorNode); + if (!decoratorProperties?.length) { + return; + } + decoratorProperties.forEach((propTuple) => { const [propName, propValue] = propTuple; switch (propName) { case "target": { diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/defaultErrorHandlerDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/defaultErrorHandlerDecoratorStrategy.ts index 215762bd2..d0e94039f 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/defaultErrorHandlerDecoratorStrategy.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/defaultErrorHandlerDecoratorStrategy.ts @@ -41,7 +41,7 @@ export default class DefaultErrorHandlerDecoratorStrategy implements CanvasItemD /** * Return XML tag for the error handler workflow item. - * + * * @returns XML tag name. */ public getCanvasType(): string { @@ -50,7 +50,7 @@ export default class DefaultErrorHandlerDecoratorStrategy implements CanvasItemD /** * Return the workflow item type supported by this decorator. - * + * * @returns type of the workflow element. */ public getDecoratorType(): WorkflowItemType { @@ -59,12 +59,12 @@ export default class DefaultErrorHandlerDecoratorStrategy implements CanvasItemD /** * Register the canvas item arguments. For the default error handler only "target" and "exception" are supported. - * + * * @param itemInfo item info for that properties should be fetched. * @param decoratorNode decorator node handle. */ public registerItemArguments(itemInfo: WorkflowItemDescriptor, decoratorNode: Decorator): void { - const decoratorProperties: [string, any][] = getDecoratorProps(decoratorNode); + const decoratorProperties = getDecoratorProps(decoratorNode); if (!decoratorProperties?.length) { return; } diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/endItemDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/endItemDecoratorStrategy.ts index f01124c63..ffe1b582f 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/endItemDecoratorStrategy.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/endItemDecoratorStrategy.ts @@ -41,7 +41,7 @@ const offSet = 20; export default class EndItemDecoratorStrategy implements CanvasItemDecoratorStrategy { /** * Return XML tag for the end workflow item. - * + * * @returns XML tag name. */ getCanvasType(): string { @@ -50,7 +50,7 @@ export default class EndItemDecoratorStrategy implements CanvasItemDecoratorStra /** * Return the workflow item type supported by this decorator. - * + * * @returns type of the workflow element. */ getDecoratorType(): WorkflowItemType { @@ -59,12 +59,12 @@ export default class EndItemDecoratorStrategy implements CanvasItemDecoratorStra /** * Register the canvas item arguments. For the default error handler only "endMode" and "exception" are supported. - * + * * @param itemInfo item info for that properties should be fetched. * @param decoratorNode decorator node handle. */ registerItemArguments(itemInfo: WorkflowItemDescriptor, decoratorNode: Decorator): void { - const decoratorProperties: [string, any][] = getDecoratorProps(decoratorNode); + const decoratorProperties = getDecoratorProps(decoratorNode); if (!decoratorProperties?.length) { return; } diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/itemDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/itemDecoratorStrategy.ts index 74794a5f0..99b90e268 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/itemDecoratorStrategy.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/itemDecoratorStrategy.ts @@ -33,7 +33,11 @@ export default class ItemDecoratorStrategy implements CanvasItemDecoratorStrateg } registerItemArguments(itemInfo: WorkflowItemDescriptor, decoratorNode: Decorator): void { - getDecoratorProps(decoratorNode).forEach((propTuple) => { + const decoratorProperties = getDecoratorProps(decoratorNode); + if (!decoratorProperties?.length) { + return; + } + decoratorProperties.forEach((propTuple) => { const [propName, propValue] = propTuple; switch (propName) { case "target": diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/scheduledWorkflowItemDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/scheduledWorkflowItemDecoratorStrategy.ts index 4afe08bf7..a9f5affcd 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/scheduledWorkflowItemDecoratorStrategy.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/scheduledWorkflowItemDecoratorStrategy.ts @@ -82,7 +82,11 @@ export default class ScheduledWorkflowItemDecoratorStrategy implements CanvasIte * @throws Error if an unsupported attribute is found */ registerItemArguments(itemInfo: WorkflowItemDescriptor, decoratorNode: Decorator): void { - getDecoratorProps(decoratorNode).forEach((propTuple) => { + const decoratorProperties = getDecoratorProps(decoratorNode); + if (!decoratorProperties?.length) { + return; + } + decoratorProperties.forEach((propTuple) => { const [propName, propValue] = propTuple; switch (propName) { case "target": diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/waitingTimerItemDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/waitingTimerItemDecoratorStrategy.ts index b9d75c5c5..d063f36ad 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/waitingTimerItemDecoratorStrategy.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/waitingTimerItemDecoratorStrategy.ts @@ -46,7 +46,11 @@ export default class WaitingTimerItemDecoratorStrategy implements CanvasItemDeco } registerItemArguments(itemInfo: WorkflowItemDescriptor, decoratorNode: Decorator): void { - getDecoratorProps(decoratorNode).forEach((propTuple) => { + const decoratorProperties = getDecoratorProps(decoratorNode); + if (!decoratorProperties?.length) { + return; + } + decoratorProperties.forEach((propTuple) => { const [propName, propValue] = propTuple; switch (propName) { case "target": diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/workflowItemDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/workflowItemDecoratorStrategy.ts index f0ec1db81..1060f479b 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/workflowItemDecoratorStrategy.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/workflowItemDecoratorStrategy.ts @@ -50,7 +50,11 @@ export default class WorkflowItemDecoratorStrategy implements CanvasItemDecorato } registerItemArguments(itemInfo: WorkflowItemDescriptor, decoratorNode: Decorator): void { - getDecoratorProps(decoratorNode).forEach((propTuple) => { + const decoratorProperties = getDecoratorProps(decoratorNode); + if (!decoratorProperties?.length) { + return; + } + decoratorProperties.forEach((propTuple) => { const [propName, propValue] = propTuple; switch (propName) { case "target": From bb20091aec4f817748c311ee74aba16490dcbcc5 Mon Sep 17 00:00:00 2001 From: Alexander Kantchev Date: Wed, 24 Jul 2024 11:24:02 +0300 Subject: [PATCH 34/67] [Task 353] fix: Updated map size to be updated correctly when set in a map object, code optimization. Signed-off-by: Alexander Kantchev --- packages/ecmascript/src/Map.ts | 31 ++++++++++++++----------------- packages/ecmascript/src/Set.ts | 22 +++++++++++----------- 2 files changed, 25 insertions(+), 28 deletions(-) diff --git a/packages/ecmascript/src/Map.ts b/packages/ecmascript/src/Map.ts index e0a0b06e1..851fd5dc7 100644 --- a/packages/ecmascript/src/Map.ts +++ b/packages/ecmascript/src/Map.ts @@ -14,7 +14,7 @@ */ export default class Map { - private size = 0; + private size: number = 0; private items: { [name: string]: any } = {}; constructor(values?: ReadonlyArray<[K, V]> | null) { @@ -26,7 +26,7 @@ export default class Map { } } - entries(): [any, any][] { + public entries(): [any, any][] { let entries = []; for (let key in this.items) { @@ -36,7 +36,7 @@ export default class Map { return entries; } - keys(): any[] { + public keys(): any[] { let keys = []; for (let key in this.items) { @@ -46,7 +46,7 @@ export default class Map { return keys; } - values(): any[] { + public values(): any[] { let values = []; for (let key in this.items) { @@ -56,26 +56,23 @@ export default class Map { return values; } - has(key): boolean { + public has(key: any): boolean { return this.items.hasOwnProperty(key); } - get(key): any { + public get(key: any): any { return this.items[key]; } - set(key, value): any { - let exist = this.items.hasOwnProperty(key); - if (exist) { - this.size++; - } - + public set(key: any, value: any): any { this.items[key] = value; + this.size++; + return this; } - delete(key): boolean { - let exist = this.items.hasOwnProperty(key); + public delete(key: any): boolean { + let exist = this.has(key); if (exist) { this.size--; delete this.items[key]; @@ -84,14 +81,14 @@ export default class Map { return exist; } - clear(): void { + public clear(): void { this.size = 0; this.items = {}; } - forEach(callbackfn: (value, key, map: Map) => void): void { + public forEach(callbackFunction: (value: any, key: any, map: Map) => void): void { for (let key in this.items) { - callbackfn(this.items[key], key, this); + callbackFunction(this.items[key], key, this); } } } diff --git a/packages/ecmascript/src/Set.ts b/packages/ecmascript/src/Set.ts index 285fbfdff..230519aed 100644 --- a/packages/ecmascript/src/Set.ts +++ b/packages/ecmascript/src/Set.ts @@ -13,7 +13,7 @@ * #L% */ export default class Set { - private size = 0; + private size: number = 0; private items: { [name: string]: boolean } = {}; constructor(values?: ReadonlyArray | null) { @@ -25,7 +25,7 @@ export default class Set { } } - entries(): [any, any][] { + public entries(): [any, any][] { let entries = []; for (let value in this.items) { @@ -35,11 +35,11 @@ export default class Set { return entries; } - keys(): any[] { + public keys(): any[] { return this.values(); } - values(): any[] { + public values(): any[] { let values = []; for (let value in this.items) { @@ -49,17 +49,17 @@ export default class Set { return values; } - has(value): boolean { + public has(value: any): boolean { return this.items.hasOwnProperty(value); } - add(value): any { + public add(value: any): any { this.items[value] = true; return this; } - delete(value: any): boolean { - let exist = this.items.hasOwnProperty(value); + public delete(value: any): boolean { + let exist = this.has(value); if (exist) { this.size--; delete this.items[value]; @@ -68,14 +68,14 @@ export default class Set { return exist; } - clear(): void { + public clear(): void { this.size = 0; this.items = {}; } - forEach(callbackfn: (value, value2, set: Set) => void): void { + public forEach(callbackFunction: (value: any, value2: any, set: Set) => void): void { for (let value in this.items) { - callbackfn(value, value, this); + callbackFunction(value, value, this); } } } From aa96ad6e846d34079fcfe69406a95e76b85cd705 Mon Sep 17 00:00:00 2001 From: Alexander Kantchev Date: Wed, 24 Jul 2024 15:26:27 +0300 Subject: [PATCH 35/67] [Task 353] code: Added incrementing of size for existing keys in the Map, added incrementing of size in the Set.add() method. Signed-off-by: Alexander Kantchev --- packages/ecmascript/src/Map.ts | 6 ++++++ packages/ecmascript/src/Set.ts | 2 ++ 2 files changed, 8 insertions(+) diff --git a/packages/ecmascript/src/Map.ts b/packages/ecmascript/src/Map.ts index 851fd5dc7..1733821d7 100644 --- a/packages/ecmascript/src/Map.ts +++ b/packages/ecmascript/src/Map.ts @@ -65,6 +65,12 @@ export default class Map { } public set(key: any, value: any): any { + let exist = this.has(key); + if (exist) { + this.items[key] = value; + this.size++; + return this; + } this.items[key] = value; this.size++; diff --git a/packages/ecmascript/src/Set.ts b/packages/ecmascript/src/Set.ts index 230519aed..3a9ec043e 100644 --- a/packages/ecmascript/src/Set.ts +++ b/packages/ecmascript/src/Set.ts @@ -55,6 +55,8 @@ export default class Set { public add(value: any): any { this.items[value] = true; + this.size++; + return this; } From f392f26421de3066209ead17b746422a4e12424b Mon Sep 17 00:00:00 2001 From: Stefan Genov Date: Wed, 24 Jul 2024 17:56:07 +0300 Subject: [PATCH 36/67] feat: Add new Action item decorator strategy Signed-off-by: Stefan Genov --- typescript/vrotsc/src/compiler/decorators.ts | 7 + .../fileTransformers/workflow/decorators.ts | 3 + .../decorators/actionItemDecoratorStrategy.ts | 148 ++++++++++++++++++ .../workflow/decorators/helpers/sourceFile.ts | 42 +++++ vro-types/vrotsc-annotations/index.d.ts | 20 +++ 5 files changed, 220 insertions(+) create mode 100644 typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/actionItemDecoratorStrategy.ts diff --git a/typescript/vrotsc/src/compiler/decorators.ts b/typescript/vrotsc/src/compiler/decorators.ts index 0f25f8592..d72244665 100644 --- a/typescript/vrotsc/src/compiler/decorators.ts +++ b/typescript/vrotsc/src/compiler/decorators.ts @@ -121,6 +121,13 @@ export enum WorkflowItemType { */ WaitingTimer = "WaitingTimerItem", + /** + * This item type represents an action item. + * + * It can target a specific item and accepts input and output bindings + */ + Action = "ActionItem", + /** * This item type represents a workflow item * diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators.ts index 036f0b31f..261cfe081 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators.ts @@ -27,6 +27,7 @@ import WaitingTimerItemDecoratorStrategy from "./decorators/waitingTimerItemDeco import WorkflowItemDecoratorStrategy from "./decorators/workflowItemDecoratorStrategy"; import ScheduledWorkflowItemDecoratorStrategy from "./decorators/scheduledWorkflowItemDecoratorStrategy"; import AsyncWorkflowItemDecoratorStrategy from "./decorators/asyncWorkflowItemDecoratorStrategy"; +import ActionItemDecoratorStrategy from "./decorators/actionItemDecoratorStrategy"; /** * Fetches details from the decorators for the methods and adds the information to the Descriptors @@ -88,6 +89,8 @@ function getItemStrategy(decoratorNode: ts.Decorator): CanvasItemDecoratorStrate return new WorkflowItemDecoratorStrategy(); case WorkflowItemType.RootItem: return new RootItemDecoratorStrategy(); + case WorkflowItemType.Action: + return new ActionItemDecoratorStrategy(); case WorkflowItemType.ScheduledWorkflow: return new ScheduledWorkflowItemDecoratorStrategy(); case WorkflowItemType.AsyncWorkflow: diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/actionItemDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/actionItemDecoratorStrategy.ts new file mode 100644 index 000000000..58cfa2b10 --- /dev/null +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/actionItemDecoratorStrategy.ts @@ -0,0 +1,148 @@ +/*- + * #%L + * vrotsc + * %% + * Copyright (C) 2023 - 2024 VMware + * %% + * Build Tools for VMware Aria + * Copyright 2023 VMware, Inc. + * + * This product is licensed to you under the BSD-2 license (the "License"). You may not use this product except in compliance with the BSD-2 License. + * + * This product may include a number of subcomponents with separate copyright notices and license terms. Your use of these subcomponents is subject to the terms and conditions of the subcomponent's license, as noted in the LICENSE file. + * #L% + */ +import { Decorator, MethodDeclaration, SourceFile } from "typescript"; +import { StringBuilderClass } from "../../../../../utilities/stringBuilder"; +import { WorkflowItemDescriptor, WorkflowItemType } from "../../../../decorators"; +import { getDecoratorProps } from "../../../helpers/node"; +import { findTargetItem } from "../helpers/findTargetItem"; +import CanvasItemDecoratorStrategy from "./canvasItemDecoratorStrategy"; +import { InputOutputBindings, buildItemParameterBindings } from "./helpers/presentation"; +import { ActionItemSourceFilePrinter, SourceFilePrinter } from "./helpers/sourceFile"; + +/** + * + * Responsible for printing out the workflow item: + * @example + * ```xml + + + + + + + + + + + + + + * ``` + */ +export default class ActionItemDecoratorStrategy implements CanvasItemDecoratorStrategy { + constructor(private readonly sourceFilePrinter: SourceFilePrinter = new ActionItemSourceFilePrinter()) { } + + getCanvasType(): string { + return "task"; + } + + getDecoratorType(): WorkflowItemType { + return WorkflowItemType.Action; + } + + registerItemArguments(itemInfo: WorkflowItemDescriptor, decoratorNode: Decorator): void { + const decoratorProperties = getDecoratorProps(decoratorNode); + if (!decoratorProperties?.length) { + return; + } + decoratorProperties.forEach((propTuple) => { + const [propName, propValue] = propTuple; + switch (propName) { + case "target": + itemInfo.target = propValue; + break; + + case "exception": + itemInfo.canvasItemPolymorphicBag.exception = propValue; + break; + + case "scriptModule": + itemInfo.canvasItemPolymorphicBag.scriptModule = propValue; + break; + + default: + throw new Error(`Item attribute '${propName}' is not supported for ${this.getDecoratorType()} item`); + } + }); + } + + /** + * There is no need to print the source file for the workflow item + */ + printSourceFile(methodNode: MethodDeclaration, sourceFile: SourceFile, itemInfo: WorkflowItemDescriptor): string { + return this.sourceFilePrinter.printSourceFile(methodNode, sourceFile, itemInfo); + } + + /** + * Prints out the item + * + * - `out-name` is the target canvas item to be called after the item is executed + * - `script-module` is the script module to be called + * + * @param itemInfo The item to print + * @param pos The position of the item in the workflow + * + * @returns The string representation of the item + */ + printItem(itemInfo: WorkflowItemDescriptor, pos: number): string { + const stringBuilder = new StringBuilderClass("", ""); + + this.validateNeededParameters(itemInfo); + + const targetItem = findTargetItem(itemInfo.target, pos, itemInfo); + if (targetItem === null) { + throw new Error(`Unable to find target item for ${this.getDecoratorType()} item`); + } + + stringBuilder.append(`").appendLine(); + stringBuilder.indent(); + stringBuilder.append(``).appendLine(); + + stringBuilder.append(``).appendLine(); + stringBuilder.appendContent(buildItemParameterBindings(itemInfo, InputOutputBindings.IN_BINDINGS)); + stringBuilder.appendContent(buildItemParameterBindings(itemInfo, InputOutputBindings.OUT_BINDINGS)); + stringBuilder.append(``).appendLine(); + stringBuilder.unindent(); + stringBuilder.append(``).appendLine(); + + return stringBuilder.toString(); + } + + /** + * Validates that the item has all the required parameters + * + * Outputs: + * There must be exactly one output + * + * @param itemInfo The item to validate + * @throws Error if the item is missing required parameters + * @returns void + */ + private validateNeededParameters(itemInfo: WorkflowItemDescriptor): void { + const outputs = itemInfo.output; + + if (outputs.length && outputs.length !== 1) { + throw new Error(`Decorator ${this.getDecoratorType()} needs exactly one output, but actually: ${outputs.length}`); + } + } +} diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/helpers/sourceFile.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/helpers/sourceFile.ts index 6c2b274d7..d3a7bf06f 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/helpers/sourceFile.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/helpers/sourceFile.ts @@ -312,3 +312,45 @@ export class AsyncWorkflowItemSourceFilePrinter implements SourceFilePrinter { } } +/** + * This is used to print the source file for an action item. + * + * @Example of what is printed: + * ```js + actionResult = System.getModule("com.vmware.stef").PrintStef(a,b); + * ``` + */ +export class ActionItemSourceFilePrinter implements SourceFilePrinter { + printSourceFile(methodNode: MethodDeclaration, sourceFile: SourceFile, itemInfo: WorkflowItemDescriptor): string { + return printSourceFile( + factory.updateSourceFile( + sourceFile, + [ + ...sourceFile.statements.filter(n => n.kind !== SyntaxKind.ClassDeclaration), + ...createWorkflowItemPrologueStatements(methodNode), + // `actionResult = System.getModule("com.vmware.stef").PrintStef(a,b);` + factory.createExpressionStatement( + factory.createAssignment( + factory.createIdentifier(itemInfo.output[0]), + factory.createCallExpression( + factory.createPropertyAccessExpression( + factory.createCallExpression( + factory.createPropertyAccessExpression( + factory.createIdentifier("System"), + factory.createIdentifier("getModule") + ), + undefined, + [factory.createStringLiteral(itemInfo.canvasItemPolymorphicBag.scriptModule.split("/")[0])] + ), + factory.createIdentifier(itemInfo.canvasItemPolymorphicBag.scriptModule.split("/")[1]) + ), + undefined, + itemInfo.input.map((input) => factory.createIdentifier(input)) + ) + ) + ) + ] + ) + ); + } +} diff --git a/vro-types/vrotsc-annotations/index.d.ts b/vro-types/vrotsc-annotations/index.d.ts index dc7f3a68f..b7a4d6811 100644 --- a/vro-types/vrotsc-annotations/index.d.ts +++ b/vro-types/vrotsc-annotations/index.d.ts @@ -321,6 +321,26 @@ interface VroAsyncWorkflowItemMethodDecorator { (target: Object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor): void; } +// ---------------------------------------------- Action Canvas Item ------------------------------------------------ + +export declare const ActionItem: VroActionItemDecorator; + +interface VroActionItemDecorator { + (obj?: VroActionItemConfiguration): VroActionItemMethodDecorator; + new(obj?: VroActionItemConfiguration): VroActionItemConfiguration; +} + +interface VroActionItemConfiguration { + target?: string; + scriptModule: string; +} + +interface VroActionItemMethodDecorator { + >(type: T): T; + (target: Object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor): void; +} + + //--------------------------------------------- POLYGLOT ------------------------------------------------------------------------------- export declare const Polyglot: VroPolyglotDecorator; From bfb167faa861016987fb039c519eaadce0b92efd Mon Sep 17 00:00:00 2001 From: Stefan Genov Date: Thu, 25 Jul 2024 09:39:56 +0300 Subject: [PATCH 37/67] docs: Added documentation for the action item Signed-off-by: Stefan Genov --- .../typescript/Components/Workflows.md | 32 +++++++++++- docs/versions/latest/Release.md | 50 +++++++++++++++++++ 2 files changed, 80 insertions(+), 2 deletions(-) diff --git a/docs/versions/latest/Components/Archetypes/typescript/Components/Workflows.md b/docs/versions/latest/Components/Archetypes/typescript/Components/Workflows.md index b11ed21ca..e79812e2e 100644 --- a/docs/versions/latest/Components/Archetypes/typescript/Components/Workflows.md +++ b/docs/versions/latest/Components/Archetypes/typescript/Components/Workflows.md @@ -184,6 +184,20 @@ Special output is needed for the AsyncWorkflowItem. No special inputs are needed for the AsyncWorkflowItem. +#### `@ActionItem` + +##### Supported Parameters + +- `@ActionItem({target: "", scriptModule: "" })` + - `target` - The name of the next in line item. Same as `@Item`. + - `scriptModule` - The path of the action you want to call and the action name, separated by `/`. Example: `com.vmware.pscoe.library.general/echo`. + +In order to bind inputs and outputs, you do it with the `@In` and `@Out` decorators. This is the same way we do it for other items. + +##### Outputs + +There is a requirement to have only one output, and it will be of type `ActionResult`. + ### Example Workflow @@ -231,6 +245,9 @@ import { }, wfToken: { type: "WorkflowToken" + }, + actionResult: { + type: "ActionResult" } }, }) @@ -285,10 +302,21 @@ export class HandleNetworkConfigurationBackup { public asyncCall(@In first: number, @In second: number, @Out wfToken: WorkflowToken) { } - @Item({ target: "end" }) + @Item({ target: "printActionResult" }) public printAsync(@In wfToken: WorkflowToken) { System.log(`Workflow token: ${wfToken.id} and state: ${wfToken.state}`); - System.log("Workflow finished"); + } + + @ActionItem({ + target: "printActionResult", + scriptModule: "com.vmware.pscoe.onboarding.sgenov.actions/test" + }) + public callTestAction(@In first: number, @In second: number, @Out actionResult: ActionResult) { + } + + @Item({ target: "end" }) + public printActionResult(@In actionResult: ActionResult) { + System.log(`Action result: ${actionResult.getResult()}`); } diff --git a/docs/versions/latest/Release.md b/docs/versions/latest/Release.md index 72c51f893..818b7e9b3 100644 --- a/docs/versions/latest/Release.md +++ b/docs/versions/latest/Release.md @@ -24,6 +24,56 @@ [//]: # (Optional But higlhy recommended Specify *NONE* if missing) [//]: # (#### Relevant Documentation:) +### *New `@ActionItem` decorator for Workflows* + +The new decorator gives you the ability to specify a canvas item that calls an action. + +#### Supported Parameters + +- `target` - The name of the next in line item. Same as `@Item`. +- `scriptModule` - The path of the action you want to call and the action name, separated by `/`. Example: `com.vmware.pscoe.library.general/echo`. + +In order to bind inputs and outputs, you do it with the `@In` and `@Out` decorators. This is the same way we do it for other items. + +#### Outputs + +There is a requirement to have only one output, and it will be of type `ActionResult`. + +#### Example + +```typescript +import { Workflow, Out, In, Item, ActionItem } from "vrotsc-annotations"; + +@Workflow({ + name: "Example", + path: "VMware/PSCoE", + attributes: { + first: { + type: "number" + }, + second: { + type: "number" + }, + actionResult: { + type: "ActionResult" + } + } +}) +export class Example { + @ActionItem({ + target: "printActionResult", + scriptModule: "com.vmware.pscoe.onboarding.sgenov.actions/test" + }) + public callTestAction(@In first: number, @In second: number, @Out actionResult: ActionResult) { + } + + @Item({ target: "end" }) + public printActionResult(@In actionResult: ActionResult) { + System.log(`Action result: ${actionResult.getResult()}`); + } +} +``` + ### *New `DefaultErrorHandler` decorator for Workflows* This decorator is used to specify a default error handler. It can be bound either to a workflow item component or workflow end. From fb389dbc82406831081613b0eccd410baf9773e6 Mon Sep 17 00:00:00 2001 From: Stefan Genov Date: Thu, 25 Jul 2024 10:02:34 +0300 Subject: [PATCH 38/67] test: Add test cases for Action item Signed-off-by: Stefan Genov --- .../e2e/cases/canvas-items/action-edge.wf.ts | 26 ++++++++++++++++ .../e2e/cases/canvas-items/action-happy.wf.ts | 30 +++++++++++++++++++ .../@types/vrotsc-annotations/index.d.ts | 20 +++++++++++++ .../VMware/PSCoE/Action Edge.element_info.xml | 9 ++++++ .../workflows/VMware/PSCoE/Action Edge.xml | 2 ++ .../PSCoE/Action Happy Path.element_info.xml | 9 ++++++ .../VMware/PSCoE/Action Happy Path.xml | 3 ++ 7 files changed, 99 insertions(+) create mode 100644 typescript/vrotsc/e2e/cases/canvas-items/action-edge.wf.ts create mode 100644 typescript/vrotsc/e2e/cases/canvas-items/action-happy.wf.ts create mode 100644 typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Action Edge.element_info.xml create mode 100644 typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Action Edge.xml create mode 100644 typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Action Happy Path.element_info.xml create mode 100644 typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Action Happy Path.xml diff --git a/typescript/vrotsc/e2e/cases/canvas-items/action-edge.wf.ts b/typescript/vrotsc/e2e/cases/canvas-items/action-edge.wf.ts new file mode 100644 index 000000000..9965d450c --- /dev/null +++ b/typescript/vrotsc/e2e/cases/canvas-items/action-edge.wf.ts @@ -0,0 +1,26 @@ +import { Workflow, Out, In, Item, ActionItem } from "vrotsc-annotations"; + +@Workflow({ + name: "Action Edge", + description: "Goes to end by itself", + path: "VMware/PSCoE", + attributes: { + first: { + type: "number" + }, + second: { + type: "number" + }, + actionResult: { + type: "ActionResult" + } + } +}) +export class Example { + @ActionItem({ + target: "printActionResult", + scriptModule: "com.vmware.pscoe.onboarding.sgenov.actions/test" + }) + public callTestAction(@In first: number, @In second: number, @Out actionResult: ActionResult) { + } +} diff --git a/typescript/vrotsc/e2e/cases/canvas-items/action-happy.wf.ts b/typescript/vrotsc/e2e/cases/canvas-items/action-happy.wf.ts new file mode 100644 index 000000000..88d45bf47 --- /dev/null +++ b/typescript/vrotsc/e2e/cases/canvas-items/action-happy.wf.ts @@ -0,0 +1,30 @@ +import { Workflow, Out, In, Item, ActionItem } from "vrotsc-annotations"; + +@Workflow({ + name: "Action Happy Path", + path: "VMware/PSCoE", + attributes: { + first: { + type: "number" + }, + second: { + type: "number" + }, + actionResult: { + type: "ActionResult" + } + } +}) +export class Example { + @ActionItem({ + target: "printActionResult", + scriptModule: "com.vmware.pscoe.onboarding.sgenov.actions/test" + }) + public callTestAction(@In first: number, @In second: number, @Out actionResult: ActionResult) { + } + + @Item({ target: "end" }) + public printActionResult(@In actionResult: ActionResult) { + System.log(`Action result: ${actionResult.getResult()}`); + } +} diff --git a/typescript/vrotsc/e2e/cases/node_modules/@types/vrotsc-annotations/index.d.ts b/typescript/vrotsc/e2e/cases/node_modules/@types/vrotsc-annotations/index.d.ts index dc7f3a68f..b7a4d6811 100644 --- a/typescript/vrotsc/e2e/cases/node_modules/@types/vrotsc-annotations/index.d.ts +++ b/typescript/vrotsc/e2e/cases/node_modules/@types/vrotsc-annotations/index.d.ts @@ -321,6 +321,26 @@ interface VroAsyncWorkflowItemMethodDecorator { (target: Object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor): void; } +// ---------------------------------------------- Action Canvas Item ------------------------------------------------ + +export declare const ActionItem: VroActionItemDecorator; + +interface VroActionItemDecorator { + (obj?: VroActionItemConfiguration): VroActionItemMethodDecorator; + new(obj?: VroActionItemConfiguration): VroActionItemConfiguration; +} + +interface VroActionItemConfiguration { + target?: string; + scriptModule: string; +} + +interface VroActionItemMethodDecorator { + >(type: T): T; + (target: Object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor): void; +} + + //--------------------------------------------- POLYGLOT ------------------------------------------------------------------------------- export declare const Polyglot: VroPolyglotDecorator; diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Action Edge.element_info.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Action Edge.element_info.xml new file mode 100644 index 000000000..028003dfe --- /dev/null +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Action Edge.element_info.xml @@ -0,0 +1,9 @@ + + + +Generated by vrotsc +VMware.PSCoE +Action Edge +Workflow +236a5e1e-30e1-3cf4-ac0b-65e91a1abe7e + diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Action Edge.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Action Edge.xml new file mode 100644 index 000000000..3ea60709e --- /dev/null +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Action Edge.xml @@ -0,0 +1,2 @@ + \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Action Happy Path.element_info.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Action Happy Path.element_info.xml new file mode 100644 index 000000000..45ae1ab58 --- /dev/null +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Action Happy Path.element_info.xml @@ -0,0 +1,9 @@ + + + +Generated by vrotsc +VMware.PSCoE +Action Happy Path +Workflow +9d4c6c70-66a1-3969-9e79-513d73819e55 + diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Action Happy Path.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Action Happy Path.xml new file mode 100644 index 000000000..05c5f257a --- /dev/null +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Action Happy Path.xml @@ -0,0 +1,3 @@ + \ No newline at end of file From dbff84530f1f6fa62ec3fecedbc674ac6cbfd264 Mon Sep 17 00:00:00 2001 From: Alexander Kantchev Date: Thu, 25 Jul 2024 11:46:48 +0300 Subject: [PATCH 39/67] [Task 353] code: Code optimization. Signed-off-by: Alexander Kantchev --- packages/ecmascript/src/Map.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/ecmascript/src/Map.ts b/packages/ecmascript/src/Map.ts index 1733821d7..ec7345796 100644 --- a/packages/ecmascript/src/Map.ts +++ b/packages/ecmascript/src/Map.ts @@ -66,12 +66,11 @@ export default class Map { public set(key: any, value: any): any { let exist = this.has(key); + this.items[key] = value; + if (exist) { - this.items[key] = value; - this.size++; return this; } - this.items[key] = value; this.size++; return this; From 933296baf086dee22284c78e89c4d7b51bc2e559 Mon Sep 17 00:00:00 2001 From: Alexander Kantchev Date: Thu, 25 Jul 2024 16:23:08 +0300 Subject: [PATCH 40/67] [Task 353] fix: Size in the Set class incorrect. Signed-off-by: Alexander Kantchev --- packages/ecmascript/src/Set.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/ecmascript/src/Set.ts b/packages/ecmascript/src/Set.ts index 3a9ec043e..b07cdafb0 100644 --- a/packages/ecmascript/src/Set.ts +++ b/packages/ecmascript/src/Set.ts @@ -54,7 +54,12 @@ export default class Set { } public add(value: any): any { + let exist = this.has(value); this.items[value] = true; + + if (exist) { + return this; + } this.size++; return this; From 841375351eafbf9bd3f1a87bdf428c606f199774 Mon Sep 17 00:00:00 2001 From: Stefan Genov Date: Fri, 26 Jul 2024 12:04:12 +0300 Subject: [PATCH 41/67] fix: Removed unused decorator property case Signed-off-by: Stefan Genov --- .../workflow/decorators/actionItemDecoratorStrategy.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/actionItemDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/actionItemDecoratorStrategy.ts index 58cfa2b10..820624b2c 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/actionItemDecoratorStrategy.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/actionItemDecoratorStrategy.ts @@ -67,10 +67,6 @@ export default class ActionItemDecoratorStrategy implements CanvasItemDecoratorS itemInfo.target = propValue; break; - case "exception": - itemInfo.canvasItemPolymorphicBag.exception = propValue; - break; - case "scriptModule": itemInfo.canvasItemPolymorphicBag.scriptModule = propValue; break; From 3fa88fa09354e1ad2ef65c7c14be8bd9511938fe Mon Sep 17 00:00:00 2001 From: Alexander Kantchev Date: Fri, 26 Jul 2024 12:07:28 +0300 Subject: [PATCH 42/67] [Task 353] code: Made size public in Map and Set classes. Signed-off-by: Alexander Kantchev --- packages/ecmascript/src/Map.ts | 2 +- packages/ecmascript/src/Set.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/ecmascript/src/Map.ts b/packages/ecmascript/src/Map.ts index ec7345796..bb3c610a6 100644 --- a/packages/ecmascript/src/Map.ts +++ b/packages/ecmascript/src/Map.ts @@ -14,7 +14,7 @@ */ export default class Map { - private size: number = 0; + public size: number = 0; private items: { [name: string]: any } = {}; constructor(values?: ReadonlyArray<[K, V]> | null) { diff --git a/packages/ecmascript/src/Set.ts b/packages/ecmascript/src/Set.ts index b07cdafb0..a26f79a85 100644 --- a/packages/ecmascript/src/Set.ts +++ b/packages/ecmascript/src/Set.ts @@ -13,7 +13,7 @@ * #L% */ export default class Set { - private size: number = 0; + public size: number = 0; private items: { [name: string]: boolean } = {}; constructor(values?: ReadonlyArray | null) { From d3bef6fba684996925b2bfd1852452bc6aa25e91 Mon Sep 17 00:00:00 2001 From: Remco Post Date: Fri, 26 Jul 2024 11:58:03 +0200 Subject: [PATCH 43/67] [polyglot] Change python runtime to 3.10 Signed-off-by: Remco Post --- docs/versions/latest/Release.md | 4 ++++ typescript/polyglotpkg/src/lib/model.ts | 3 ++- typescript/polyglotpkg/src/lib/utils.ts | 10 ++++++++-- typescript/polyglotpkg/src/packager.ts | 1 + 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/docs/versions/latest/Release.md b/docs/versions/latest/Release.md index 818b7e9b3..4256e1164 100644 --- a/docs/versions/latest/Release.md +++ b/docs/versions/latest/Release.md @@ -24,6 +24,10 @@ [//]: # (Optional But higlhy recommended Specify *NONE* if missing) [//]: # (#### Relevant Documentation:) +### Support python 3.10 runtime + +Add support for python 3.10 runtime in Orchestrator. This is now the default, since python 3.7 is deprecated. + ### *New `@ActionItem` decorator for Workflows* The new decorator gives you the ability to specify a canvas item that calls an action. diff --git a/typescript/polyglotpkg/src/lib/model.ts b/typescript/polyglotpkg/src/lib/model.ts index c06360cc2..dad8adcd9 100644 --- a/typescript/polyglotpkg/src/lib/model.ts +++ b/typescript/polyglotpkg/src/lib/model.ts @@ -27,6 +27,7 @@ export enum ActionRuntime { VRO_POWERCLI_11_PS_62 = 'powercli:11-powershell-6.2', VRO_POWERCLI_12_PS_71 = 'powercli:12-powershell-7.1', VRO_PYTHON_37 = 'python:3.7', + VRO_PYTHON_310 = 'python:3.10', ABX_NODEJS = 'nodejs', ABX_POWERSHELL = 'powershell', ABX_PYTHON = 'python', @@ -35,7 +36,7 @@ export enum ActionRuntime { export type ActionRuntimeType = ActionRuntime.ABX_NODEJS | ActionRuntime.VRO_NODEJS_12 | ActionRuntime.VRO_NODEJS_14 | ActionRuntime.ABX_POWERSHELL | ActionRuntime.VRO_POWERCLI_11_PS_62 | ActionRuntime.VRO_POWERCLI_12_PS_71 - | ActionRuntime.VRO_PYTHON_37 | ActionRuntime.ABX_PYTHON + | ActionRuntime.VRO_PYTHON_37 | ActionRuntime.VRO_PYTHON_310 | ActionRuntime.ABX_PYTHON export type PackageDefinition = { [key: string]: any, diff --git a/typescript/polyglotpkg/src/lib/utils.ts b/typescript/polyglotpkg/src/lib/utils.ts index 6ed266d86..ca0c081c6 100644 --- a/typescript/polyglotpkg/src/lib/utils.ts +++ b/typescript/polyglotpkg/src/lib/utils.ts @@ -27,8 +27,11 @@ export function determineRuntime(pkg: PlatformDefinition, actionType?: ActionTyp return actionType === ActionType.ABX ? ActionRuntime.ABX_POWERSHELL : ActionRuntime.VRO_POWERCLI_11_PS_62; case "powercli:12-powershell-7.1": return actionType === ActionType.ABX ? ActionRuntime.ABX_POWERSHELL : ActionRuntime.VRO_POWERCLI_12_PS_71; - case "python": + case "python:3.7": return actionType === ActionType.ABX ? ActionRuntime.ABX_PYTHON : ActionRuntime.VRO_PYTHON_37; + case "python:3.10": + case "python": + return actionType === ActionType.ABX ? ActionRuntime.ABX_PYTHON : ActionRuntime.VRO_PYTHON_310; default: return pkg.platform.runtime; } @@ -45,8 +48,11 @@ export function determineRuntime(pkg: PlatformDefinition, actionType?: ActionTyp case "powercli:11-powershell-6.2": case 'powershell': return pkg.vro ? ActionRuntime.VRO_POWERCLI_11_PS_62 : ActionRuntime.ABX_POWERSHELL; - case 'python': + case 'python:3.7': return pkg.vro ? ActionRuntime.VRO_PYTHON_37 : ActionRuntime.ABX_PYTHON; + case 'python:3.10': + case 'python': + return pkg.vro ? ActionRuntime.VRO_PYTHON_310 : ActionRuntime.ABX_PYTHON; default: return pkg.platform.runtime; } diff --git a/typescript/polyglotpkg/src/packager.ts b/typescript/polyglotpkg/src/packager.ts index 6f4ac774b..0b1fab0cd 100644 --- a/typescript/polyglotpkg/src/packager.ts +++ b/typescript/polyglotpkg/src/packager.ts @@ -60,6 +60,7 @@ export class Packager extends EventEmitter { await strategy.packageProject(); break; case ActionRuntime.ABX_PYTHON: + case ActionRuntime.VRO_PYTHON_310: case ActionRuntime.VRO_PYTHON_37: strategy = new PythonStrategy(this.logger, projectActions[i], (e: Events) => this.emit(e)); await strategy.packageProject(); From e79bcc72bbc952b661cbca3d10d880e129c11e86 Mon Sep 17 00:00:00 2001 From: Stefan Genov Date: Mon, 29 Jul 2024 09:19:59 +0300 Subject: [PATCH 44/67] feat: Add graph generator Signed-off-by: Stefan Genov --- .../workflow/decorators/helpers/graph.ts | 244 ++++++++++++++++++ 1 file changed, 244 insertions(+) create mode 100644 typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/helpers/graph.ts diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/helpers/graph.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/helpers/graph.ts new file mode 100644 index 000000000..583ce3eda --- /dev/null +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/helpers/graph.ts @@ -0,0 +1,244 @@ +// const nodes = [ +// // First Start +// { name: "A", targets: ["B"] }, +// { name: "B", targets: ["C"] }, +// { name: "C", targets: ["D", "G"] }, +// { name: "D", targets: ["E"] }, +// { name: "E", targets: ["C", "F"] }, +// { name: "F", targets: ["O"] }, +// { name: "G", targets: ["H"] }, +// { name: "H", targets: ["I"] }, +// { name: "I", targets: ["J", "K", "L", "M"] }, +// { name: "J", targets: [] }, +// { name: "K", targets: [] }, +// { name: "L", targets: [] }, +// { name: "M", targets: [] }, +// { name: "O", targets: ["P"] }, +// { name: "P", targets: ["Q"] }, +// { name: "Q", targets: [] }, +// +// // Second start +// { name: "S", targets: ["T"] }, +// { name: "T", targets: ["U", "W", "D"] }, +// { name: "U", targets: [] }, +// { name: "W", targets: [] }, +// +// // Third Start +// { name: "X", targets: ["Y"] }, +// { name: "Y", targets: [] }, +// ]; +// +// const graph = new Graph(nodes, ["A", "S", "X"]); +// +// graph.draw(); + +/** + * The node holds information about it's position + */ +export interface GraphNode { + name: string; + x?: number; + y?: number; + targets: string[]; +} + +/** + * Leaf holds the node and it's children(leaves) + */ +export interface Leaf { + node: GraphNode; + leaves: Leaf[]; +} + +/** + * Tree holds the structure of the graph, it's populated with the calculated positions + */ +interface Tree { + startNodes: string[]; + leaves: { + [nodeName: string]: Leaf; + }; +} + +export class Graph { + /** + * Space between nodes + */ + public NODE_SPACING = 5; + + /** + * Max width of the graph + */ + public WIDTH = 100; + + /** + * Max height of the graph + */ + public HEIGHT = 40; + + /** + * Holds a flag if calculations were already done + */ + private calculated = false; + + /** + * Will hold the calculated tree + */ + private tree: Tree; + + /** + * @param {GraphNode[]} nodes - List of the nodes that will be used to build the tree + * @param {string[]} startNodeNames - List of the names of the nodes that will be used as the start of the tree + */ + constructor( + private nodes: GraphNode[], + startNodeNames: string[] + ) { + this.tree = { + startNodes: startNodeNames, + leaves: {} + }; + + this.calculatePositions(); + } + + /** + * Use to draw a graph in the console + * + * @WARN: Used for debugging purposes + */ + public draw() { + this.calculatePositions(); + + const grid = Array.from({ length: this.HEIGHT }, () => Array(this.WIDTH).fill('.')); + + for (const leaf of Object.values(this.tree.leaves)) { + grid[Math.round(leaf.node.y)][Math.round(leaf.node.x)] = leaf.node.name; + } + + grid.forEach(line => console.log(line.join(''))); + } + + /** + * Retrieves the node by name + * + * @param {string} name + * @returns {GraphNode} + * @throws {Error} if the node is not found + */ + public getNode(name: string): GraphNode { + const node = this.nodes.find(node => node.name === name); + if (!node) { + throw new Error(`Node "${name}" not found`); + } + + return node; + } + + /** + * Get the leaf by name + * + * @param {string} name + * @returns {Leaf | null} + */ + public getLeaf(name: string): Leaf { + const leaf = this.tree.leaves[name]; + if (!leaf) { + throw new Error(`Leaf "${name}" not found`); + } + + return leaf; + } + + /** + * Check if a node is already at the given position + */ + private hasOverlap(x: number, y: number) { + for (const leaf of Object.values(this.tree.leaves)) { + if (Math.round(leaf.node.x) === Math.round(x) && Math.round(leaf.node.y) === Math.round(y)) { + return true; + } + } + return false; + } + + /** + * Builds the tree + * + * Calculates the x and y positions of each leaf + */ + private buildTree( + origin: GraphNode, + visited: Set = new Set(), + x: number = this.NODE_SPACING, + y: number = this.HEIGHT / 2 + ) { + while (this.hasOverlap(x, y)) { + y += this.NODE_SPACING; + } + + origin.x = x; + origin.y = y; + + let positions = { + x: x + this.NODE_SPACING, + y: y + }; + + if (origin.targets.length > 1) { + positions.y -= this.NODE_SPACING * (origin.targets.length - 1) / 2; + } + + origin.targets.forEach(targetName => { + const target = this.getNode(targetName); + + if (!this.tree.leaves[target.name]) { + this.tree.leaves[target.name] = { + node: target, + leaves: [] + }; + } + + const targetLeaf = this.getLeaf(target.name); + this.getLeaf(origin.name).leaves.push(targetLeaf); + + // LPS (`Loop Prevention System`) + if (visited.has(target)) return; + visited.add(target); + + this.buildTree(targetLeaf.node, visited, positions.x, positions.y); + positions.y += this.NODE_SPACING; + }); + } + + /** + * Calculates all the positions of the tree leaves + * + * If this method is called multiple times, it will only calculate the positions once + */ + private calculatePositions() { + if (this.calculated) return; + + for (const node of this.nodes) { + this.tree.leaves[node.name] = { + node, + leaves: [] + }; + } + + const visited = new Set(); + const spacedOutY = this.HEIGHT / (this.tree.startNodes.length + 1); + const positions = { x: this.NODE_SPACING, y: spacedOutY }; + + for (const name of this.tree.startNodes) { + const startNode = this.getNode(name); + this.buildTree(startNode, visited, positions.x, positions.y); + + positions.y += spacedOutY; + } + + this.calculated = true; + } + + +} From f0ebf1b9a8b107d45d2574ebaa0b7e708a1fc673 Mon Sep 17 00:00:00 2001 From: Stefan Genov Date: Mon, 29 Jul 2024 14:52:25 +0300 Subject: [PATCH 45/67] feat: Added graph presentation for canvas items Signed-off-by: Stefan Genov --- .../decorators/actionItemDecoratorStrategy.ts | 15 +- .../asyncWorkflowItemDecoratorStrategy.ts | 15 +- .../decorators/canvasItemDecoratorStrategy.ts | 8 +- .../decisionItemDecoratorStrategy.ts | 18 +- .../defaultErrorHandlerDecoratorStrategy.ts | 24 ++- .../decorators/endItemDecoratorStrategy.ts | 24 ++- .../workflow/decorators/helpers/graph.ts | 185 ++++++++++++------ .../decorators/itemDecoratorStrategy.ts | 15 +- .../decorators/rootItemDecoratorStrategy.ts | 7 +- .../scheduledWorkflowItemDecoratorStrategy.ts | 15 +- .../waitingTimerItemDecoratorStrategy.ts | 14 +- .../workflowItemDecoratorStrategy.ts | 15 +- .../fileTransformers/workflow/presentation.ts | 50 ++++- 13 files changed, 306 insertions(+), 99 deletions(-) diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/actionItemDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/actionItemDecoratorStrategy.ts index 820624b2c..276332701 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/actionItemDecoratorStrategy.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/actionItemDecoratorStrategy.ts @@ -20,6 +20,7 @@ import { findTargetItem } from "../helpers/findTargetItem"; import CanvasItemDecoratorStrategy from "./canvasItemDecoratorStrategy"; import { InputOutputBindings, buildItemParameterBindings } from "./helpers/presentation"; import { ActionItemSourceFilePrinter, SourceFilePrinter } from "./helpers/sourceFile"; +import { GraphNode } from "./helpers/graph"; /** * @@ -77,6 +78,16 @@ export default class ActionItemDecoratorStrategy implements CanvasItemDecoratorS }); } + /** + * @see CanvasItemDecoratorStrategy.getGraphNode + */ + getGraphNode(itemInfo: WorkflowItemDescriptor, pos: number): GraphNode { + return { + name: `item${pos}`, + targets: [findTargetItem(itemInfo.target, pos, itemInfo)] + }; + } + /** * There is no need to print the source file for the workflow item */ @@ -95,7 +106,7 @@ export default class ActionItemDecoratorStrategy implements CanvasItemDecoratorS * * @returns The string representation of the item */ - printItem(itemInfo: WorkflowItemDescriptor, pos: number): string { + printItem(itemInfo: WorkflowItemDescriptor, pos: number, x: number, y: number): string { const stringBuilder = new StringBuilderClass("", ""); this.validateNeededParameters(itemInfo); @@ -117,7 +128,7 @@ export default class ActionItemDecoratorStrategy implements CanvasItemDecoratorS stringBuilder.append(``).appendLine(); stringBuilder.appendContent(buildItemParameterBindings(itemInfo, InputOutputBindings.IN_BINDINGS)); stringBuilder.appendContent(buildItemParameterBindings(itemInfo, InputOutputBindings.OUT_BINDINGS)); - stringBuilder.append(``).appendLine(); + stringBuilder.append(``).appendLine(); stringBuilder.unindent(); stringBuilder.append(``).appendLine(); diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/asyncWorkflowItemDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/asyncWorkflowItemDecoratorStrategy.ts index d99cd1035..7f2fce766 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/asyncWorkflowItemDecoratorStrategy.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/asyncWorkflowItemDecoratorStrategy.ts @@ -20,6 +20,7 @@ import { findTargetItem } from "../helpers/findTargetItem"; import CanvasItemDecoratorStrategy from "./canvasItemDecoratorStrategy"; import { InputOutputBindings, buildItemParameterBindings } from "./helpers/presentation"; import { AsyncWorkflowItemSourceFilePrinter, SourceFilePrinter } from "./helpers/sourceFile"; +import { GraphNode } from "./helpers/graph"; /** * @@ -102,6 +103,16 @@ export default class AsyncWorkflowItemDecoratorStrategy implements CanvasItemDec }); } + /** + * @see CanvasItemDecoratorStrategy.getGraphNode + */ + getGraphNode(itemInfo: WorkflowItemDescriptor, pos: number): GraphNode { + return { + name: `item${pos}`, + targets: [findTargetItem(itemInfo.target, pos, itemInfo)] + }; + } + /** * There is no need to print the source file for the workflow item */ @@ -120,7 +131,7 @@ export default class AsyncWorkflowItemDecoratorStrategy implements CanvasItemDec * * @returns The string representation of the item */ - printItem(itemInfo: WorkflowItemDescriptor, pos: number): string { + printItem(itemInfo: WorkflowItemDescriptor, pos: number, x: number, y: number): string { const stringBuilder = new StringBuilderClass("", ""); this.validateNeededParameters(itemInfo); @@ -143,7 +154,7 @@ export default class AsyncWorkflowItemDecoratorStrategy implements CanvasItemDec stringBuilder.append(``).appendLine(); stringBuilder.appendContent(buildItemParameterBindings(itemInfo, InputOutputBindings.IN_BINDINGS)); stringBuilder.appendContent(buildItemParameterBindings(itemInfo, InputOutputBindings.OUT_BINDINGS)); - stringBuilder.append(``).appendLine(); + stringBuilder.append(``).appendLine(); stringBuilder.unindent(); stringBuilder.append(``).appendLine(); diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/canvasItemDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/canvasItemDecoratorStrategy.ts index 86dde7073..26f1a1149 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/canvasItemDecoratorStrategy.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/canvasItemDecoratorStrategy.ts @@ -14,6 +14,7 @@ */ import * as ts from "typescript"; import { WorkflowItemDescriptor, WorkflowItemType } from "../../../../decorators"; +import { GraphNode } from "./helpers/graph"; export default interface CanvasItemDecoratorStrategy { /** @@ -38,6 +39,11 @@ export default interface CanvasItemDecoratorStrategy { */ printSourceFile(methodNode: ts.MethodDeclaration, sourceFile: ts.SourceFile, itemInfo: WorkflowItemDescriptor): string; - printItem(itemInfo: WorkflowItemDescriptor, pos: number): string; + printItem(itemInfo: WorkflowItemDescriptor, pos: number, x: number, y: number): string; + + /** + * Returns the Node representation of the item + */ + getGraphNode(itemInfo: WorkflowItemDescriptor, pos: number): GraphNode; } diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/decisionItemDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/decisionItemDecoratorStrategy.ts index 8ae654ae4..c4fb7689c 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/decisionItemDecoratorStrategy.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/decisionItemDecoratorStrategy.ts @@ -20,6 +20,7 @@ import { findTargetItem } from "../helpers/findTargetItem"; import CanvasItemDecoratorStrategy from "./canvasItemDecoratorStrategy"; import { InputOutputBindings, buildItemParameterBindings } from "./helpers/presentation"; import { SourceFilePrinter, WrapperSourceFilePrinter } from "./helpers/sourceFile"; +import { GraphNode } from "./helpers/graph"; /** * Responsible for printing out decision items @@ -70,6 +71,19 @@ export default class DecisionItemDecoratorStrategy implements CanvasItemDecorato }); } + /** + * @see CanvasItemDecoratorStrategy.getGraphNode + */ + getGraphNode(itemInfo: WorkflowItemDescriptor, pos: number): GraphNode { + return { + name: `item${pos}`, + targets: [ + findTargetItem(itemInfo.target, pos, itemInfo), + findTargetItem((itemInfo.canvasItemPolymorphicBag as CanvasItemPolymorphicBagForDecision).else, pos, itemInfo) + ] + }; + } + printSourceFile(methodNode: MethodDeclaration, sourceFile: SourceFile, itemInfo: WorkflowItemDescriptor): string { return this.sourceFilePrinter.printSourceFile(methodNode, sourceFile, itemInfo); } @@ -87,7 +101,7 @@ export default class DecisionItemDecoratorStrategy implements CanvasItemDecorato * @param pos The position of the item in the workflow * @returns The string representation of the decision item */ - printItem(itemInfo: WorkflowItemDescriptor, pos: number): string { + printItem(itemInfo: WorkflowItemDescriptor, pos: number, x: number, y: number): string { const stringBuilder = new StringBuilderClass("", ""); const targetItem = findTargetItem(itemInfo.target, pos, itemInfo); @@ -108,7 +122,7 @@ export default class DecisionItemDecoratorStrategy implements CanvasItemDecorato stringBuilder.append(``).appendLine(); stringBuilder.appendContent(buildItemParameterBindings(itemInfo, InputOutputBindings.IN_BINDINGS)); stringBuilder.appendContent(buildItemParameterBindings(itemInfo, InputOutputBindings.OUT_BINDINGS)); - stringBuilder.append(``).appendLine(); + stringBuilder.append(``).appendLine(); stringBuilder.unindent(); stringBuilder.append(``).appendLine(); diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/defaultErrorHandlerDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/defaultErrorHandlerDecoratorStrategy.ts index d0e94039f..5a94aa9f6 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/defaultErrorHandlerDecoratorStrategy.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/defaultErrorHandlerDecoratorStrategy.ts @@ -18,11 +18,7 @@ import { WorkflowItemDescriptor, WorkflowItemType } from "../../../../decorators import { getDecoratorProps } from "../../../helpers/node"; import { findTargetItem } from "../helpers/findTargetItem"; import CanvasItemDecoratorStrategy from "./canvasItemDecoratorStrategy"; - -// UI positioning constants in the output XML file. -const xBasePosition = 180; -const yBasePosition = 110; -const offSet = 20; +import { GraphNode } from "./helpers/graph"; /** * Responsible for printing out a default error handler @@ -87,12 +83,20 @@ export default class DefaultErrorHandlerDecoratorStrategy implements CanvasItemD } /** - * There is no need to print the source file for the default error handler. + * @see CanvasItemDecoratorStrategy.getGraphNode */ - public printSourceFile(methodNode: MethodDeclaration, sourceFile: SourceFile, itemInfo: WorkflowItemDescriptor): string { - return ""; + getGraphNode(itemInfo: WorkflowItemDescriptor, pos: number): GraphNode { + return { + name: `item${pos}`, + targets: [findTargetItem(itemInfo.target, pos, itemInfo)] + }; } + /** + * There is no need to print the source file for the default error handler. + */ + public printSourceFile(methodNode: MethodDeclaration, sourceFile: SourceFile, itemInfo: WorkflowItemDescriptor): string { return ""; } + /** * Prints out the default handler item. Note that it needs to be connected with an end item and * both must have identical name. @@ -102,7 +106,7 @@ export default class DefaultErrorHandlerDecoratorStrategy implements CanvasItemD * * @returns The string representation of the item. */ - public printItem(itemInfo: WorkflowItemDescriptor, pos: number): string { + printItem(itemInfo: WorkflowItemDescriptor, pos: number, x: number, y: number): string { const stringBuilder = new StringBuilderClass("", ""); const targetItemName = findTargetItem(itemInfo.target, pos, itemInfo); @@ -117,7 +121,7 @@ export default class DefaultErrorHandlerDecoratorStrategy implements CanvasItemD } stringBuilder.append(">").appendLine(); stringBuilder.indent(); - stringBuilder.append(``).appendLine(); + stringBuilder.append(``).appendLine(); stringBuilder.unindent(); stringBuilder.append("").appendLine(); stringBuilder.unindent(); diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/endItemDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/endItemDecoratorStrategy.ts index ffe1b582f..f82b29a0a 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/endItemDecoratorStrategy.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/endItemDecoratorStrategy.ts @@ -18,11 +18,7 @@ import { WorkflowItemDescriptor, WorkflowItemType } from "../../../../decorators import { getDecoratorProps } from "../../../helpers/node"; import CanvasItemDecoratorStrategy from "./canvasItemDecoratorStrategy"; import { buildItemParameterBindings, InputOutputBindings } from "./helpers/presentation"; - -// UI positioning constants in the output XML file. -const xBasePosition = 160; -const yBasePosition = 100; -const offSet = 20; +import { GraphNode } from "./helpers/graph"; /** * Responsible for printing out the workflow end item. @@ -91,12 +87,20 @@ export default class EndItemDecoratorStrategy implements CanvasItemDecoratorStra } /** - * There is no need to print the source file for the workflow item. + * @see CanvasItemDecoratorStrategy.getGraphNode */ - printSourceFile(methodNode: MethodDeclaration, sourceFile: SourceFile, itemInfo: WorkflowItemDescriptor): string { - return ""; + getGraphNode(itemInfo: WorkflowItemDescriptor, pos: number): GraphNode { + return { + name: `item${pos}`, + targets: [] + }; } + /** + * There is no need to print the source file for the workflow item. + */ + printSourceFile(methodNode: MethodDeclaration, sourceFile: SourceFile, itemInfo: WorkflowItemDescriptor): string { return ""; } + /** * Prints out the end item. * @@ -105,7 +109,7 @@ export default class EndItemDecoratorStrategy implements CanvasItemDecoratorStra * * @returns The string representation of the item. */ - printItem(itemInfo: WorkflowItemDescriptor, pos: number): string { + printItem(itemInfo: WorkflowItemDescriptor, pos: number, x: number, y: number): string { const stringBuilder = new StringBuilderClass("", ""); const endMode = itemInfo?.canvasItemPolymorphicBag?.endMode ?? 0; @@ -122,7 +126,7 @@ export default class EndItemDecoratorStrategy implements CanvasItemDecoratorStra stringBuilder.append(">").appendLine(); stringBuilder.indent(); stringBuilder.appendContent(buildItemParameterBindings(itemInfo, InputOutputBindings.OUT_BINDINGS)); - stringBuilder.append(``).appendLine(); + stringBuilder.append(``).appendLine(); stringBuilder.unindent(); stringBuilder.append(``).appendLine(); diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/helpers/graph.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/helpers/graph.ts index 583ce3eda..8a959c4a9 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/helpers/graph.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/helpers/graph.ts @@ -1,36 +1,17 @@ -// const nodes = [ -// // First Start -// { name: "A", targets: ["B"] }, -// { name: "B", targets: ["C"] }, -// { name: "C", targets: ["D", "G"] }, -// { name: "D", targets: ["E"] }, -// { name: "E", targets: ["C", "F"] }, -// { name: "F", targets: ["O"] }, -// { name: "G", targets: ["H"] }, -// { name: "H", targets: ["I"] }, -// { name: "I", targets: ["J", "K", "L", "M"] }, -// { name: "J", targets: [] }, -// { name: "K", targets: [] }, -// { name: "L", targets: [] }, -// { name: "M", targets: [] }, -// { name: "O", targets: ["P"] }, -// { name: "P", targets: ["Q"] }, -// { name: "Q", targets: [] }, -// -// // Second start -// { name: "S", targets: ["T"] }, -// { name: "T", targets: ["U", "W", "D"] }, -// { name: "U", targets: [] }, -// { name: "W", targets: [] }, -// -// // Third Start -// { name: "X", targets: ["Y"] }, -// { name: "Y", targets: [] }, -// ]; -// -// const graph = new Graph(nodes, ["A", "S", "X"]); -// -// graph.draw(); +/*- + * #%L + * vrotsc + * %% + * Copyright (C) 2023 - 2024 VMware + * %% + * Build Tools for VMware Aria + * Copyright 2023 VMware, Inc. + * + * This product is licensed to you under the BSD-2 license (the "License"). You may not use this product except in compliance with the BSD-2 License. + * + * This product may include a number of subcomponents with separate copyright notices and license terms. Your use of these subcomponents is subject to the terms and conditions of the subcomponent's license, as noted in the LICENSE file. + * #L% + */ /** * The node holds information about it's position @@ -60,22 +41,77 @@ interface Tree { }; } +/** + * This is used to chart out a graph and give you the x and y positions of each node + * + * Example: + * ```typescript +const nodes = [ + // First Start + { name: "A", targets: ["B"] }, + { name: "B", targets: ["C"] }, + { name: "C", targets: ["D", "G"] }, + { name: "D", targets: ["E"] }, + { name: "E", targets: ["C", "F"] }, + { name: "F", targets: ["O"] }, + { name: "G", targets: ["H"] }, + { name: "H", targets: ["I"] }, + { name: "I", targets: ["J", "K", "L", "M"] }, + { name: "J", targets: [] }, + { name: "K", targets: [] }, + { name: "L", targets: [] }, + { name: "M", targets: [] }, + { name: "O", targets: ["P"] }, + { name: "P", targets: ["Q"] }, + { name: "Q", targets: [] }, + + // Second start + { name: "S", targets: ["T"] }, + { name: "T", targets: ["U", "W", "D"] }, + { name: "U", targets: [] }, + { name: "W", targets: [] }, + + // Third Start + { name: "X", targets: ["Y"] }, + { name: "Y", targets: [] }, +]; + +const graph = new Graph(nodes, ["A", "S", "X"]); + +graph.draw(); + * ``` + * + * Will output: + * ``` +.................................................................................................... +.................................................................................................... +.................................................................................................... +..............................F....O....P....Q...................................................... +.................................................................................................... +.................................................................................................... +....................D....E.......................................................................... +.................................................................................................... +.....A....B....C...................J................................................................ +.................................................................................................... +.................................................................................................... +....................G....H....I..................................................................... +.................................................................................................... +.....S....T....U...................K................................................................ +.................................................................................................... +.................................................................................................... +.................................................................................................... +.................................................................................................... +...............W...................L................................................................ +.................................................................................................... +.................................................................................................... +.................................................................................................... +.................................................................................................... +...................................M................................................................ +.................................................................................................... +.................................................................................................... + * ``` + */ export class Graph { - /** - * Space between nodes - */ - public NODE_SPACING = 5; - - /** - * Max width of the graph - */ - public WIDTH = 100; - - /** - * Max height of the graph - */ - public HEIGHT = 40; - /** * Holds a flag if calculations were already done */ @@ -89,10 +125,16 @@ export class Graph { /** * @param {GraphNode[]} nodes - List of the nodes that will be used to build the tree * @param {string[]} startNodeNames - List of the names of the nodes that will be used as the start of the tree + * @param {number} nodeSpacing - The spacing between the nodes + * @param {number} height - The height of the graph + * @param {number} width - The width of the graph */ constructor( private nodes: GraphNode[], - startNodeNames: string[] + startNodeNames: string[], + private nodeSpacing: number = 5, + private readonly height: number = 40, + private readonly width: number = 100 ) { this.tree = { startNodes: startNodeNames, @@ -110,7 +152,7 @@ export class Graph { public draw() { this.calculatePositions(); - const grid = Array.from({ length: this.HEIGHT }, () => Array(this.WIDTH).fill('.')); + const grid = Array.from({ length: this.height }, () => Array(this.width).fill('.')); for (const leaf of Object.values(this.tree.leaves)) { grid[Math.round(leaf.node.y)][Math.round(leaf.node.x)] = leaf.node.name; @@ -150,6 +192,33 @@ export class Graph { return leaf; } + /** + * Height of the graph + * + * Retrieve from here so you don't have to store a variable + */ + public getHeight() { + return this.height; + } + + /** + * Width of the graph + * + * Retrieve from here so you don't have to store a variable + */ + public getWidth() { + return this.width; + } + + /** + * Node spacing + * + * Retrieve from here so you don't have to store a variable + */ + public getNodeSpacing() { + return this.nodeSpacing; + } + /** * Check if a node is already at the given position */ @@ -170,23 +239,23 @@ export class Graph { private buildTree( origin: GraphNode, visited: Set = new Set(), - x: number = this.NODE_SPACING, - y: number = this.HEIGHT / 2 + x: number = this.nodeSpacing, + y: number = this.height / 2 ) { while (this.hasOverlap(x, y)) { - y += this.NODE_SPACING; + y += this.nodeSpacing; } origin.x = x; origin.y = y; let positions = { - x: x + this.NODE_SPACING, + x: x + this.nodeSpacing, y: y }; if (origin.targets.length > 1) { - positions.y -= this.NODE_SPACING * (origin.targets.length - 1) / 2; + positions.y -= this.nodeSpacing * (origin.targets.length - 1) / 2; } origin.targets.forEach(targetName => { @@ -207,7 +276,7 @@ export class Graph { visited.add(target); this.buildTree(targetLeaf.node, visited, positions.x, positions.y); - positions.y += this.NODE_SPACING; + positions.y += this.nodeSpacing; }); } @@ -227,8 +296,8 @@ export class Graph { } const visited = new Set(); - const spacedOutY = this.HEIGHT / (this.tree.startNodes.length + 1); - const positions = { x: this.NODE_SPACING, y: spacedOutY }; + const spacedOutY = this.height / (this.tree.startNodes.length + 1); + const positions = { x: this.nodeSpacing, y: spacedOutY }; for (const name of this.tree.startNodes) { const startNode = this.getNode(name); diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/itemDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/itemDecoratorStrategy.ts index 99b90e268..3003d16ed 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/itemDecoratorStrategy.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/itemDecoratorStrategy.ts @@ -20,6 +20,7 @@ import { findTargetItem } from "../helpers/findTargetItem"; import CanvasItemDecoratorStrategy from "./canvasItemDecoratorStrategy"; import { InputOutputBindings, buildItemParameterBindings } from "./helpers/presentation"; import { DefaultSourceFilePrinter, SourceFilePrinter } from "./helpers/sourceFile"; +import { GraphNode } from "./helpers/graph"; export default class ItemDecoratorStrategy implements CanvasItemDecoratorStrategy { constructor(private readonly sourceFilePrinter: SourceFilePrinter = new DefaultSourceFilePrinter()) { } @@ -54,6 +55,16 @@ export default class ItemDecoratorStrategy implements CanvasItemDecoratorStrateg }); } + /** + * @see CanvasItemDecoratorStrategy.getGraphNode + */ + getGraphNode(itemInfo: WorkflowItemDescriptor, pos: number): GraphNode { + return { + name: `item${pos}`, + targets: [findTargetItem(itemInfo.target, pos, itemInfo)] + }; + } + printSourceFile(methodNode: MethodDeclaration, sourceFile: SourceFile, itemInfo: WorkflowItemDescriptor): string { return this.sourceFilePrinter.printSourceFile(methodNode, sourceFile, itemInfo); } @@ -68,7 +79,7 @@ export default class ItemDecoratorStrategy implements CanvasItemDecoratorStrateg * * @returns The string representation of the item */ - printItem(itemInfo: WorkflowItemDescriptor, pos: number): string { + printItem(itemInfo: WorkflowItemDescriptor, pos: number, x: number, y: number): string { const stringBuilder = new StringBuilderClass("", ""); const targetItem = findTargetItem(itemInfo.target, pos, itemInfo); @@ -88,7 +99,7 @@ export default class ItemDecoratorStrategy implements CanvasItemDecoratorStrateg stringBuilder.append(``).appendLine(); stringBuilder.appendContent(buildItemParameterBindings(itemInfo, InputOutputBindings.IN_BINDINGS)); stringBuilder.appendContent(buildItemParameterBindings(itemInfo, InputOutputBindings.OUT_BINDINGS)); - stringBuilder.append(``).appendLine(); + stringBuilder.append(``).appendLine(); stringBuilder.unindent(); stringBuilder.append(``).appendLine(); diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/rootItemDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/rootItemDecoratorStrategy.ts index 0e0de2a9e..fb2a7f426 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/rootItemDecoratorStrategy.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/rootItemDecoratorStrategy.ts @@ -15,6 +15,7 @@ import { Decorator, MethodDeclaration, SourceFile, isIdentifier, isPrivateIdentifier } from "typescript"; import { WorkflowItemDescriptor, WorkflowItemType } from "../../../../decorators"; import CanvasItemDecoratorStrategy from "./canvasItemDecoratorStrategy"; +import { GraphNode } from "./helpers/graph"; export default class RootItemDecoratorStrategy implements CanvasItemDecoratorStrategy { getDecoratorType(): WorkflowItemType { @@ -34,9 +35,13 @@ export default class RootItemDecoratorStrategy implements CanvasItemDecoratorStr itemInfo.parent.rootItem = methodNode.name.escapedText as string; } + /** + * @see CanvasItemDecoratorStrategy.getGraphNode + */ + getGraphNode(itemInfo: WorkflowItemDescriptor, pos: number): GraphNode { this.throwDoNotCallError(); } printSourceFile(methodNode: MethodDeclaration, sourceFile: SourceFile, itemInfo: WorkflowItemDescriptor): string { return this.throwDoNotCallError(); } getCanvasType(): string { return this.throwDoNotCallError(); } - printItem(itemInfo: WorkflowItemDescriptor, pos: number): string { return this.throwDoNotCallError(); } + printItem(itemInfo: WorkflowItemDescriptor, pos: number, x: number, y: number): string { return this.throwDoNotCallError(); } private throwDoNotCallError(): never { throw new Error("Method should not be called. RootItem is a meta decorator."); diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/scheduledWorkflowItemDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/scheduledWorkflowItemDecoratorStrategy.ts index a9f5affcd..da03c3c4a 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/scheduledWorkflowItemDecoratorStrategy.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/scheduledWorkflowItemDecoratorStrategy.ts @@ -20,6 +20,7 @@ import { findTargetItem } from "../helpers/findTargetItem"; import CanvasItemDecoratorStrategy from "./canvasItemDecoratorStrategy"; import { InputOutputBindings, buildItemParameterBindings } from "./helpers/presentation"; import { ScheduledWorkflowItemSourceFilePrinter, SourceFilePrinter } from "./helpers/sourceFile"; +import { GraphNode } from "./helpers/graph"; /** * @@ -103,6 +104,16 @@ export default class ScheduledWorkflowItemDecoratorStrategy implements CanvasIte }); } + /** + * @see CanvasItemDecoratorStrategy.getGraphNode + */ + getGraphNode(itemInfo: WorkflowItemDescriptor, pos: number): GraphNode { + return { + name: `item${pos}`, + targets: [findTargetItem(itemInfo.target, pos, itemInfo)] + }; + } + /** * There is no need to print the source file for the workflow item */ @@ -120,7 +131,7 @@ export default class ScheduledWorkflowItemDecoratorStrategy implements CanvasIte * * @returns The string representation of the item */ - printItem(itemInfo: WorkflowItemDescriptor, pos: number): string { + printItem(itemInfo: WorkflowItemDescriptor, pos: number, x: number, y: number): string { const stringBuilder = new StringBuilderClass("", ""); this.validateNeededParameters(itemInfo); @@ -143,7 +154,7 @@ export default class ScheduledWorkflowItemDecoratorStrategy implements CanvasIte stringBuilder.append(``).appendLine(); stringBuilder.appendContent(buildItemParameterBindings(itemInfo, InputOutputBindings.IN_BINDINGS)); stringBuilder.appendContent(buildItemParameterBindings(itemInfo, InputOutputBindings.OUT_BINDINGS)); - stringBuilder.append(``).appendLine(); + stringBuilder.append(``).appendLine(); stringBuilder.unindent(); stringBuilder.append(``).appendLine(); diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/waitingTimerItemDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/waitingTimerItemDecoratorStrategy.ts index d063f36ad..bf604d4f5 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/waitingTimerItemDecoratorStrategy.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/waitingTimerItemDecoratorStrategy.ts @@ -19,6 +19,7 @@ import { getDecoratorProps } from "../../../helpers/node"; import { findTargetItem } from "../helpers/findTargetItem"; import CanvasItemDecoratorStrategy from "./canvasItemDecoratorStrategy"; import { InputOutputBindings, buildItemParameterBindings } from "./helpers/presentation"; +import { GraphNode } from "./helpers/graph"; /** * Responsible for printing out the waiting timer item @@ -63,6 +64,15 @@ export default class WaitingTimerItemDecoratorStrategy implements CanvasItemDeco }); } + /** + * @see CanvasItemDecoratorStrategy.getGraphNode + */ + getGraphNode(itemInfo: WorkflowItemDescriptor, pos: number): GraphNode { + return { + name: `item${pos}`, + targets: [findTargetItem(itemInfo.target, pos, itemInfo)] + }; + } /** * There is no need to print the source file for a waiting timer item @@ -78,7 +88,7 @@ export default class WaitingTimerItemDecoratorStrategy implements CanvasItemDeco * @param pos The position of the item in the workflow * @returns The string representation of the item */ - printItem(itemInfo: WorkflowItemDescriptor, pos: number): string { + printItem(itemInfo: WorkflowItemDescriptor, pos: number, x: number, y: number): string { const stringBuilder = new StringBuilderClass("", ""); const targetItem = findTargetItem(itemInfo.target, pos, itemInfo); @@ -96,7 +106,7 @@ export default class WaitingTimerItemDecoratorStrategy implements CanvasItemDeco stringBuilder.append(``).appendLine(); stringBuilder.appendContent(buildItemParameterBindings(itemInfo, InputOutputBindings.IN_BINDINGS)); stringBuilder.appendContent(buildItemParameterBindings(itemInfo, InputOutputBindings.OUT_BINDINGS)); - stringBuilder.append(``).appendLine(); + stringBuilder.append(``).appendLine(); stringBuilder.unindent(); stringBuilder.append(``).appendLine(); diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/workflowItemDecoratorStrategy.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/workflowItemDecoratorStrategy.ts index 1060f479b..4017ec6be 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/workflowItemDecoratorStrategy.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/workflowItemDecoratorStrategy.ts @@ -19,6 +19,7 @@ import { getDecoratorProps } from "../../../helpers/node"; import { findTargetItem } from "../helpers/findTargetItem"; import CanvasItemDecoratorStrategy from "./canvasItemDecoratorStrategy"; import { InputOutputBindings, buildItemParameterBindings } from "./helpers/presentation"; +import { GraphNode } from "./helpers/graph"; /** * @@ -75,6 +76,16 @@ export default class WorkflowItemDecoratorStrategy implements CanvasItemDecorato }); } + /** + * @see CanvasItemDecoratorStrategy.getGraphNode + */ + getGraphNode(itemInfo: WorkflowItemDescriptor, pos: number): GraphNode { + return { + name: `item${pos}`, + targets: [findTargetItem(itemInfo.target, pos, itemInfo)] + }; + } + /** * There is no need to print the source file for the workflow item */ @@ -90,7 +101,7 @@ export default class WorkflowItemDecoratorStrategy implements CanvasItemDecorato * * @returns The string representation of the item */ - printItem(itemInfo: WorkflowItemDescriptor, pos: number): string { + printItem(itemInfo: WorkflowItemDescriptor, pos: number, x: number, y: number): string { const stringBuilder = new StringBuilderClass("", ""); const targetItem = findTargetItem(itemInfo.target, pos, itemInfo); @@ -108,7 +119,7 @@ export default class WorkflowItemDecoratorStrategy implements CanvasItemDecorato stringBuilder.append(``).appendLine(); stringBuilder.appendContent(buildItemParameterBindings(itemInfo, InputOutputBindings.IN_BINDINGS)); stringBuilder.appendContent(buildItemParameterBindings(itemInfo, InputOutputBindings.OUT_BINDINGS)); - stringBuilder.append(``).appendLine(); + stringBuilder.append(``).appendLine(); stringBuilder.unindent(); stringBuilder.append(``).appendLine(); diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/presentation.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/presentation.ts index 956cedbd9..d975f8614 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/presentation.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/presentation.ts @@ -16,9 +16,12 @@ import { WorkflowDescriptor, WorkflowParameter, WorkflowParameterType } from ".. import { FileTransformationContext, XmlElement, XmlNode } from "../../../../types"; import { StringBuilderClass } from "../../../../utilities/stringBuilder"; import { findItemByName } from "./helpers/findItemByName"; +import { Graph } from "./decorators/helpers/graph"; const xmldoc: typeof import("xmldoc") = require("xmldoc"); +const LARGEST_INT32 = 2147483647; + /** * This will print the workflow in XML format * @@ -44,16 +47,22 @@ export function printWorkflowXml(workflow: WorkflowDescriptor, context: FileTran if (workflow.description) { stringBuilder.append(``).appendLine(); } - stringBuilder.append(``).appendLine(); + + const graph = getGraph(workflow); + + stringBuilder.append(``).appendLine(); buildParameters("input", workflow.parameters.filter(p => !p.isAttribute && p.parameterType & WorkflowParameterType.Input)); buildParameters("output", workflow.parameters.filter(p => !p.isAttribute && p.parameterType & WorkflowParameterType.Output)); buildAttributes(workflow.parameters.filter(p => p.isAttribute)); - buildEndItem(); + + const defaultEndNode = graph.getNode("item0"); + buildEndItem(defaultEndNode.x, defaultEndNode.y); workflow.items.forEach((item, i) => { const pos = i + 1; + const node = graph.getNode(`item${pos}`); - stringBuilder.appendContent(item.strategy.printItem(item, pos)); + stringBuilder.appendContent(item.strategy.printItem(item, pos, node.x, node.y)); }); buildPresentation(); @@ -116,10 +125,10 @@ export function printWorkflowXml(workflow: WorkflowDescriptor, context: FileTran stringBuilder.append(` conf-key="${key}" `); } - function buildEndItem() { + function buildEndItem(x: number, y: number) { stringBuilder.append(``).appendLine(); stringBuilder.indent(); - stringBuilder.append(``).appendLine(); + stringBuilder.append(``).appendLine(); stringBuilder.unindent(); stringBuilder.append(``).appendLine(); } @@ -254,3 +263,34 @@ function buildOutput(output: string[]): string { } return output[0]; } + +/** + * Returns the graph for all the nodes. + * + * Will insert the `rootItem` by default as a start node an search for other start nodes + * + * Will insert the default `end` node as well as the others require it but it's not an actual workflow item + */ +function getGraph(workflow: WorkflowDescriptor) { + + const startNodes = [`item${findItemByName(workflow.items, workflow.rootItem) || "1"}`]; + const nodes = workflow.items.map((item, i) => { + switch (item.strategy.getCanvasType()) { + case "error-handler": + startNodes.push(`item${i + 1}`); + break; + default: + break; + } + + return item.strategy.getGraphNode(item, i + 1); + }); + nodes.push({ name: "item0", targets: [] }); + + const nodeSpacing = 100; + const height = 200; + const width = LARGEST_INT32; + const graph = new Graph(nodes, startNodes, nodeSpacing, height, width); + + return graph; +} From 41a372500f8464491dd8fcc2a5a704e08e1203c9 Mon Sep 17 00:00:00 2001 From: Stefan Genov Date: Mon, 29 Jul 2024 14:55:11 +0300 Subject: [PATCH 46/67] test: Add presentation of items in the workflow Signed-off-by: Stefan Genov --- .../workflows/MyOrg/MyProject/Test Workflow 1.xml | 4 ++-- .../workflows/VMware/PSCoE/Action Edge.xml | 4 ++-- .../workflows/VMware/PSCoE/Action Happy Path.xml | 6 +++--- .../workflows/VMware/PSCoE/Async Workflow Test.xml | 10 +++++----- .../canvas-items/workflows/VMware/PSCoE/Complex.xml | 6 +++--- .../workflows/VMware/PSCoE/Decision Edge 2.xml | 2 +- .../workflows/VMware/PSCoE/Decision Edge.xml | 2 +- .../workflows/VMware/PSCoE/Decision Happy.xml | 2 +- .../VMware/PSCoE/Default Error Handler Custom Item.xml | 6 +++--- .../VMware/PSCoE/Default Error Handler Happy.xml | 2 +- .../workflows/VMware/PSCoE/Root Default First.xml | 2 +- .../workflows/VMware/PSCoE/Root When Set.xml | 2 +- .../workflows/VMware/PSCoE/Scheduled Workflow Test.xml | 10 +++++----- .../workflows/VMware/PSCoE/Waitin Timer Edge 2.xml | 2 +- .../workflows/VMware/PSCoE/Waiting Timer Edge.xml | 2 +- .../workflows/VMware/PSCoE/Waiting Timer Happy.xml | 2 +- .../workflows/VMware/PSCoE/Workflow End Exception.xml | 2 +- .../workflows/VMware/PSCoE/Workflow End Happy.xml | 2 +- .../workflows/VMware/PSCoE/Workflow Test.xml | 10 +++++----- .../PS CoE/Test Workflows/Test Workflow 2.xml | 4 ++-- .../PS CoE/Test Workflows/Test Workflow 3.xml | 4 ++-- .../PS CoE/Test Workflows/Test Workflow 4.xml | 10 +++++----- .../PS CoE/Test Workflows/Test Workflow 5.xml | 10 +++++----- .../workflows/PSCoE/vRO TypeScript/TestWorkflow1.xml | 4 ++-- .../PSCoE/vRO TypeScript/sub/TestWorkflow2.xml | 4 ++-- .../PSCoE/vRO TypeScript/sub/sub2/TestWorkflow3.xml | 4 ++-- 26 files changed, 59 insertions(+), 59 deletions(-) diff --git a/typescript/vrotsc/e2e/expect/all-content/workflows/MyOrg/MyProject/Test Workflow 1.xml b/typescript/vrotsc/e2e/expect/all-content/workflows/MyOrg/MyProject/Test Workflow 1.xml index 0ab8a38ec..0cd8084f6 100644 --- a/typescript/vrotsc/e2e/expect/all-content/workflows/MyOrg/MyProject/Test Workflow 1.xml +++ b/typescript/vrotsc/e2e/expect/all-content/workflows/MyOrg/MyProject/Test Workflow 1.xml @@ -1,2 +1,2 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Action Edge.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Action Edge.xml index 3ea60709e..60c41365f 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Action Edge.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Action Edge.xml @@ -1,2 +1,2 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Action Happy Path.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Action Happy Path.xml index 05c5f257a..73c50cc73 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Action Happy Path.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Action Happy Path.xml @@ -1,3 +1,3 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Async Workflow Test.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Async Workflow Test.xml index 3a0fb67fa..9c0381dd1 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Async Workflow Test.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Async Workflow Test.xml @@ -1,13 +1,13 @@ - \ No newline at end of file +]]> \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Complex.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Complex.xml index 46a6b3e3a..3475b0600 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Complex.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Complex.xml @@ -1,4 +1,4 @@ - \ No newline at end of file +]]> \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Decision Edge 2.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Decision Edge 2.xml index 7cff000fb..0afbd45da 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Decision Edge 2.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Decision Edge 2.xml @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Decision Edge.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Decision Edge.xml index 8903355e4..abcc08cf7 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Decision Edge.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Decision Edge.xml @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Decision Happy.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Decision Happy.xml index 60c757042..59cb70e57 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Decision Happy.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Decision Happy.xml @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Default Error Handler Custom Item.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Default Error Handler Custom Item.xml index 791db924d..52731ebde 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Default Error Handler Custom Item.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Default Error Handler Custom Item.xml @@ -1,3 +1,3 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Default Error Handler Happy.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Default Error Handler Happy.xml index 9bec5a2df..368efad84 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Default Error Handler Happy.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Default Error Handler Happy.xml @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Root Default First.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Root Default First.xml index 79c3f3b23..b77b45811 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Root Default First.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Root Default First.xml @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Root When Set.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Root When Set.xml index d88ecd983..88d6869c8 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Root When Set.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Root When Set.xml @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Scheduled Workflow Test.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Scheduled Workflow Test.xml index 594b0523a..1c32065cd 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Scheduled Workflow Test.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Scheduled Workflow Test.xml @@ -1,13 +1,13 @@ - \ No newline at end of file +]]> \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waitin Timer Edge 2.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waitin Timer Edge 2.xml index c26fc1eb9..42f83d5fc 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waitin Timer Edge 2.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waitin Timer Edge 2.xml @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waiting Timer Edge.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waiting Timer Edge.xml index 86d7b7d16..f0092d4b5 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waiting Timer Edge.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waiting Timer Edge.xml @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waiting Timer Happy.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waiting Timer Happy.xml index 493ba4c46..015932aad 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waiting Timer Happy.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waiting Timer Happy.xml @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Exception.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Exception.xml index bb352e32e..a9e620030 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Exception.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Exception.xml @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Happy.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Happy.xml index ffb430d66..878dfec99 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Happy.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Happy.xml @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow Test.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow Test.xml index 4fb02655a..bb5d216a6 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow Test.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow Test.xml @@ -1,7 +1,7 @@ - \ No newline at end of file +]]> \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/workflow/workflows/PS CoE/Test Workflows/Test Workflow 2.xml b/typescript/vrotsc/e2e/expect/workflow/workflows/PS CoE/Test Workflows/Test Workflow 2.xml index a0cf7f5cc..0cadf7ed9 100644 --- a/typescript/vrotsc/e2e/expect/workflow/workflows/PS CoE/Test Workflows/Test Workflow 2.xml +++ b/typescript/vrotsc/e2e/expect/workflow/workflows/PS CoE/Test Workflows/Test Workflow 2.xml @@ -1,2 +1,2 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/workflow/workflows/PS CoE/Test Workflows/Test Workflow 3.xml b/typescript/vrotsc/e2e/expect/workflow/workflows/PS CoE/Test Workflows/Test Workflow 3.xml index 61e6f9955..cd840c196 100644 --- a/typescript/vrotsc/e2e/expect/workflow/workflows/PS CoE/Test Workflows/Test Workflow 3.xml +++ b/typescript/vrotsc/e2e/expect/workflow/workflows/PS CoE/Test Workflows/Test Workflow 3.xml @@ -1,2 +1,2 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/workflow/workflows/PS CoE/Test Workflows/Test Workflow 4.xml b/typescript/vrotsc/e2e/expect/workflow/workflows/PS CoE/Test Workflows/Test Workflow 4.xml index 54daf5d52..a42563d9e 100644 --- a/typescript/vrotsc/e2e/expect/workflow/workflows/PS CoE/Test Workflows/Test Workflow 4.xml +++ b/typescript/vrotsc/e2e/expect/workflow/workflows/PS CoE/Test Workflows/Test Workflow 4.xml @@ -1,4 +1,4 @@ - \ No newline at end of file +]]> \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/workflow/workflows/PS CoE/Test Workflows/Test Workflow 5.xml b/typescript/vrotsc/e2e/expect/workflow/workflows/PS CoE/Test Workflows/Test Workflow 5.xml index 2c377ac51..450a1ac6c 100644 --- a/typescript/vrotsc/e2e/expect/workflow/workflows/PS CoE/Test Workflows/Test Workflow 5.xml +++ b/typescript/vrotsc/e2e/expect/workflow/workflows/PS CoE/Test Workflows/Test Workflow 5.xml @@ -1,4 +1,4 @@ - \ No newline at end of file +]]> \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/workflow/workflows/PSCoE/vRO TypeScript/TestWorkflow1.xml b/typescript/vrotsc/e2e/expect/workflow/workflows/PSCoE/vRO TypeScript/TestWorkflow1.xml index ec216c6d5..ad1501ced 100644 --- a/typescript/vrotsc/e2e/expect/workflow/workflows/PSCoE/vRO TypeScript/TestWorkflow1.xml +++ b/typescript/vrotsc/e2e/expect/workflow/workflows/PSCoE/vRO TypeScript/TestWorkflow1.xml @@ -1,2 +1,2 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/workflow/workflows/PSCoE/vRO TypeScript/sub/TestWorkflow2.xml b/typescript/vrotsc/e2e/expect/workflow/workflows/PSCoE/vRO TypeScript/sub/TestWorkflow2.xml index 30e5d7c61..21f424db3 100644 --- a/typescript/vrotsc/e2e/expect/workflow/workflows/PSCoE/vRO TypeScript/sub/TestWorkflow2.xml +++ b/typescript/vrotsc/e2e/expect/workflow/workflows/PSCoE/vRO TypeScript/sub/TestWorkflow2.xml @@ -1,2 +1,2 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/workflow/workflows/PSCoE/vRO TypeScript/sub/sub2/TestWorkflow3.xml b/typescript/vrotsc/e2e/expect/workflow/workflows/PSCoE/vRO TypeScript/sub/sub2/TestWorkflow3.xml index fcd75cea4..b4f490ca0 100644 --- a/typescript/vrotsc/e2e/expect/workflow/workflows/PSCoE/vRO TypeScript/sub/sub2/TestWorkflow3.xml +++ b/typescript/vrotsc/e2e/expect/workflow/workflows/PSCoE/vRO TypeScript/sub/sub2/TestWorkflow3.xml @@ -1,3 +1,3 @@ - \ No newline at end of file +]]> \ No newline at end of file From e85f6fcc3aa4b168cb8c1aba6ff311d04a23c66d Mon Sep 17 00:00:00 2001 From: Alexander Kantchev Date: Mon, 29 Jul 2024 15:39:34 +0300 Subject: [PATCH 47/67] [Task 361] code: Added object support in the VROES.Shims.arrayFrom() in order to be compatible with Array.from() Signed-off-by: Alexander Kantchev --- docs/versions/latest/Release.md | 184 ++++++++++++++++++------------- packages/ecmascript/src/Shims.ts | 59 +++++----- 2 files changed, 142 insertions(+), 101 deletions(-) diff --git a/docs/versions/latest/Release.md b/docs/versions/latest/Release.md index 4256e1164..fbe14b8f1 100644 --- a/docs/versions/latest/Release.md +++ b/docs/versions/latest/Release.md @@ -1,34 +1,37 @@ -[//]: # (VERSION_PLACEHOLDER DO NOT DELETE) -[//]: # (Used when working on a new release. Placed together with the Version.md) -[//]: # (Nothing here is optional. If a step must not be performed, it must be said so) -[//]: # (Do not fill the version, it will be done automatically) -[//]: # (Quick Intro to what is the focus of this release) +[//]: # "VERSION_PLACEHOLDER DO NOT DELETE" +[//]: # "Used when working on a new release. Placed together with the Version.md" +[//]: # "Nothing here is optional. If a step must not be performed, it must be said so" +[//]: # "Do not fill the version, it will be done automatically" +[//]: # "Quick Intro to what is the focus of this release" ## Breaking Changes -[//]: # (### *Breaking Change*) -[//]: # (Describe the breaking change AND explain how to resolve it) -[//]: # (You can utilize internal links /e.g. link to the upgrade procedure, link to the improvement|deprecation that introduced this/) +[//]: # "### *Breaking Change*" +[//]: # "Describe the breaking change AND explain how to resolve it" +[//]: # "You can utilize internal links /e.g. link to the upgrade procedure, link to the improvement|deprecation that introduced this/" ## Deprecations -[//]: # (### *Deprecation*) -[//]: # (Explain what is deprecated and suggest alternatives) - -[//]: # (Features -> New Functionality) +[//]: # "### *Deprecation*" +[//]: # "Explain what is deprecated and suggest alternatives" +[//]: # "Features -> New Functionality" ## Features -[//]: # (### *Feature Name*) -[//]: # (Describe the feature) -[//]: # (Optional But higlhy recommended Specify *NONE* if missing) -[//]: # (#### Relevant Documentation:) +[//]: # "### *Feature Name*" +[//]: # "Describe the feature" +[//]: # "Optional But higlhy recommended Specify *NONE* if missing" +[//]: # "#### Relevant Documentation:" + +### Support of Objects in the VROES.Shims.arrayFrom() Method + +Add support for objects in the `VROES.Shims.arrayFrom()` method so its behavior is similar to the standard `Array.from()` method. ### Support python 3.10 runtime Add support for python 3.10 runtime in Orchestrator. This is now the default, since python 3.7 is deprecated. -### *New `@ActionItem` decorator for Workflows* +### _New `@ActionItem` decorator for Workflows_ The new decorator gives you the ability to specify a canvas item that calls an action. @@ -53,23 +56,26 @@ import { Workflow, Out, In, Item, ActionItem } from "vrotsc-annotations"; path: "VMware/PSCoE", attributes: { first: { - type: "number" + type: "number", }, second: { - type: "number" + type: "number", }, actionResult: { - type: "ActionResult" - } - } + type: "ActionResult", + }, + }, }) export class Example { @ActionItem({ target: "printActionResult", - scriptModule: "com.vmware.pscoe.onboarding.sgenov.actions/test" + scriptModule: "com.vmware.pscoe.onboarding.sgenov.actions/test", }) - public callTestAction(@In first: number, @In second: number, @Out actionResult: ActionResult) { - } + public callTestAction( + @In first: number, + @In second: number, + @Out actionResult: ActionResult + ) {} @Item({ target: "end" }) public printActionResult(@In actionResult: ActionResult) { @@ -78,7 +84,7 @@ export class Example { } ``` -### *New `DefaultErrorHandler` decorator for Workflows* +### _New `DefaultErrorHandler` decorator for Workflows_ This decorator is used to specify a default error handler. It can be bound either to a workflow item component or workflow end. @@ -146,7 +152,7 @@ export class HandleDefaultError { } ``` -### *New `@WorkflowEndItem` decorator for Workflows* +### _New `@WorkflowEndItem` decorator for Workflows_ The decorator is used to specify a custom workflow end item. @@ -194,7 +200,7 @@ export class WorkflowEnd { } ``` -### *New `AsyncWorkflowItem` decorator for Workflows* +### _New `AsyncWorkflowItem` decorator for Workflows_ The decorator is used to specify a canvas item that calls an asynchronous workflow. @@ -214,40 +220,51 @@ Special output is needed for the AsyncWorkflowItem. No special inputs are needed for the AsyncWorkflowItem. - #### Example ```typescript -import { Workflow, Out, In, Item, RootItem, AsyncWorkflowItem } from "vrotsc-annotations"; +import { + Workflow, + Out, + In, + Item, + RootItem, + AsyncWorkflowItem, +} from "vrotsc-annotations"; @Workflow({ name: "Async Workflow Test", path: "VMware/PSCoE", - description: "Calling another workflow asynchronously and binding values correctly", + description: + "Calling another workflow asynchronously and binding values correctly", attributes: { waitingTimer: { - type: "Date" + type: "Date", }, counter: { - type: "number" + type: "number", }, first: { - type: "number" + type: "number", }, second: { - type: "number" + type: "number", }, wfToken: { - type: "WorkflowToken" - } - } + type: "WorkflowToken", + }, + }, }) export class HandleNetworkConfigurationBackup { @AsyncWorkflowItem({ target: "printAsync", - linkedItem: "9e4503db-cbaa-435a-9fad-144409c08df0" + linkedItem: "9e4503db-cbaa-435a-9fad-144409c08df0", }) - public asyncCall(@In first: number, @In second: number, @Out wfToken: WorkflowToken) { } + public asyncCall( + @In first: number, + @In second: number, + @Out wfToken: WorkflowToken + ) {} @Item({ target: "callAsyncWf" }) public prepareItems(@In @Out first: number, @In @Out second: number) { @@ -269,7 +286,7 @@ export class HandleNetworkConfigurationBackup { } ``` -### *New `ScheduledWorkflowItem` decorator for Workflows* +### _New `ScheduledWorkflowItem` decorator for Workflows_ The new decorator gives you the ability to specify a canvas item that schedules a Workflow. @@ -294,34 +311,44 @@ Special output is needed for the ScheduledWorkflowItem. #### Example ```ts -import { Workflow, Out, In, Item, RootItem, DecisionItem, WaitingTimerItem, WorkflowItem, ScheduledWorkflowItem } from "vrotsc-annotations"; +import { + Workflow, + Out, + In, + Item, + RootItem, + DecisionItem, + WaitingTimerItem, + WorkflowItem, + ScheduledWorkflowItem, +} from "vrotsc-annotations"; @Workflow({ name: "Example Waiting Timer", path: "VMware/PSCoE", attributes: { waitingTimer: { - type: "Date" + type: "Date", }, counter: { - type: "number" + type: "number", }, first: { - type: "number" + type: "number", }, second: { - type: "number" + type: "number", }, result: { - type: "number" + type: "number", }, workflowScheduleDate: { - type: "Date" + type: "Date", }, scheduledTask: { - type: "Task" - } - } + type: "Task", + }, + }, }) export class HandleNetworkConfigurationBackup { @DecisionItem({ target: "waitForEvent", else: "prepareItems" }) @@ -330,7 +357,11 @@ export class HandleNetworkConfigurationBackup { } @Item({ target: "callOtherWf" }) - public prepareItems(@In @Out first: number, @In @Out second: number, @In @Out workflowScheduleDate: Date) { + public prepareItems( + @In @Out first: number, + @In @Out second: number, + @In @Out workflowScheduleDate: Date + ) { first = 1; second = 2; workflowScheduleDate = System.getDate("1 minute from now", undefined); @@ -338,11 +369,13 @@ export class HandleNetworkConfigurationBackup { @WorkflowItem({ target: "print", - linkedItem: "9e4503db-cbaa-435a-9fad-144409c08df0" + linkedItem: "9e4503db-cbaa-435a-9fad-144409c08df0", }) - public callOtherWf(@In first: number, @In second: number, @Out result: number) { - } - + public callOtherWf( + @In first: number, + @In second: number, + @Out result: number + ) {} @Item({ target: "scheduleOtherWf" }) public print(@In result: number) { @@ -351,10 +384,14 @@ export class HandleNetworkConfigurationBackup { @ScheduledWorkflowItem({ target: "printScheduledDetails", - linkedItem: "9e4503db-cbaa-435a-9fad-144409c08df0" + linkedItem: "9e4503db-cbaa-435a-9fad-144409c08df0", }) - public scheduleOtherWf(@In first: number, @In second: number, @In workflowScheduleDate: Date, @Out scheduledTask: Task) { - } + public scheduleOtherWf( + @In first: number, + @In second: number, + @In workflowScheduleDate: Date, + @Out scheduledTask: Task + ) {} @Item({ target: "end" }) public printScheduledDetails(@In scheduledTask: Task) { @@ -387,12 +424,11 @@ export class HandleNetworkConfigurationBackup { } @WaitingTimerItem({ target: "execute" }) - public waitForEvent(@In waitingTimer: Date) { - } + public waitForEvent(@In waitingTimer: Date) {} } ``` -### *New `WorkflowItem` decorator for Workflows* +### _New `WorkflowItem` decorator for Workflows_ The new Decorator gives you the ability to specify a canvas item that calls a Workflow. @@ -497,18 +533,18 @@ export class HandleNetworkConfigurationBackup { ## Improvements -[//]: # (### *Improvement Name* ) -[//]: # (Talk ONLY regarding the improvement) -[//]: # (Optional But higlhy recommended) -[//]: # (#### Previous Behavior) -[//]: # (Explain how it used to behave, regarding to the change) -[//]: # (Optional But higlhy recommended) -[//]: # (#### New Behavior) -[//]: # (Explain how it behaves now, regarding to the change) -[//]: # (Optional But higlhy recommended Specify *NONE* if missing) -[//]: # (#### Relevant Documentation:) +[//]: # "### *Improvement Name* " +[//]: # "Talk ONLY regarding the improvement" +[//]: # "Optional But higlhy recommended" +[//]: # "#### Previous Behavior" +[//]: # "Explain how it used to behave, regarding to the change" +[//]: # "Optional But higlhy recommended" +[//]: # "#### New Behavior" +[//]: # "Explain how it behaves now, regarding to the change" +[//]: # "Optional But higlhy recommended Specify *NONE* if missing" +[//]: # "#### Relevant Documentation:" -### *ABX archetype build issue, cannot compile* +### _ABX archetype build issue, cannot compile_ Fixed an issue where the ABX archetype could not compile due to an old version of the `xmlbuilder2` package. @@ -552,4 +588,4 @@ The ABX archetype now compiles successfully. ## Upgrade procedure -[//]: # (Explain in details if something needs to be done) +[//]: # "Explain in details if something needs to be done" diff --git a/packages/ecmascript/src/Shims.ts b/packages/ecmascript/src/Shims.ts index ff76df7de..69237def2 100644 --- a/packages/ecmascript/src/Shims.ts +++ b/packages/ecmascript/src/Shims.ts @@ -16,10 +16,10 @@ function getPadString(sourceLength: number, targetLength: number, padString?: st if (sourceLength > targetLength) { return ""; } - if (padString != null) { + if (padString !== null) { padString = "" + padString; } - if (padString == null || !padString.length) { + if (padString !== null || !padString.length) { padString = " "; } let pad = ""; @@ -79,7 +79,7 @@ export default class Shims { return str + getPadString(str.length, targetLength, padString); } - static arrayFind = function (array: T[], predicate: (value: T, index: number, obj: T[]) => boolean): T | undefined { + static readonly arrayFind = function (array: T[], predicate: (value: T, index: number, obj: T[]) => boolean): T | undefined { for (let i = 0; i < array.length; i++) { if (predicate(array[i], i, array)) { return array[i]; @@ -87,7 +87,7 @@ export default class Shims { } } - static arrayFindIndex = function (array: T[], predicate: (value: T, index: number, obj: T[]) => boolean): number { + static readonly arrayFindIndex = function (array: T[], predicate: (value: T, index: number, obj: T[]) => boolean): number { for (let i = 0; i < array.length; i++) { if (predicate(array[i], i, array)) { return i; @@ -97,7 +97,7 @@ export default class Shims { return -1; } - static arrayFill = function (array: T[], value: T, start?: number, end?: number): T[] { + static readonly arrayFill = function (array: T[], value: T, start?: number, end?: number): T[] { if (end < 0) { end = array.length + end * -1; } @@ -109,12 +109,12 @@ export default class Shims { return array; } - static arrayFrom(arrayLike: ArrayLike | Iterable, mapfn?: (v: any, k: number) => any): any[] { - let array: Array; + static arrayFrom(arrayLike: ArrayLike | Iterable, mapFunction?: (v: any, k: number) => any): any[] { let arrayLikeClone = JSON.parse(JSON.stringify(arrayLike)); switch (arrayLike.constructor.name) { - case "Array": break; + case "Array": + break; case "String": arrayLikeClone = (arrayLikeClone as string).split(""); break; @@ -124,30 +124,32 @@ export default class Shims { case "Map": arrayLikeClone = (arrayLike as Map).entries(); break; - default: return arrayLikeClone; - } - - if (mapfn) { - array = arrayLikeClone.map(mapfn); - } else { - array = arrayLikeClone; + case "Object": + arrayLikeClone = []; + // check whether the object is an array (using the length property) + if (Object.keys(arrayLike).find(item => item.indexOf('length') >= 0)) { + arrayLikeClone = Array.apply(null, Array(arrayLike));// nosonar + } + break; + default: + return arrayLikeClone; } - return array; + return mapFunction ? arrayLikeClone.map(mapFunction) : arrayLikeClone; } static arrayOf(): any[] { return Array.prototype.slice.call(arguments); } - static objectAssign(target): any { + static objectAssign(target: any): any { if (target === null || target === undefined) { throw new TypeError("Cannot convert undefined or null to object"); } - for (var i = 1, len = arguments.length; i < len; i++) { - var source = arguments[i]; - for (var p in source) { + for (let i = 1, len = arguments.length; i < len; i++) { + let source = arguments[i]; + for (let p in source) { if (Object.prototype.hasOwnProperty.call(source, p)) { target[p] = source[p]; } @@ -160,22 +162,25 @@ export default class Shims { return Object.keys(target).map(key => target[key]); } - static objectSetPrototypeOf(target, prototype): any { - target.__proto__ = prototype; + static objectSetPrototypeOf(target: any, prototype: any): any { + Object.setPrototypeOf(target, prototype); return target; } static spreadArrays() { - var size = 0; - for (var i = 0, len = arguments.length; i < len; i++) { + let size = 0; + let len = arguments.length; + + for (let i = 0; i < len; i++) { size += arguments[i].length; } - var result = Array(size); - for (var k = 0, i = 0; i < len; i++) { - for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) { + let result = Array(size); + for (let k = 0, i = 0; i < len; i++) { + for (let a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) { result[k] = a[j]; } } + return result; } } From fc2a5f8f1c0cd6ef7ab24c20c8b23235e6d2ec8a Mon Sep 17 00:00:00 2001 From: Stefan Genov Date: Mon, 29 Jul 2024 17:31:45 +0300 Subject: [PATCH 48/67] test: Fix tests in cases where the item is not linked to anything Signed-off-by: Stefan Genov --- .../cases/canvas-items/async-workflow.wf.ts | 2 +- .../e2e/cases/canvas-items/complex.wf.ts | 3 +- .../cases/canvas-items/decision-edge.wf.ts | 4 +++ .../default-error-handler-custom-item.wf.ts | 7 +++++ .../canvas-items/end-item-exception.wf.ts | 11 ++++---- .../cases/canvas-items/end-item-happy.wf.ts | 8 ++++-- .../canvas-items/root-default-first.wf.ts | 6 ++-- .../cases/canvas-items/root-when-set.wf.ts | 5 +++- .../canvas-items/waiting-timer-edge-2.wf.ts | 4 +-- .../canvas-items/waiting-timer-edge.wf.ts | 28 ------------------- .../VMware/PSCoE/Async Workflow Test.xml | 6 ++-- .../workflows/VMware/PSCoE/Complex.xml | 2 +- .../workflows/VMware/PSCoE/Decision Edge.xml | 2 +- .../Default Error Handler Custom Item.xml | 6 ++-- .../VMware/PSCoE/Root Default First.xml | 2 +- .../workflows/VMware/PSCoE/Root When Set.xml | 2 +- .../Waitin Timer Edge 2.element_info.xml | 9 ------ .../VMware/PSCoE/Waitin Timer Edge 2.xml | 1 - ...xml => Waitin Timer Edge.element_info.xml} | 4 +-- .../VMware/PSCoE/Waitin Timer Edge.xml | 1 + .../VMware/PSCoE/Waiting Timer Edge.xml | 1 - .../VMware/PSCoE/Workflow End Exception.xml | 2 +- .../VMware/PSCoE/Workflow End Happy.xml | 2 +- .../workflow/decorators/helpers/graph.ts | 21 ++++++++++++++ .../fileTransformers/workflow/presentation.ts | 16 +++++++---- 25 files changed, 81 insertions(+), 74 deletions(-) delete mode 100644 typescript/vrotsc/e2e/cases/canvas-items/waiting-timer-edge.wf.ts delete mode 100644 typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waitin Timer Edge 2.element_info.xml delete mode 100644 typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waitin Timer Edge 2.xml rename typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/{Waiting Timer Edge.element_info.xml => Waitin Timer Edge.element_info.xml} (72%) create mode 100644 typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waitin Timer Edge.xml delete mode 100644 typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waiting Timer Edge.xml diff --git a/typescript/vrotsc/e2e/cases/canvas-items/async-workflow.wf.ts b/typescript/vrotsc/e2e/cases/canvas-items/async-workflow.wf.ts index cd092e8ab..2f67d01a8 100644 --- a/typescript/vrotsc/e2e/cases/canvas-items/async-workflow.wf.ts +++ b/typescript/vrotsc/e2e/cases/canvas-items/async-workflow.wf.ts @@ -29,7 +29,7 @@ export class HandleNetworkConfigurationBackup { }) public asyncCall(@In first: number, @In second: number, @Out wfToken: WorkflowToken) { } - @Item({ target: "callAsyncWf" }) + @Item({ target: "asyncCall" }) public prepareItems(@In @Out first: number, @In @Out second: number) { first = 1; second = 2; diff --git a/typescript/vrotsc/e2e/cases/canvas-items/complex.wf.ts b/typescript/vrotsc/e2e/cases/canvas-items/complex.wf.ts index a8a33e33e..ed10ce21a 100644 --- a/typescript/vrotsc/e2e/cases/canvas-items/complex.wf.ts +++ b/typescript/vrotsc/e2e/cases/canvas-items/complex.wf.ts @@ -13,10 +13,9 @@ import { Workflow, Out, In, Item, RootItem, DecisionItem, WaitingTimerItem } fro } }) export class Complex { - @DecisionItem({ target: "waitForEvent", - else: null + else: "end" }) public decisionElement(waitingTimer: Date) { return waitingTimer !== null; diff --git a/typescript/vrotsc/e2e/cases/canvas-items/decision-edge.wf.ts b/typescript/vrotsc/e2e/cases/canvas-items/decision-edge.wf.ts index 3b728a8ec..ff79ab43b 100644 --- a/typescript/vrotsc/e2e/cases/canvas-items/decision-edge.wf.ts +++ b/typescript/vrotsc/e2e/cases/canvas-items/decision-edge.wf.ts @@ -19,6 +19,10 @@ export class HandleNetworkConfigurationBackup { return waitingTimer !== null; } + public waitForEvent() { + // NOOP + } + public shouldGoHere() { // NOOP } diff --git a/typescript/vrotsc/e2e/cases/canvas-items/default-error-handler-custom-item.wf.ts b/typescript/vrotsc/e2e/cases/canvas-items/default-error-handler-custom-item.wf.ts index cc2c5acbc..1051d8ac6 100644 --- a/typescript/vrotsc/e2e/cases/canvas-items/default-error-handler-custom-item.wf.ts +++ b/typescript/vrotsc/e2e/cases/canvas-items/default-error-handler-custom-item.wf.ts @@ -17,6 +17,13 @@ export class HandleDefaultError { System.log("Initiating workflow execution"); } + @Item({ + target: "end" + }) + public goToEnd() { + // NOOP + } + @Item({ target: "workflowEnd" }) diff --git a/typescript/vrotsc/e2e/cases/canvas-items/end-item-exception.wf.ts b/typescript/vrotsc/e2e/cases/canvas-items/end-item-exception.wf.ts index d03ab535f..6a23b5981 100644 --- a/typescript/vrotsc/e2e/cases/canvas-items/end-item-exception.wf.ts +++ b/typescript/vrotsc/e2e/cases/canvas-items/end-item-exception.wf.ts @@ -1,4 +1,4 @@ -import { Workflow, RootItem, WorkflowEndItem } from "vrotsc-annotations"; +import { Workflow, RootItem, DecisionItem, WorkflowEndItem } from "vrotsc-annotations"; @Workflow({ name: "Workflow End Exception", @@ -11,16 +11,17 @@ import { Workflow, RootItem, WorkflowEndItem } from "vrotsc-annotations"; businessStatus: { type: "string" }, - endMode: { - type: "number" - } } }) export class WorkflowEnd { @RootItem() + @DecisionItem({ + target: "end", + else: "workflowEnd" + }) public initiateWorkflow() { - // NOOP + return true; } @WorkflowEndItem({ diff --git a/typescript/vrotsc/e2e/cases/canvas-items/end-item-happy.wf.ts b/typescript/vrotsc/e2e/cases/canvas-items/end-item-happy.wf.ts index 42bb8e811..106246da4 100644 --- a/typescript/vrotsc/e2e/cases/canvas-items/end-item-happy.wf.ts +++ b/typescript/vrotsc/e2e/cases/canvas-items/end-item-happy.wf.ts @@ -1,4 +1,4 @@ -import { Workflow, RootItem, WorkflowEndItem } from "vrotsc-annotations"; +import { Workflow, RootItem, DecisionItem, WorkflowEndItem } from "vrotsc-annotations"; @Workflow({ name: "Workflow End Happy", @@ -13,8 +13,12 @@ import { Workflow, RootItem, WorkflowEndItem } from "vrotsc-annotations"; export class WorkflowEnd { @RootItem() + @DecisionItem({ + target: "end", + else: "workflowEnd" + }) public initiateWorkflow() { - // NOOP + return true; } @WorkflowEndItem({ diff --git a/typescript/vrotsc/e2e/cases/canvas-items/root-default-first.wf.ts b/typescript/vrotsc/e2e/cases/canvas-items/root-default-first.wf.ts index a5c81dfb0..63b0cf8c7 100644 --- a/typescript/vrotsc/e2e/cases/canvas-items/root-default-first.wf.ts +++ b/typescript/vrotsc/e2e/cases/canvas-items/root-default-first.wf.ts @@ -3,7 +3,7 @@ import { Workflow, In, Item } from "vrotsc-annotations"; @Workflow({ name: "Root Default First", path: "VMware/PSCoE", - description: "default is first item, points to end", + description: "default is first item", attributes: { waitingTimer: { type: "Date" @@ -16,13 +16,13 @@ import { Workflow, In, Item } from "vrotsc-annotations"; export class Complex { @Item({ - target: "end" + target: "shouldGoHere" }) public waitForEvent(@In waitingTimer: Date) { // NOOP } - public shouldNotGoHere() { + public shouldGoHere() { // NOOP } } diff --git a/typescript/vrotsc/e2e/cases/canvas-items/root-when-set.wf.ts b/typescript/vrotsc/e2e/cases/canvas-items/root-when-set.wf.ts index 2f323f2ff..ac0a61f02 100644 --- a/typescript/vrotsc/e2e/cases/canvas-items/root-when-set.wf.ts +++ b/typescript/vrotsc/e2e/cases/canvas-items/root-when-set.wf.ts @@ -3,7 +3,7 @@ import { Workflow, In, Item, RootItem } from "vrotsc-annotations"; @Workflow({ name: "Root When Set", path: "VMware/PSCoE", - description: "root is shouldGoHere, points to end", + description: "root is shouldGoHere", attributes: { waitingTimer: { type: "Date" @@ -23,6 +23,9 @@ export class Complex { } @RootItem() + @Item({ + target: "waitForEvent" + }) public shouldGoHere() { // NOOP } diff --git a/typescript/vrotsc/e2e/cases/canvas-items/waiting-timer-edge-2.wf.ts b/typescript/vrotsc/e2e/cases/canvas-items/waiting-timer-edge-2.wf.ts index e8b2dfaff..9046e91ee 100644 --- a/typescript/vrotsc/e2e/cases/canvas-items/waiting-timer-edge-2.wf.ts +++ b/typescript/vrotsc/e2e/cases/canvas-items/waiting-timer-edge-2.wf.ts @@ -1,7 +1,7 @@ import { Workflow, In, WaitingTimerItem } from "vrotsc-annotations"; @Workflow({ - name: "Waitin Timer Edge 2", + name: "Waitin Timer Edge", path: "VMware/PSCoE", description: "Waiting timer will point to shouldGoHere with target", attributes: { @@ -20,7 +20,7 @@ export class Complex { // NOOP } - public shouldGoHere() { + public shouldGoHere() { // NOOP } } diff --git a/typescript/vrotsc/e2e/cases/canvas-items/waiting-timer-edge.wf.ts b/typescript/vrotsc/e2e/cases/canvas-items/waiting-timer-edge.wf.ts deleted file mode 100644 index 936eede2e..000000000 --- a/typescript/vrotsc/e2e/cases/canvas-items/waiting-timer-edge.wf.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { Workflow, In, WaitingTimerItem } from "vrotsc-annotations"; - -@Workflow({ - name: "Waiting Timer Edge", - path: "VMware/PSCoE", - description: "Waiting timer will point to end with target", - attributes: { - waitingTimer: { - type: "Date" - }, - counter: { - type: "number" - } - } -}) -export class Complex { - - @WaitingTimerItem({ - target: "shouldGoHere", - }) - public waitForEvent(@In waitingTimer: Date) { - // NOOP - } - - public shouldNotGoHere() { - // NOOP - } -} diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Async Workflow Test.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Async Workflow Test.xml index 9c0381dd1..4de581f21 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Async Workflow Test.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Async Workflow Test.xml @@ -1,13 +1,13 @@ - \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Complex.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Complex.xml index 3475b0600..8a2b90382 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Complex.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Complex.xml @@ -1,4 +1,4 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Default Error Handler Custom Item.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Default Error Handler Custom Item.xml index 52731ebde..6cfddfae2 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Default Error Handler Custom Item.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Default Error Handler Custom Item.xml @@ -1,3 +1,3 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Root Default First.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Root Default First.xml index b77b45811..131e9f522 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Root Default First.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Root Default First.xml @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Root When Set.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Root When Set.xml index 88d6869c8..f538d2b25 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Root When Set.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Root When Set.xml @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waitin Timer Edge 2.element_info.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waitin Timer Edge 2.element_info.xml deleted file mode 100644 index c54432aed..000000000 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waitin Timer Edge 2.element_info.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - -Generated by vrotsc -VMware.PSCoE -Waitin Timer Edge 2 -Workflow -193a306a-a95c-3569-a8ec-b3b60455f326 - diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waitin Timer Edge 2.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waitin Timer Edge 2.xml deleted file mode 100644 index 42f83d5fc..000000000 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waitin Timer Edge 2.xml +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waiting Timer Edge.element_info.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waitin Timer Edge.element_info.xml similarity index 72% rename from typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waiting Timer Edge.element_info.xml rename to typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waitin Timer Edge.element_info.xml index 2ed18038c..eb675b98f 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waiting Timer Edge.element_info.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waitin Timer Edge.element_info.xml @@ -3,7 +3,7 @@ Generated by vrotsc VMware.PSCoE -Waiting Timer Edge +Waitin Timer Edge Workflow -983d90ae-55f4-3618-b049-264e66324e74 +03f7e907-57ee-3195-b5a5-140f3b73e8a5 diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waitin Timer Edge.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waitin Timer Edge.xml new file mode 100644 index 000000000..b574d2dc6 --- /dev/null +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waitin Timer Edge.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waiting Timer Edge.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waiting Timer Edge.xml deleted file mode 100644 index f0092d4b5..000000000 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waiting Timer Edge.xml +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Exception.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Exception.xml index a9e620030..7bbf5a99d 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Exception.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Exception.xml @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Happy.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Happy.xml index 878dfec99..c85d24494 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Happy.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Happy.xml @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/helpers/graph.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/helpers/graph.ts index 8a959c4a9..8de76ff19 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/helpers/graph.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/helpers/graph.ts @@ -307,6 +307,27 @@ export class Graph { } this.calculated = true; + + for (const leaf of Object.values(this.tree.leaves)) { + if (this.tree.startNodes.includes(leaf.node.name)) { + continue; + } + + if (leaf.node.x === undefined || leaf.node.y === undefined) { + + console.log( + JSON.stringify( + Object.values(this.tree.leaves).map(l => { + return { node: l.node, leaves: l.leaves.map(le => le.node.name) }; + }), + null, + 2 + ) + ); + + throw new Error(`Node "${leaf.node.name}" has no position, seems like one of the nodes is not connected which would make your wf unusable, check your targets. Above should be a log of all the leaves.`); + } + } } diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/presentation.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/presentation.ts index d975f8614..04614c037 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/presentation.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/presentation.ts @@ -48,7 +48,14 @@ export function printWorkflowXml(workflow: WorkflowDescriptor, context: FileTran stringBuilder.append(``).appendLine(); } - const graph = getGraph(workflow); + let graph: Graph; + + try { + graph = getGraph(workflow); + } catch (e) { + throw new Error(`Error while building graph for workflow "${workflow.name}". Please check the workflow for any missing target items. + Original Error: ${e.message}`); + } stringBuilder.append(``).appendLine(); buildParameters("input", workflow.parameters.filter(p => !p.isAttribute && p.parameterType & WorkflowParameterType.Input)); @@ -272,7 +279,7 @@ function buildOutput(output: string[]): string { * Will insert the default `end` node as well as the others require it but it's not an actual workflow item */ function getGraph(workflow: WorkflowDescriptor) { - + // start node const startNodes = [`item${findItemByName(workflow.items, workflow.rootItem) || "1"}`]; const nodes = workflow.items.map((item, i) => { switch (item.strategy.getCanvasType()) { @@ -285,12 +292,11 @@ function getGraph(workflow: WorkflowDescriptor) { return item.strategy.getGraphNode(item, i + 1); }); + // end node nodes.push({ name: "item0", targets: [] }); const nodeSpacing = 100; const height = 200; const width = LARGEST_INT32; - const graph = new Graph(nodes, startNodes, nodeSpacing, height, width); - - return graph; + return new Graph(nodes, startNodes, nodeSpacing, height, width); } From 426519c0e948a33690bdd73a5db03a14530c3c7c Mon Sep 17 00:00:00 2001 From: Stefan Genov Date: Mon, 29 Jul 2024 17:35:30 +0300 Subject: [PATCH 49/67] docs: Add Release notes Signed-off-by: Stefan Genov --- docs/versions/latest/Release.md | 67 +++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/docs/versions/latest/Release.md b/docs/versions/latest/Release.md index 818b7e9b3..b23f07946 100644 --- a/docs/versions/latest/Release.md +++ b/docs/versions/latest/Release.md @@ -24,6 +24,73 @@ [//]: # (Optional But higlhy recommended Specify *NONE* if missing) [//]: # (#### Relevant Documentation:) +### *Better ordering of the canvas items* + +The canvas items are now ordered based on an tree algorithm. + +Example: + +From input: + +```ts +const nodes = [ + { name: "A", targets: ["B"] }, + { name: "B", targets: ["C"] }, + { name: "C", targets: ["D", "G"] }, + { name: "D", targets: ["E", "F"] }, + { name: "E", targets: ["C"] }, + { name: "F", targets: ["O"] }, + { name: "G", targets: ["H"] }, + { name: "H", targets: ["I"] }, + { name: "I", targets: ["J", "K", "L", "M"] }, + { name: "J", targets: [] }, + { name: "K", targets: [] }, + { name: "L", targets: [] }, + { name: "M", targets: [] }, + { name: "O", targets: ["P"] }, + { name: "P", targets: ["Q"] }, + { name: "Q", targets: [] }, + + // Second start? + { name: "S", targets: ["T"] }, + { name: "T", targets: ["U", "W", "D"] }, + { name: "U", targets: [] }, + { name: "W", targets: [] }, + { name: "X", targets: ["Y"] }, + { name: "Y", targets: [] }, +]; +``` + +We get: +``` +.................................................................................................... +.................................................................................................... +.................................................................................................... +..............................F....O....P....Q...................................................... +.................................................................................................... +.................................................................................................... +....................D....E.......................................................................... +.................................................................................................... +.....A....B....C...................J................................................................ +.................................................................................................... +.................................................................................................... +....................G....H....I..................................................................... +.................................................................................................... +.....S....T....U...................K................................................................ +.................................................................................................... +.................................................................................................... +.................................................................................................... +.................................................................................................... +...............W...................L................................................................ +.................................................................................................... +.................................................................................................... +.................................................................................................... +.................................................................................................... +...................................M................................................................ +.................................................................................................... +.................................................................................................... +``` + ### *New `@ActionItem` decorator for Workflows* The new decorator gives you the ability to specify a canvas item that calls an action. From c30323ca0f078e98c347bd2106db4419032ac1e4 Mon Sep 17 00:00:00 2001 From: Stefan Genov Date: Mon, 29 Jul 2024 17:43:30 +0300 Subject: [PATCH 50/67] style: Lint issues (tabs > spaces) Signed-off-by: Stefan Genov --- docs/versions/latest/Release.md | 48 ++++++++++++++++----------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/docs/versions/latest/Release.md b/docs/versions/latest/Release.md index b23f07946..488ec4e1b 100644 --- a/docs/versions/latest/Release.md +++ b/docs/versions/latest/Release.md @@ -34,30 +34,30 @@ From input: ```ts const nodes = [ - { name: "A", targets: ["B"] }, - { name: "B", targets: ["C"] }, - { name: "C", targets: ["D", "G"] }, - { name: "D", targets: ["E", "F"] }, - { name: "E", targets: ["C"] }, - { name: "F", targets: ["O"] }, - { name: "G", targets: ["H"] }, - { name: "H", targets: ["I"] }, - { name: "I", targets: ["J", "K", "L", "M"] }, - { name: "J", targets: [] }, - { name: "K", targets: [] }, - { name: "L", targets: [] }, - { name: "M", targets: [] }, - { name: "O", targets: ["P"] }, - { name: "P", targets: ["Q"] }, - { name: "Q", targets: [] }, - - // Second start? - { name: "S", targets: ["T"] }, - { name: "T", targets: ["U", "W", "D"] }, - { name: "U", targets: [] }, - { name: "W", targets: [] }, - { name: "X", targets: ["Y"] }, - { name: "Y", targets: [] }, + { name: "A", targets: ["B"] }, + { name: "B", targets: ["C"] }, + { name: "C", targets: ["D", "G"] }, + { name: "D", targets: ["E", "F"] }, + { name: "E", targets: ["C"] }, + { name: "F", targets: ["O"] }, + { name: "G", targets: ["H"] }, + { name: "H", targets: ["I"] }, + { name: "I", targets: ["J", "K", "L", "M"] }, + { name: "J", targets: [] }, + { name: "K", targets: [] }, + { name: "L", targets: [] }, + { name: "M", targets: [] }, + { name: "O", targets: ["P"] }, + { name: "P", targets: ["Q"] }, + { name: "Q", targets: [] }, + + // Second start? + { name: "S", targets: ["T"] }, + { name: "T", targets: ["U", "W", "D"] }, + { name: "U", targets: [] }, + { name: "W", targets: [] }, + { name: "X", targets: ["Y"] }, + { name: "Y", targets: [] }, ]; ``` From 681715f2656e7bf01c850965c4ef8a24dfe90518 Mon Sep 17 00:00:00 2001 From: Stefan Genov Date: Mon, 29 Jul 2024 17:52:53 +0300 Subject: [PATCH 51/67] style: Linting changes Signed-off-by: Stefan Genov --- docs/versions/latest/Release.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/versions/latest/Release.md b/docs/versions/latest/Release.md index 488ec4e1b..1c1f51306 100644 --- a/docs/versions/latest/Release.md +++ b/docs/versions/latest/Release.md @@ -61,8 +61,8 @@ const nodes = [ ]; ``` -We get: -``` +We get: +```log .................................................................................................... .................................................................................................... .................................................................................................... From 3f464d7ba003edf6663c42eada493b414bdedd01 Mon Sep 17 00:00:00 2001 From: Stefan Genov Date: Tue, 30 Jul 2024 10:25:41 +0300 Subject: [PATCH 52/67] test: fix typo Signed-off-by: Stefan Genov --- .../vrotsc/e2e/cases/canvas-items/waiting-timer-edge-2.wf.ts | 2 +- .../canvas-items/workflows/VMware/PSCoE/Waitin Timer Edge.xml | 1 - ...dge.element_info.xml => Waiting Timer Edge.element_info.xml} | 2 +- .../canvas-items/workflows/VMware/PSCoE/Waiting Timer Edge.xml | 1 + 4 files changed, 3 insertions(+), 3 deletions(-) delete mode 100644 typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waitin Timer Edge.xml rename typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/{Waitin Timer Edge.element_info.xml => Waiting Timer Edge.element_info.xml} (88%) create mode 100644 typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waiting Timer Edge.xml diff --git a/typescript/vrotsc/e2e/cases/canvas-items/waiting-timer-edge-2.wf.ts b/typescript/vrotsc/e2e/cases/canvas-items/waiting-timer-edge-2.wf.ts index 9046e91ee..93cfad48b 100644 --- a/typescript/vrotsc/e2e/cases/canvas-items/waiting-timer-edge-2.wf.ts +++ b/typescript/vrotsc/e2e/cases/canvas-items/waiting-timer-edge-2.wf.ts @@ -1,7 +1,7 @@ import { Workflow, In, WaitingTimerItem } from "vrotsc-annotations"; @Workflow({ - name: "Waitin Timer Edge", + name: "Waiting Timer Edge", path: "VMware/PSCoE", description: "Waiting timer will point to shouldGoHere with target", attributes: { diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waitin Timer Edge.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waitin Timer Edge.xml deleted file mode 100644 index b574d2dc6..000000000 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waitin Timer Edge.xml +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waitin Timer Edge.element_info.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waiting Timer Edge.element_info.xml similarity index 88% rename from typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waitin Timer Edge.element_info.xml rename to typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waiting Timer Edge.element_info.xml index eb675b98f..3d2cccdc1 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waitin Timer Edge.element_info.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waiting Timer Edge.element_info.xml @@ -3,7 +3,7 @@ Generated by vrotsc VMware.PSCoE -Waitin Timer Edge +Waiting Timer Edge Workflow 03f7e907-57ee-3195-b5a5-140f3b73e8a5 diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waiting Timer Edge.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waiting Timer Edge.xml new file mode 100644 index 000000000..2fa5c0ccc --- /dev/null +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waiting Timer Edge.xml @@ -0,0 +1 @@ + From ba43b8326fe59c2682049dc45cc366a7fddf72aa Mon Sep 17 00:00:00 2001 From: Leonid Belenkiy Date: Fri, 19 Jul 2024 11:09:16 +0200 Subject: [PATCH 53/67] Fixing issue #347 Signed-off-by: Leonid Belenkiy --- docs/versions/latest/Release.md | 131 +++++--- vro-types/o11n-plugin-aria/index.d.ts | 427 +++++++++++++++++++++++++- 2 files changed, 509 insertions(+), 49 deletions(-) diff --git a/docs/versions/latest/Release.md b/docs/versions/latest/Release.md index bc2f9cb59..79ae1dad1 100644 --- a/docs/versions/latest/Release.md +++ b/docs/versions/latest/Release.md @@ -1,32 +1,30 @@ -[//]: # (VERSION_PLACEHOLDER DO NOT DELETE) -[//]: # (Used when working on a new release. Placed together with the Version.md) -[//]: # (Nothing here is optional. If a step must not be performed, it must be said so) -[//]: # (Do not fill the version, it will be done automatically) -[//]: # (Quick Intro to what is the focus of this release) +[//]: # "VERSION_PLACEHOLDER DO NOT DELETE" +[//]: # "Used when working on a new release. Placed together with the Version.md" +[//]: # "Nothing here is optional. If a step must not be performed, it must be said so" +[//]: # "Do not fill the version, it will be done automatically" +[//]: # "Quick Intro to what is the focus of this release" ## Breaking Changes -[//]: # (### *Breaking Change*) -[//]: # (Describe the breaking change AND explain how to resolve it) -[//]: # (You can utilize internal links /e.g. link to the upgrade procedure, link to the improvement|deprecation that introduced this/) +[//]: # "### *Breaking Change*" +[//]: # "Describe the breaking change AND explain how to resolve it" +[//]: # "You can utilize internal links /e.g. link to the upgrade procedure, link to the improvement|deprecation that introduced this/" ## Deprecations -[//]: # (### *Deprecation*) -[//]: # (Explain what is deprecated and suggest alternatives) - -[//]: # (Features -> New Functionality) +[//]: # "### *Deprecation*" +[//]: # "Explain what is deprecated and suggest alternatives" +[//]: # "Features -> New Functionality" ## Features -[//]: # (### *Feature Name*) -[//]: # (Describe the feature) -[//]: # (Optional But higlhy recommended Specify *NONE* if missing) -[//]: # (#### Relevant Documentation:) - -[//]: # (Improvements -> Bugfixes/hotfixes or general improvements) +[//]: # "### *Feature Name*" +[//]: # "Describe the feature" +[//]: # "Optional But higlhy recommended Specify *NONE* if missing" +[//]: # "#### Relevant Documentation:" +[//]: # "Improvements -> Bugfixes/hotfixes or general improvements" -### *New `WorkflowItem` decorator for Workflows +### \*New `WorkflowItem` decorator for Workflows The new Decorator gives you the ability to specify a canvas item that calls a Workflow. @@ -39,28 +37,37 @@ In order to bind inputs and outputs, you do it with the `@In` and `@Out` decorat Example: ```typescript -import { Workflow, Out, In, Item, RootItem, DecisionItem, WaitingTimerItem, WorkflowItem } from "vrotsc-annotations"; +import { + Workflow, + Out, + In, + Item, + RootItem, + DecisionItem, + WaitingTimerItem, + WorkflowItem, +} from "vrotsc-annotations"; @Workflow({ name: "Example Waiting Timer", path: "VMware/PSCoE", attributes: { waitingTimer: { - type: "Date" + type: "Date", }, counter: { - type: "number" + type: "number", }, first: { - type: "number" + type: "number", }, second: { - type: "number" + type: "number", }, result: { - type: "number" - } - } + type: "number", + }, + }, }) export class HandleNetworkConfigurationBackup { @DecisionItem({ target: "waitForEvent", else: "prepareItems" }) @@ -76,10 +83,13 @@ export class HandleNetworkConfigurationBackup { @WorkflowItem({ target: "print", - linkedItem: "9e4503db-cbaa-435a-9fad-144409c08df0" + linkedItem: "9e4503db-cbaa-435a-9fad-144409c08df0", }) - public callOtherWf(@In first: number, @In second: number, @Out result: number) { - } + public callOtherWf( + @In first: number, + @In second: number, + @Out result: number + ) {} @Item({ target: "end" }) public print(@In result: number) { @@ -112,25 +122,24 @@ export class HandleNetworkConfigurationBackup { } @WaitingTimerItem({ target: "execute" }) - public waitForEvent(@In waitingTimer: Date) { - } + public waitForEvent(@In waitingTimer: Date) {} } ``` ## Improvements -[//]: # (### *Improvement Name* ) -[//]: # (Talk ONLY regarding the improvement) -[//]: # (Optional But higlhy recommended) -[//]: # (#### Previous Behavior) -[//]: # (Explain how it used to behave, regarding to the change) -[//]: # (Optional But higlhy recommended) -[//]: # (#### New Behavior) -[//]: # (Explain how it behaves now, regarding to the change) -[//]: # (Optional But higlhy recommended Specify *NONE* if missing) -[//]: # (#### Relevant Documentation:) +[//]: # "### *Improvement Name* " +[//]: # "Talk ONLY regarding the improvement" +[//]: # "Optional But higlhy recommended" +[//]: # "#### Previous Behavior" +[//]: # "Explain how it used to behave, regarding to the change" +[//]: # "Optional But higlhy recommended" +[//]: # "#### New Behavior" +[//]: # "Explain how it behaves now, regarding to the change" +[//]: # "Optional But higlhy recommended Specify *NONE* if missing" +[//]: # "#### Relevant Documentation:" -### *ABX archetype build issue, cannot compile* +### _ABX archetype build issue, cannot compile_ Fixed an issue where the ABX archetype could not compile due to an old version of the `xmlbuilder2` package. @@ -172,6 +181,40 @@ org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit The ABX archetype now compiles successfully. +### Add missing classes to `o11n-plugin-aria` and add missing methods to the existing classes + +#### Previous Behavior + +Many classes are missing completely compared with vRO API and some existing classes were missing some methods + +#### Current Behavior + +The following classes were added to `o11n-plugin-aria`: + +- VraInfrastructureClient +- VraCloudAccountService +- VraUpdateCloudAccountVsphereSpecification +- VraCloudAccountVsphereSpecification +- VraRegionSpecification +- VraCloudAccountVsphere +- VraCloudZoneService +- VraZone +- VraHref +- VraZoneSpecification +- VraTag +- VraDataCollectorService +- VraRequestService +- VraRequestTracker + +The following missing methods were added to the exist classes: + +- Class `VraHost` + - `destroy` + +#### Related issue + + + ## Upgrade procedure -[//]: # (Explain in details if something needs to be done) +[//]: # "Explain in details if something needs to be done" diff --git a/vro-types/o11n-plugin-aria/index.d.ts b/vro-types/o11n-plugin-aria/index.d.ts index d87576700..6a7c6d185 100644 --- a/vro-types/o11n-plugin-aria/index.d.ts +++ b/vro-types/o11n-plugin-aria/index.d.ts @@ -10,16 +10,430 @@ declare class VraHost { readonly sessionMode: string; readonly connectionType: string; readonly user: string; + constructor(); + /** + * Automation Host No Argument Constructor. + */ + constructor(); + + createInfrastructureClient(): VraInfrastructureClient; + /** * Validates the Host Connection. */ validate(): boolean; + /** + * Destroys the connection object + */ + destroy(): void; + /** * Creates a generic REST client for Automation Host */ createRestClient(): VraGenericRestClient; +} + +declare class VraInfrastructureClient { + constructor(); + /** + * @param genericRestClient + */ + constructor(genericRestClient: VraGenericRestClient); + + /** + * Create Data Collector service to invoke APIs. + */ + createDataCollectorService(): VraDataCollectorService; + + /** + * Create a Request service to invoke APIs. + */ + createRequestService(): VraRequestService; + + /** + * Create Cloud Zone service to invoke APIs. + */ + createCloudZoneService(): VraCloudZoneService; + + /** + * Create a Cloud Account service to invoke APIs. + */ + createCloudAccountService(): VraCloudAccountService; +} + +declare class VraCloudAccountService { + constructor(); + constructor(); + + /** + * @param genericRestClient + */ + setGenericRestClient(genericRestClient: VraGenericRestClient): void; + + /** + * Delete a vSphere Cloud Account with a given id + * @param cloudAccountVsphereId + */ + deleteVSphereCloudAccountById(cloudAccountVsphereId): void; + + /** + * Delete a vSphere Cloud Account with a given cloudAccountVsphere object + * @param cloudAccountVsphere + */ + deleteVSphereCloudAccount( + cloudAccountVsphere: VraCloudAccountVsphere + ): void; + + /** + * Create a vSphere cloud account + * @param body + */ + createVSphereCloudAccount( + body: VraCloudAccountVsphereSpecification + ): VraCloudAccountVsphere; + + /** + * Create a vSphere cloud account in an asynchronous manner + * @param body + */ + createVSphereCloudAccountAsync( + body: VraCloudAccountVsphereSpecification + ): VraRequestTracker; + + /** + * Update vSphere cloud account in an asynchronous manner + * @param cloudAccountVsphere + * @param body + */ + updateVSphereCloudAccountAsync( + cloudAccountVsphere: VraCloudAccountVsphere, + body: VraUpdateCloudAccountVsphereSpecification + ): VraRequestTracker; + + /** + * Update vSphere cloud account + * @param cloudAccountVsphere + * @param body + */ + updateVSphereCloudAccount( + cloudAccountVsphere: VraCloudAccountVsphere, + body: VraUpdateCloudAccountVsphereSpecification + ): VraCloudAccountVsphere; +} + +declare class VraUpdateCloudAccountVsphereSpecification { + hostName: string; + acceptSelfSignedCertificate: boolean; + createDefaultZones: boolean; + password: string; + associatedCloudAccountIds: Object[]; + regions: Object[]; + dcid: string; + name: string; + description: string; + username: string; + tags: Object[]; + constructor(); + constructor(); + + /** + * @param associatedCloudAccountIdsItem + */ + addAssociatedCloudAccountIdsItem( + associatedCloudAccountIdsItem: string + ): VraUpdateCloudAccountVsphereSpecification; + + /** + * @param tagsItem + */ + addTagsItem(tagsItem: VraTag): VraUpdateCloudAccountVsphereSpecification; + + /** + * @param regionsItem + */ + addRegionsItem( + regionsItem: VraRegionSpecification + ): VraUpdateCloudAccountVsphereSpecification; +} + +/** + * Specification for a vSphere cloud account.

A cloud account identifies a cloud account type and an account-specific deployment region or data center where the associated cloud account resources are hosted. + */ +declare class VraCloudAccountVsphereSpecification { + hostName: string; + acceptSelfSignedCertificate: boolean; + createDefaultZones: boolean; + password: string; + associatedCloudAccountIds: Object[]; + regions: Object[]; + dcid: string; + name: string; + description: string; + username: string; + tags: Object[]; + constructor(); + constructor(); + + /** + * @param regionsItem + */ + addRegionsItem( + regionsItem: VraRegionSpecification + ): VraCloudAccountVsphereSpecification; + + /** + * @param associatedCloudAccountIdsItem + */ + addAssociatedCloudAccountIdsItem( + associatedCloudAccountIdsItem: string + ): VraCloudAccountVsphereSpecification; + + /** + * @param tagsItem + */ + addTagsItem(tagsItem: VraTag): VraCloudAccountVsphereSpecification; +} + +declare class VraRegionSpecification { + externalRegionId: string; + name: string; + constructor(); + constructor(); +} + +declare class VraCloudAccountVsphere { + owner: string; + hostName: string; + linksExtension: string; + enabledRegionIdsExtension: string; + description: string; + orgId: string; + tags: Object[]; + createdAt: string; + enabledRegions: Object[]; + dcid: string; + readonly internalIdString: string; + name: string; + host: VraHost; + tagsExtension: string; + id: string; + updatedAt: string; + username: string; + customPropertiesExtension: string; + constructor(); + constructor(); + + /** + * @param key + * @param linksItem + */ + putLinksItem(key: string, linksItem: VraHref): VraCloudAccountVsphere; + + /** + * @param key + * @param customPropertiesItem + */ + putCustomPropertiesItem( + key: string, + customPropertiesItem: string + ): VraCloudAccountVsphere; +} + +declare class VraCloudZoneService { + constructor(); + constructor(); + + /** + * @param genericRestClient + */ + setGenericRestClient(genericRestClient: VraGenericRestClient): void; + + deleteZoneById(zoneId: string): void; + + /** + * This method deletes Zone based on given zone. + * @param zone + */ + deleteZone(zone: VraZone): void; + + /** + * This method updates the Zone based on zoneId & ZoneSpecification. + * @param id + * @param body + */ + updateZone(id: string, body: VraZoneSpecification): VraZone; + + /** + * This method creates Zone based on ZoneSpecification details. + * @param body + */ + createZone(body: VraZoneSpecification): VraZone; +} + +declare class VraZone { + owner: string; + linksExtension: string; + externalRegionId: string; + cloudAccountId: string; + description: string; + orgId: string; + tags: Object[]; + createdAt: string; + folder: string; + tagsToMatch: Object[]; + internalIdString: string; + name: string; + host: VraHost; + placementPolicy: string; + tagsExtension: string; + tagsToMatchExtension: string; + id: string; + updatedAt: string; + customPropertiesExtension: string; + constructor(); + constructor(); + + /** + * @param tagsToMatchItem + */ + addTagsToMatchItem(tagsToMatchItem: VraTag): VraZone; + + /** + * @param key + * @param linksItem + */ + putLinksItem(key: string, linksItem: VraHref): VraZone; + + /** + * @param tagsItem + */ + addTagsItem(tagsItem: VraTag): VraZone; + + /** + * @param key + * @param customPropertiesItem + */ + putCustomPropertiesItem(key: string, customPropertiesItem: string): VraZone; +} + +declare class VraHref { + hrefs: Object[]; + href: string; + constructor(); + constructor(); + + /** + * @param hrefsItem + */ + addHrefsItem(hrefsItem: string): VraHref; +} + +/** + * Specification for a zone. + */ +declare class VraZoneSpecification { + folder: string; + computeIds: Object[]; + tagsToMatch: Object[]; + regionId: string; + name: string; + placementPolicy: string; + description: string; + tags: Object[]; + constructor(); + constructor(); + + /** + * @param tagsToMatchItem + */ + addTagsToMatchItem(tagsToMatchItem: VraTag): VraZoneSpecification; + + /** + * @param key + * @param customPropertiesItem + */ + putCustomPropertiesItem( + key: string, + customPropertiesItem: string + ): VraZoneSpecification; + /** + * @param computeIdsItem + */ + addComputeIdsItem(computeIdsItem: string): VraZoneSpecification; + + /** + * @param tagsItem + */ + addTagsItem(tagsItem: VraTag): VraZoneSpecification; +} + +declare class VraTag { + readonly displayName: string; + readonly internalIdString: string; + host: VraHost; + value: string; + key: string; + constructor(); + constructor(); +} + +declare class VraDataCollectorService { + constructor(); + + /** + * @param genericRestClient + */ + setGenericRestClient(genericRestClient: VraGenericRestClient): void; +} + +declare class VraRequestService { + constructor(); + + /** + * @param genericRestClient + */ + setGenericRestClient(genericRestClient: VraGenericRestClient): void; + + /** + * Awaits successfully completed RequestTracker Response. + * @param requestTracker + */ + awaitRequestTrackerResponse( + requestTracker: VraRequestTracker + ): VraRequestTracker; + + /** + * Delete a request tracker object for a given request id. + * @param requestTrackerId + */ + deleteRequestTracker(requestTrackerId: string): void; +} + +declare class VraRequestTracker { + deploymentId: string; + readonly internalIdString: string; + name: string; + host: VraHost; + resources: Object[]; + progress: number; + id: string; + requestTrackerStatus: string; + message: string; + selfLink: string; + constructor(); + + /** + * An object used to track long-running operations. + */ + constructor(); + + /** + * An object used to track long-running operations. + * @param resourcesItem + */ + addResourcesItem(resourcesItem: string): VraRequestTracker; } declare class VraGenericRestClient { @@ -37,8 +451,11 @@ declare class VraGenericRestClient { * @param path * @param requestPayload */ - createRequest(method: string, path: string, requestPayload: string): VraRestRequest; - + createRequest( + method: string, + path: string, + requestPayload: string + ): VraRestRequest; } declare class VraRestRequest { @@ -51,7 +468,7 @@ declare class VraRestRequest { * @param key * @param value */ - setHeader(key: string,value:string): void; + setHeader(key: string, value: string): void; /** * Gets Http Header value for the key from the Http Request. @@ -66,10 +483,10 @@ declare class VraRestResponse { readonly contentLength: number; readonly statusMessage: string; readonly statusCode: number; - + /** * Retrieves the server's response header values per header with specific name. * @param headerName */ getHeaderValues(headerName: string): string; -} \ No newline at end of file +} From f7680f3b6f0d7cffba12130feb89d8550896508b Mon Sep 17 00:00:00 2001 From: Leonid Belenkiy Date: Fri, 19 Jul 2024 17:58:06 +0200 Subject: [PATCH 54/67] Revert Release.md Signed-off-by: Leonid Belenkiy --- docs/versions/latest/Release.md | 97 +++++++++++++++------------------ 1 file changed, 44 insertions(+), 53 deletions(-) diff --git a/docs/versions/latest/Release.md b/docs/versions/latest/Release.md index 79ae1dad1..4cd3bfea7 100644 --- a/docs/versions/latest/Release.md +++ b/docs/versions/latest/Release.md @@ -1,30 +1,32 @@ -[//]: # "VERSION_PLACEHOLDER DO NOT DELETE" -[//]: # "Used when working on a new release. Placed together with the Version.md" -[//]: # "Nothing here is optional. If a step must not be performed, it must be said so" -[//]: # "Do not fill the version, it will be done automatically" -[//]: # "Quick Intro to what is the focus of this release" +[//]: # (VERSION_PLACEHOLDER DO NOT DELETE) +[//]: # (Used when working on a new release. Placed together with the Version.md) +[//]: # (Nothing here is optional. If a step must not be performed, it must be said so) +[//]: # (Do not fill the version, it will be done automatically) +[//]: # (Quick Intro to what is the focus of this release) ## Breaking Changes -[//]: # "### *Breaking Change*" -[//]: # "Describe the breaking change AND explain how to resolve it" -[//]: # "You can utilize internal links /e.g. link to the upgrade procedure, link to the improvement|deprecation that introduced this/" +[//]: # (### *Breaking Change*) +[//]: # (Describe the breaking change AND explain how to resolve it) +[//]: # (You can utilize internal links /e.g. link to the upgrade procedure, link to the improvement|deprecation that introduced this/) ## Deprecations -[//]: # "### *Deprecation*" -[//]: # "Explain what is deprecated and suggest alternatives" -[//]: # "Features -> New Functionality" +[//]: # (### *Deprecation*) +[//]: # (Explain what is deprecated and suggest alternatives) + +[//]: # (Features -> New Functionality) ## Features -[//]: # "### *Feature Name*" -[//]: # "Describe the feature" -[//]: # "Optional But higlhy recommended Specify *NONE* if missing" -[//]: # "#### Relevant Documentation:" -[//]: # "Improvements -> Bugfixes/hotfixes or general improvements" +[//]: # (### *Feature Name*) +[//]: # (Describe the feature) +[//]: # (Optional But higlhy recommended Specify *NONE* if missing) +[//]: # (#### Relevant Documentation:) + +[//]: # (Improvements -> Bugfixes/hotfixes or general improvements) -### \*New `WorkflowItem` decorator for Workflows +### *New `WorkflowItem` decorator for Workflows The new Decorator gives you the ability to specify a canvas item that calls a Workflow. @@ -37,37 +39,28 @@ In order to bind inputs and outputs, you do it with the `@In` and `@Out` decorat Example: ```typescript -import { - Workflow, - Out, - In, - Item, - RootItem, - DecisionItem, - WaitingTimerItem, - WorkflowItem, -} from "vrotsc-annotations"; +import { Workflow, Out, In, Item, RootItem, DecisionItem, WaitingTimerItem, WorkflowItem } from "vrotsc-annotations"; @Workflow({ name: "Example Waiting Timer", path: "VMware/PSCoE", attributes: { waitingTimer: { - type: "Date", + type: "Date" }, counter: { - type: "number", + type: "number" }, first: { - type: "number", + type: "number" }, second: { - type: "number", + type: "number" }, result: { - type: "number", - }, - }, + type: "number" + } + } }) export class HandleNetworkConfigurationBackup { @DecisionItem({ target: "waitForEvent", else: "prepareItems" }) @@ -83,13 +76,10 @@ export class HandleNetworkConfigurationBackup { @WorkflowItem({ target: "print", - linkedItem: "9e4503db-cbaa-435a-9fad-144409c08df0", + linkedItem: "9e4503db-cbaa-435a-9fad-144409c08df0" }) - public callOtherWf( - @In first: number, - @In second: number, - @Out result: number - ) {} + public callOtherWf(@In first: number, @In second: number, @Out result: number) { + } @Item({ target: "end" }) public print(@In result: number) { @@ -122,24 +112,25 @@ export class HandleNetworkConfigurationBackup { } @WaitingTimerItem({ target: "execute" }) - public waitForEvent(@In waitingTimer: Date) {} + public waitForEvent(@In waitingTimer: Date) { + } } ``` ## Improvements -[//]: # "### *Improvement Name* " -[//]: # "Talk ONLY regarding the improvement" -[//]: # "Optional But higlhy recommended" -[//]: # "#### Previous Behavior" -[//]: # "Explain how it used to behave, regarding to the change" -[//]: # "Optional But higlhy recommended" -[//]: # "#### New Behavior" -[//]: # "Explain how it behaves now, regarding to the change" -[//]: # "Optional But higlhy recommended Specify *NONE* if missing" -[//]: # "#### Relevant Documentation:" +[//]: # (### *Improvement Name* ) +[//]: # (Talk ONLY regarding the improvement) +[//]: # (Optional But higlhy recommended) +[//]: # (#### Previous Behavior) +[//]: # (Explain how it used to behave, regarding to the change) +[//]: # (Optional But higlhy recommended) +[//]: # (#### New Behavior) +[//]: # (Explain how it behaves now, regarding to the change) +[//]: # (Optional But higlhy recommended Specify *NONE* if missing) +[//]: # (#### Relevant Documentation:) -### _ABX archetype build issue, cannot compile_ +### *ABX archetype build issue, cannot compile* Fixed an issue where the ABX archetype could not compile due to an old version of the `xmlbuilder2` package. @@ -217,4 +208,4 @@ The following missing methods were added to the exist classes: ## Upgrade procedure -[//]: # "Explain in details if something needs to be done" +[//]: # (Explain in details if something needs to be done) From 879ec1c1cd9ef4ffb8bd6a9ce2a8642a7934e796 Mon Sep 17 00:00:00 2001 From: Leonid Belenkiy Date: Fri, 19 Jul 2024 18:00:36 +0200 Subject: [PATCH 55/67] Remove duplicated constrcutor Signed-off-by: Leonid Belenkiy --- vro-types/o11n-plugin-aria/index.d.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/vro-types/o11n-plugin-aria/index.d.ts b/vro-types/o11n-plugin-aria/index.d.ts index 6a7c6d185..67e66a648 100644 --- a/vro-types/o11n-plugin-aria/index.d.ts +++ b/vro-types/o11n-plugin-aria/index.d.ts @@ -10,7 +10,6 @@ declare class VraHost { readonly sessionMode: string; readonly connectionType: string; readonly user: string; - constructor(); /** * Automation Host No Argument Constructor. */ From 8d7e5ce783541f9880471e4dc00b733b8e0bc7b5 Mon Sep 17 00:00:00 2001 From: Leonid Belenkiy Date: Mon, 29 Jul 2024 15:42:53 +0200 Subject: [PATCH 56/67] fix duplicate constructors bug add missing methods to the `VraGenericRestClient` class: get, put, delete, post, patch Signed-off-by: Leonid Belenkiy --- vro-types/o11n-plugin-aria/index.d.ts | 57 +++++++++++++++++++-------- 1 file changed, 41 insertions(+), 16 deletions(-) diff --git a/vro-types/o11n-plugin-aria/index.d.ts b/vro-types/o11n-plugin-aria/index.d.ts index 67e66a648..86d02ca02 100644 --- a/vro-types/o11n-plugin-aria/index.d.ts +++ b/vro-types/o11n-plugin-aria/index.d.ts @@ -1,5 +1,5 @@ /** - * Specifies the object Type VRA:HOST. + * VMware Aria Automation Host provides access to connection host properties & validation access. */ declare class VraHost { readonly displayName: string; @@ -34,7 +34,6 @@ declare class VraHost { } declare class VraInfrastructureClient { - constructor(); /** * @param genericRestClient */ @@ -63,7 +62,6 @@ declare class VraInfrastructureClient { declare class VraCloudAccountService { constructor(); - constructor(); /** * @param genericRestClient @@ -74,7 +72,7 @@ declare class VraCloudAccountService { * Delete a vSphere Cloud Account with a given id * @param cloudAccountVsphereId */ - deleteVSphereCloudAccountById(cloudAccountVsphereId): void; + deleteVSphereCloudAccountById(cloudAccountVsphereId: string): void; /** * Delete a vSphere Cloud Account with a given cloudAccountVsphere object @@ -134,7 +132,6 @@ declare class VraUpdateCloudAccountVsphereSpecification { username: string; tags: Object[]; constructor(); - constructor(); /** * @param associatedCloudAccountIdsItem @@ -172,7 +169,6 @@ declare class VraCloudAccountVsphereSpecification { username: string; tags: Object[]; constructor(); - constructor(); /** * @param regionsItem @@ -198,7 +194,6 @@ declare class VraRegionSpecification { externalRegionId: string; name: string; constructor(); - constructor(); } declare class VraCloudAccountVsphere { @@ -221,7 +216,6 @@ declare class VraCloudAccountVsphere { username: string; customPropertiesExtension: string; constructor(); - constructor(); /** * @param key @@ -241,7 +235,6 @@ declare class VraCloudAccountVsphere { declare class VraCloudZoneService { constructor(); - constructor(); /** * @param genericRestClient @@ -291,7 +284,6 @@ declare class VraZone { updatedAt: string; customPropertiesExtension: string; constructor(); - constructor(); /** * @param tagsToMatchItem @@ -320,7 +312,6 @@ declare class VraHref { hrefs: Object[]; href: string; constructor(); - constructor(); /** * @param hrefsItem @@ -341,7 +332,6 @@ declare class VraZoneSpecification { description: string; tags: Object[]; constructor(); - constructor(); /** * @param tagsToMatchItem @@ -375,7 +365,6 @@ declare class VraTag { value: string; key: string; constructor(); - constructor(); } declare class VraDataCollectorService { @@ -421,7 +410,6 @@ declare class VraRequestTracker { requestTrackerStatus: string; message: string; selfLink: string; - constructor(); /** * An object used to track long-running operations. @@ -429,14 +417,27 @@ declare class VraRequestTracker { constructor(); /** - * An object used to track long-running operations. * @param resourcesItem */ addResourcesItem(resourcesItem: string): VraRequestTracker; } +/** + * A generic VMware Aria Automation Rest client for executing REST operations + */ declare class VraGenericRestClient { - readonly host: VraHost; + host: VraHost; + + /** + * Automation GenericRestClient No Argument Constructor. + */ + constructor(); + + /** + * Get Method to execute rest operation by setting Request object. Request object can hold information (http method, resource url, request payload) + * @param request + */ + get(request: VraRestRequest): VraRestResponse; /** * Method to execute rest operation by setting Request object. Request object can hold information (http method, resource url, request payload) @@ -444,6 +445,24 @@ declare class VraGenericRestClient { */ execute(restRequest: VraRestRequest): VraRestResponse; + /** + * Put Method to execute rest operation by setting Request object. Request object can hold information (http method, resource url, request payload) + * @param request + */ + put(request: VraRestRequest): VraRestResponse; + + /** + * Delete Method (Http Delete) to execute rest operation by setting Request object. Request object can hold information (http method, resource url, request payload) + * @param request + */ + delete(request: VraRestRequest): VraRestResponse; + + /** + * Post Method to execute rest operation by setting Request object. Request object can hold information (http method, resource url, request payload) + * @param request + */ + post(request: VraRestRequest): VraRestResponse; + /** * Method to create HTTP rest Request. It holds parameter (HTTP Method (GET/PUT/POST/DELETE/PATCH), Resource Path URI, Request Payload (Stringified JSON)). * @param method @@ -455,6 +474,12 @@ declare class VraGenericRestClient { path: string, requestPayload: string ): VraRestRequest; + + /** + * Patch Method (Http Patch) to execute rest operation by setting Request object. Request object can hold information (http method, resource url, request payload) + * @param request + */ + patch(request: VraRestRequest): VraRestResponse; } declare class VraRestRequest { From 10e779e86d4647190898adc74447fb941f745e24 Mon Sep 17 00:00:00 2001 From: Leonid Belenkiy Date: Tue, 30 Jul 2024 10:46:15 +0200 Subject: [PATCH 57/67] add JDOC to deleteZoneById method Signed-off-by: Leonid Belenkiy --- vro-types/o11n-plugin-aria/index.d.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/vro-types/o11n-plugin-aria/index.d.ts b/vro-types/o11n-plugin-aria/index.d.ts index 86d02ca02..aa0006d1e 100644 --- a/vro-types/o11n-plugin-aria/index.d.ts +++ b/vro-types/o11n-plugin-aria/index.d.ts @@ -241,6 +241,10 @@ declare class VraCloudZoneService { */ setGenericRestClient(genericRestClient: VraGenericRestClient): void; + /** + * This method deletes Zone based on given zoneId + * @param zoneId + */ deleteZoneById(zoneId: string): void; /** From a96335aea8101bc79dc821b5d5f5deca1b357532 Mon Sep 17 00:00:00 2001 From: Leonid Belenkiy Date: Tue, 30 Jul 2024 10:55:03 +0200 Subject: [PATCH 58/67] Update Release.md Signed-off-by: Leonid Belenkiy --- docs/versions/latest/Release.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/versions/latest/Release.md b/docs/versions/latest/Release.md index 4cd3bfea7..99b803d31 100644 --- a/docs/versions/latest/Release.md +++ b/docs/versions/latest/Release.md @@ -201,6 +201,7 @@ The following missing methods were added to the exist classes: - Class `VraHost` - `destroy` + - `createInfrastructureClient` #### Related issue From 804a1dae6eca01b123cf266c9899550a8ede6390 Mon Sep 17 00:00:00 2001 From: Stefan Genov Date: Tue, 30 Jul 2024 13:15:16 +0300 Subject: [PATCH 59/67] feat: Add missing option for installer to skip unreleasing blueprints Signed-off-by: Stefan Genov --- .../vmware/pscoe/iac/installer/Installer.java | 12 +++++++++ .../workflow/decorators/helpers/graph.ts | 26 ++++++++++++++----- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/package-installer/src/main/java/com/vmware/pscoe/iac/installer/Installer.java b/package-installer/src/main/java/com/vmware/pscoe/iac/installer/Installer.java index e79b174fe..839c76c83 100644 --- a/package-installer/src/main/java/com/vmware/pscoe/iac/installer/Installer.java +++ b/package-installer/src/main/java/com/vmware/pscoe/iac/installer/Installer.java @@ -252,6 +252,18 @@ enum Option { VRANG_CLOUD_PROXY_NAME( "varng_cloud_proxy_name", ConfigurationVraNg.CLOUD_PROXY_NAME), + + /** + * VRANG unrelease blueprint versions. Decides wether old versions need to be + * unrelased + * + * This only works when running in non interactive mode + */ + VRANG_BP_UNRELEASE_VERSIONS( + "vrang_bp_unrelease_versions", + ConfigurationVraNg.UNRELEASE_BLUEPRINT_VERSIONS), + + /** * VRLI server. */ diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/helpers/graph.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/helpers/graph.ts index 8de76ff19..2f291704d 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/helpers/graph.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/helpers/graph.ts @@ -14,7 +14,7 @@ */ /** - * The node holds information about it's position + * The node holds information about its position */ export interface GraphNode { name: string; @@ -24,7 +24,7 @@ export interface GraphNode { } /** - * Leaf holds the node and it's children(leaves) + * Leaf holds the node and its children(leaves) */ export interface Leaf { node: GraphNode; @@ -36,9 +36,7 @@ export interface Leaf { */ interface Tree { startNodes: string[]; - leaves: { - [nodeName: string]: Leaf; - }; + leaves: Record; } /** @@ -86,6 +84,8 @@ graph.draw(); .................................................................................................... .................................................................................................... .................................................................................................... +.................................................................................................... +.................................................................................................... ..............................F....O....P....Q...................................................... .................................................................................................... .................................................................................................... @@ -96,18 +96,30 @@ graph.draw(); .................................................................................................... ....................G....H....I..................................................................... .................................................................................................... -.....S....T....U...................K................................................................ +...............U...................K................................................................ .................................................................................................... .................................................................................................... .................................................................................................... .................................................................................................... -...............W...................L................................................................ +.....S....T....W...................L................................................................ .................................................................................................... .................................................................................................... .................................................................................................... .................................................................................................... ...................................M................................................................ .................................................................................................... +.................................................................................................... +.................................................................................................... +.................................................................................................... +.....X....Y......................................................................................... +.................................................................................................... +.................................................................................................... +.................................................................................................... +.................................................................................................... +.................................................................................................... +.................................................................................................... +.................................................................................................... +.................................................................................................... .................................................................................................... * ``` */ From 30c22efc0b0d7ab33ae4262c94eff1a457a80dd8 Mon Sep 17 00:00:00 2001 From: Stefan Genov Date: Tue, 30 Jul 2024 13:29:52 +0300 Subject: [PATCH 60/67] test: Fixed test for the Waiting Timer Edge element Signed-off-by: Stefan Genov --- .../workflows/VMware/PSCoE/Waiting Timer Edge.element_info.xml | 2 +- .../canvas-items/workflows/VMware/PSCoE/Waiting Timer Edge.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waiting Timer Edge.element_info.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waiting Timer Edge.element_info.xml index 3d2cccdc1..2ed18038c 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waiting Timer Edge.element_info.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waiting Timer Edge.element_info.xml @@ -5,5 +5,5 @@ VMware.PSCoE Waiting Timer Edge Workflow -03f7e907-57ee-3195-b5a5-140f3b73e8a5 +983d90ae-55f4-3618-b049-264e66324e74 diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waiting Timer Edge.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waiting Timer Edge.xml index 2fa5c0ccc..1be0ff776 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waiting Timer Edge.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waiting Timer Edge.xml @@ -1 +1 @@ - + \ No newline at end of file From cb85dac8aabe6443d47e0911678c89a3ec0656d0 Mon Sep 17 00:00:00 2001 From: Stefan Genov Date: Tue, 30 Jul 2024 13:30:03 +0300 Subject: [PATCH 61/67] refactor: Improved structure of an error message Signed-off-by: Stefan Genov --- .../workflow/decorators/helpers/graph.ts | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/helpers/graph.ts b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/helpers/graph.ts index 2f291704d..b06c5ad20 100644 --- a/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/helpers/graph.ts +++ b/typescript/vrotsc/src/compiler/transformer/fileTransformers/workflow/decorators/helpers/graph.ts @@ -233,6 +233,9 @@ export class Graph { /** * Check if a node is already at the given position + * + * @param {number} x + * @param {number} y */ private hasOverlap(x: number, y: number) { for (const leaf of Object.values(this.tree.leaves)) { @@ -247,6 +250,11 @@ export class Graph { * Builds the tree * * Calculates the x and y positions of each leaf + * + * @param {GraphNode} origin - The node to start building the tree from + * @param {Set} visited - The set of visited nodes + * @param {number} x - The x position of the new node + * @param {number} y - The y position of the new node */ private buildTree( origin: GraphNode, @@ -326,16 +334,10 @@ export class Graph { } if (leaf.node.x === undefined || leaf.node.y === undefined) { - - console.log( - JSON.stringify( - Object.values(this.tree.leaves).map(l => { - return { node: l.node, leaves: l.leaves.map(le => le.node.name) }; - }), - null, - 2 - ) - ); + const nodes = Object.values(this.tree.leaves).map(l => { + return { node: l.node, leaves: l.leaves.map(le => le.node.name) }; + }); + console.log(JSON.stringify(nodes, null, 2)); throw new Error(`Node "${leaf.node.name}" has no position, seems like one of the nodes is not connected which would make your wf unusable, check your targets. Above should be a log of all the leaves.`); } From 61de2aeb83515615df2ba7e3ab3ee38bf7f6c948 Mon Sep 17 00:00:00 2001 From: Stefan Genov Date: Tue, 30 Jul 2024 14:54:11 +0300 Subject: [PATCH 62/67] feat: fixed the position of the start Signed-off-by: Stefan Genov --- .../expect/canvas-items/workflows/VMware/PSCoE/Action Edge.xml | 2 +- .../canvas-items/workflows/VMware/PSCoE/Action Happy Path.xml | 2 +- .../canvas-items/workflows/VMware/PSCoE/Async Workflow Test.xml | 2 +- .../e2e/expect/canvas-items/workflows/VMware/PSCoE/Complex.xml | 2 +- .../canvas-items/workflows/VMware/PSCoE/Decision Edge 2.xml | 2 +- .../canvas-items/workflows/VMware/PSCoE/Decision Edge.xml | 2 +- .../canvas-items/workflows/VMware/PSCoE/Decision Happy.xml | 2 +- .../VMware/PSCoE/Default Error Handler Custom Item.xml | 2 +- .../workflows/VMware/PSCoE/Default Error Handler Happy.xml | 2 +- .../canvas-items/workflows/VMware/PSCoE/Root Default First.xml | 2 +- .../canvas-items/workflows/VMware/PSCoE/Root When Set.xml | 2 +- .../workflows/VMware/PSCoE/Scheduled Workflow Test.xml | 2 +- .../canvas-items/workflows/VMware/PSCoE/Waiting Timer Edge.xml | 2 +- .../canvas-items/workflows/VMware/PSCoE/Waiting Timer Happy.xml | 2 +- .../workflows/VMware/PSCoE/Workflow End Exception.xml | 2 +- .../canvas-items/workflows/VMware/PSCoE/Workflow End Happy.xml | 2 +- .../canvas-items/workflows/VMware/PSCoE/Workflow Test.xml | 2 +- .../transformer/fileTransformers/workflow/presentation.ts | 2 +- 18 files changed, 18 insertions(+), 18 deletions(-) diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Action Edge.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Action Edge.xml index 60c41365f..6f0d8d800 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Action Edge.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Action Edge.xml @@ -1,2 +1,2 @@ - \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Action Happy Path.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Action Happy Path.xml index 73c50cc73..409f409c0 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Action Happy Path.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Action Happy Path.xml @@ -1,3 +1,3 @@ - \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Async Workflow Test.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Async Workflow Test.xml index 4de581f21..fe8dcc188 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Async Workflow Test.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Async Workflow Test.xml @@ -1,4 +1,4 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Decision Edge.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Decision Edge.xml index 16b9ff553..c127911f0 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Decision Edge.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Decision Edge.xml @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Decision Happy.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Decision Happy.xml index 59cb70e57..198ad926c 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Decision Happy.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Decision Happy.xml @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Default Error Handler Custom Item.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Default Error Handler Custom Item.xml index 6cfddfae2..67b4cee33 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Default Error Handler Custom Item.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Default Error Handler Custom Item.xml @@ -1,3 +1,3 @@ - \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Default Error Handler Happy.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Default Error Handler Happy.xml index 368efad84..3ebb75ad9 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Default Error Handler Happy.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Default Error Handler Happy.xml @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Root Default First.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Root Default First.xml index 131e9f522..4e0d3da1b 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Root Default First.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Root Default First.xml @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Root When Set.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Root When Set.xml index f538d2b25..547b03894 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Root When Set.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Root When Set.xml @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Scheduled Workflow Test.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Scheduled Workflow Test.xml index 1c32065cd..8f1093bcd 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Scheduled Workflow Test.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Scheduled Workflow Test.xml @@ -1,4 +1,4 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waiting Timer Happy.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waiting Timer Happy.xml index 015932aad..4ddd605a3 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waiting Timer Happy.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Waiting Timer Happy.xml @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Exception.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Exception.xml index 7bbf5a99d..bbd3ccba9 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Exception.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Exception.xml @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Happy.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Happy.xml index c85d24494..03e6f7e0e 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Happy.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow End Happy.xml @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow Test.xml b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow Test.xml index bb5d216a6..ede4be95f 100644 --- a/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow Test.xml +++ b/typescript/vrotsc/e2e/expect/canvas-items/workflows/VMware/PSCoE/Workflow Test.xml @@ -1,4 +1,4 @@ - \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/workflow/workflows/PS CoE/Test Workflows/Test Workflow 2.xml b/typescript/vrotsc/e2e/expect/workflow/workflows/PS CoE/Test Workflows/Test Workflow 2.xml index 0cadf7ed9..77624b9ab 100644 --- a/typescript/vrotsc/e2e/expect/workflow/workflows/PS CoE/Test Workflows/Test Workflow 2.xml +++ b/typescript/vrotsc/e2e/expect/workflow/workflows/PS CoE/Test Workflows/Test Workflow 2.xml @@ -1,2 +1,2 @@ - \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/workflow/workflows/PS CoE/Test Workflows/Test Workflow 3.xml b/typescript/vrotsc/e2e/expect/workflow/workflows/PS CoE/Test Workflows/Test Workflow 3.xml index cd840c196..20a774fad 100644 --- a/typescript/vrotsc/e2e/expect/workflow/workflows/PS CoE/Test Workflows/Test Workflow 3.xml +++ b/typescript/vrotsc/e2e/expect/workflow/workflows/PS CoE/Test Workflows/Test Workflow 3.xml @@ -1,2 +1,2 @@ - \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/workflow/workflows/PS CoE/Test Workflows/Test Workflow 4.xml b/typescript/vrotsc/e2e/expect/workflow/workflows/PS CoE/Test Workflows/Test Workflow 4.xml index a42563d9e..1b8554940 100644 --- a/typescript/vrotsc/e2e/expect/workflow/workflows/PS CoE/Test Workflows/Test Workflow 4.xml +++ b/typescript/vrotsc/e2e/expect/workflow/workflows/PS CoE/Test Workflows/Test Workflow 4.xml @@ -1,4 +1,4 @@ - \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/workflow/workflows/PSCoE/vRO TypeScript/sub/TestWorkflow2.xml b/typescript/vrotsc/e2e/expect/workflow/workflows/PSCoE/vRO TypeScript/sub/TestWorkflow2.xml index 21f424db3..860506483 100644 --- a/typescript/vrotsc/e2e/expect/workflow/workflows/PSCoE/vRO TypeScript/sub/TestWorkflow2.xml +++ b/typescript/vrotsc/e2e/expect/workflow/workflows/PSCoE/vRO TypeScript/sub/TestWorkflow2.xml @@ -1,2 +1,2 @@ - \ No newline at end of file diff --git a/typescript/vrotsc/e2e/expect/workflow/workflows/PSCoE/vRO TypeScript/sub/sub2/TestWorkflow3.xml b/typescript/vrotsc/e2e/expect/workflow/workflows/PSCoE/vRO TypeScript/sub/sub2/TestWorkflow3.xml index b4f490ca0..dc15d1b2e 100644 --- a/typescript/vrotsc/e2e/expect/workflow/workflows/PSCoE/vRO TypeScript/sub/sub2/TestWorkflow3.xml +++ b/typescript/vrotsc/e2e/expect/workflow/workflows/PSCoE/vRO TypeScript/sub/sub2/TestWorkflow3.xml @@ -1,3 +1,3 @@ - \ No newline at end of file From 2041f435de8ce244d7ee4acf9aee848661333cf2 Mon Sep 17 00:00:00 2001 From: Alexander Kantchev Date: Wed, 31 Jul 2024 14:19:06 +0300 Subject: [PATCH 66/67] [Task 361] code: Improve code to handle indexed items and return null for non indexed ones. Signed-off-by: Alexander Kantchev --- packages/ecmascript/src/Shims.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/ecmascript/src/Shims.ts b/packages/ecmascript/src/Shims.ts index 69237def2..2c18f39d4 100644 --- a/packages/ecmascript/src/Shims.ts +++ b/packages/ecmascript/src/Shims.ts @@ -126,9 +126,18 @@ export default class Shims { break; case "Object": arrayLikeClone = []; - // check whether the object is an array (using the length property) + // Check if the object is an array-like object if (Object.keys(arrayLike).find(item => item.indexOf('length') >= 0)) { - arrayLikeClone = Array.apply(null, Array(arrayLike));// nosonar + const length = (arrayLike as ArrayLike).length; + // mimic the behavior of the standard Array.from() method + arrayLikeClone = Array.apply(null, Array(length));// nosonar + Object.keys(arrayLike).forEach(element => { + const indexKey = parseInt(element); + // Check if object key is like an indexed element and within range + if (!isNaN(indexKey) && indexKey < length) { + arrayLikeClone[element] = arrayLike[element]; + } + }); } break; default: From 61c9ffdc9130b1266fb1cc4e575e56230f816a6d Mon Sep 17 00:00:00 2001 From: Alexander Kantchev Date: Wed, 31 Jul 2024 15:26:12 +0300 Subject: [PATCH 67/67] [Task 361] fix: Fix expression with padString. Signed-off-by: Alexander Kantchev --- packages/ecmascript/src/Shims.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ecmascript/src/Shims.ts b/packages/ecmascript/src/Shims.ts index 2c18f39d4..63ed0c757 100644 --- a/packages/ecmascript/src/Shims.ts +++ b/packages/ecmascript/src/Shims.ts @@ -19,7 +19,7 @@ function getPadString(sourceLength: number, targetLength: number, padString?: st if (padString !== null) { padString = "" + padString; } - if (padString !== null || !padString.length) { + if (!padString?.length) { padString = " "; } let pad = "";