Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ You can use the method decorators to define various canvas items that will be in
- [`@Item`](#item)
- [`@WaitingTimerItem`](#waitingtimeritem)
- [`@DecisionItem`](#decisionitem)
- [`@SwitchItem`](#switchitem)
- [`@WorkflowItem`](#workflowitem)
- [`@ScheduledWorkflowItem`](#scheduledworkflowitem)
- [`@RootItem`](#rootitem)
Expand Down Expand Up @@ -273,6 +274,126 @@ The example above would generate the following workflow.

[![Decision Item Workflow](images/Decision_Item_Canvas_Item_Workflow.png)](images/Decision_Item_Canvas_Item_Workflow.png)

#### `@SwitchItem`

This decorator is used to specify a switch item that routes workflow execution to different paths based on the value of a variable or expression.

##### Supported Parameters

- `cases` - An array of case objects that define the routing logic. Each case object contains:
- `condition` - The value to match against the switch variable
- `target` - The name of the next item to execute when this condition is met
- `variable` - The name of the variable to evaluate (optional, can be inferred from method parameters)
- `type` - The data type of the variable being switched on (e.g., "number", "string", "boolean")
- `defaultTarget` - The name of the next item to execute when none of the cases match. If this is set to `end`, it will point to the end of the workflow. If this is set to `null`, it will point to the next item or if none, the end of the workflow.
- `comparator` - The comparison operator to use when evaluating cases. Supported values are:
- `"==="` - Equals (default behavior if not specified)
- `"=="` - Loose equality, same as '===' for consistency
- `"!=="` - Not equals
- `"!="` - Loose inequality, same as '!==' for consistency
- `"<"` - Less than
- `"<=` - Less than or equal
- `">"` - Greater than
- `">=` - Greater than or equal
- `exception` - The name of the next in line item in case an exception is encountered during the execution of the current item. If this is set to `null` or empty string, the parameter is ignored. If this is set to a string, but it does not exist in the workflow, it will point to the end of the workflow.

##### Example

```ts
import { Workflow, SwitchItem } from "vrotsc-annotations";

@Workflow({
name: "Switch Happy Path",
path: "VMware/PSCoE",
description: "Basic switch test with multiple numeric cases and default target",
attributes: {
operationType: {
type: "number"
},
}
})
export class SwitchHappyPath {
@SwitchItem({
cases: [
{ condition: 1, target: "createResource", variable: "operationType", type: "number" },
{ condition: 2, target: "updateResource", variable: "operationType", type: "number" },
{ condition: 3, target: "deleteResource", variable: "operationType", type: "number" }
],
defaultTarget: "logUnknownOperation"
})
public switchElement(operationType: number) {
// Switch logic will be generated automatically
}

public createResource() {
System.log("Creating resource");
}

public updateResource() {
System.log("Updating resource");
}

public deleteResource() {
System.log("Deleting resource");
}

public logUnknownOperation() {
System.log("Unknown operation type");
}
}
```

The example above would generate a workflow where:
- If `operationType` equals 1, the workflow goes to `createResource`
- If `operationType` equals 2, the workflow goes to `updateResource`
- If `operationType` equals 3, the workflow goes to `deleteResource`
- If `operationType` has any other value, the workflow goes to `logUnknownOperation`

##### Switch Item with String Cases

```ts
import { Workflow, SwitchItem } from "vrotsc-annotations";

@Workflow({
name: "String Switch Workflow",
path: "VMware/PSCoE",
description: "Switch workflow with string cases",
attributes: {
environment: {
type: "string"
},
}
})
export class StringSwitchWorkflow {
@SwitchItem({
cases: [
{ condition: "dev", target: "setupDevelopment", variable: "environment", type: "string" },
{ condition: "test", target: "setupTesting", variable: "environment", type: "string" },
{ condition: "prod", target: "setupProduction", variable: "environment", type: "string" }
],
defaultTarget: "setupDefault"
})
public routeByEnvironment(environment: string) {
// Switch logic will be generated automatically
}

public setupDevelopment() {
System.log("Setting up development environment");
}

public setupTesting() {
System.log("Setting up testing environment");
}

public setupProduction() {
System.log("Setting up production environment");
}

public setupDefault() {
System.log("Setting up default environment");
}
}
````
#### `@WorkflowItem`

The decorator is used to specify a workflow item that will be called.
Expand Down
2 changes: 2 additions & 0 deletions typescript/npmconv/package-lock.json

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

2 changes: 2 additions & 0 deletions typescript/polyglotpkg/package-lock.json

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

4 changes: 4 additions & 0 deletions typescript/vro-scripting-api/package-lock.json

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

4 changes: 4 additions & 0 deletions typescript/vropkg/package-lock.json

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

40 changes: 40 additions & 0 deletions typescript/vrotsc/e2e/cases/canvas-items/switch-boolean.wf.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Workflow, SwitchItem } from "vrotsc-annotations";

@Workflow({
name: "Switch Boolean Cases",
path: "VMware/PSCoE",
description: "Switch test with boolean conditions and mixed types",
attributes: {
isEnabled: {
type: "boolean"
},
priority: {
type: "number"
},
}
})
export class SwitchBooleanCases {

@SwitchItem({
cases: [
{ condition: true, target: "enableFeature", variable: "isEnabled", type: "boolean", comparator: "===" },
{ condition: false, target: "disableFeature", variable: "isEnabled", type: "boolean", comparator: "===" }
],
defaultTarget: "handleUndefined"
})
public switchByBoolean(isEnabled: boolean, priority: number) {
// Boolean switch logic
}

public enableFeature() {
System.log("Feature is enabled");
}

public disableFeature() {
System.log("Feature is disabled");
}

public handleUndefined() {
System.log("Boolean value is undefined");
}
}
107 changes: 107 additions & 0 deletions typescript/vrotsc/e2e/cases/canvas-items/switch-edge.wf.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import { Workflow, SwitchItem } from "vrotsc-annotations";

@Workflow({
name: "Switch Edge Cases",
path: "VMware/PSCoE",
description: "Switch test covering edge cases - various operators, no default target, and complex conditions",
attributes: {
errorCode: {
type: "number"
},
priority: {
type: "number"
},
status: {
type: "string"
},
}
})
export class SwitchEdgeCases {

@SwitchItem({
cases: [
{ condition: 404, target: "handleNotFound", variable: "errorCode", type: "number", comparator: "===" },
{ condition: 500, target: "handleServerError", variable: "errorCode", type: "number", comparator: "!==" },
{ condition: 403, target: "handleForbidden", variable: "errorCode", type: "number", comparator: "==" }
],
// No default target - will fall through to next item
})
public switchErrorCodes(errorCode: number) {
// Error code switch without default using various equality operators
System.log("Processing error code: " + errorCode);
}

@SwitchItem({
cases: [
{ condition: 1, target: "lowPriority", variable: "priority", type: "number", comparator: "<=" },
{ condition: 5, target: "mediumPriority", variable: "priority", type: "number", comparator: ">" },
{ condition: 10, target: "highPriority", variable: "priority", type: "number", comparator: ">=" }
],
defaultTarget: "handleInvalidPriority"
})
public switchPriority(priority: number) {
// Priority switch using comparison operators
System.log("Processing priority: " + priority);
}

@SwitchItem({
cases: [
{ condition: "active", target: "processActive", variable: "status", type: "string", comparator: "===" },
{ condition: "pending", target: "processPending", variable: "status", type: "string", comparator: "!=" },
{ condition: "inactive", target: "processInactive", variable: "status", type: "string", comparator: "!==" }
],
defaultTarget: "handleUnknownStatus"
})
public switchStatus(status: string) {
// String status switch with mixed operators
System.log("Processing status: " + status);
}

public handleNotFound() {
System.log("404 - Resource not found");
}

public handleServerError() {
System.log("500 - Internal server error");
}

public handleForbidden() {
System.log("403 - Access forbidden");
}

public lowPriority() {
System.log("Low priority task (<=1)");
}

public mediumPriority() {
System.log("Medium priority task (>5)");
}

public highPriority() {
System.log("High priority task (>=10)");
}

public handleInvalidPriority() {
System.log("Invalid priority level");
}

public processActive() {
System.log("Processing active status");
}

public processPending() {
System.log("Processing pending status (not equal to 'pending')");
}

public processInactive() {
System.log("Processing inactive status (not strictly equal to 'inactive')");
}

public handleUnknownStatus() {
System.log("Unknown status - using default handler");
}

public fallbackHandler() {
System.log("Unhandled error code - using fallback");
}
}
Loading
Loading