Skip to content
Open
Show file tree
Hide file tree
Changes from all 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,195 @@ 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"` - Equals (default behaviour if not specified)
- `"different"` - Not equals
- `"smaller"` - Less than
- `"smaller or equals"` - Less than or equal
- `"greater"` - Greater than
- `"greater or equals"` - Greater than or equal
- `"contains"` - Contains a value
- `"match"` - Matches a value
- `"is defined"` - Value is defined
- `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 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: "equals" },
{ condition: 500, target: "handleServerError", variable: "errorCode", type: "number", comparator: "different" }
],
target: "switchPriority"
})
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: "smaller" },
{ condition: 5, target: "mediumPriority", variable: "priority", type: "number", comparator: "greater" }
],
target: "switchStatus"
})
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: "equals" },
{ condition: "pending", target: "processPending", variable: "status", type: "string", comparator: "different" }
],
target: "handleNotFound"
})
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("Not handled error code - using fallback");
}
}
```

##### Switch Item with String Cases


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

@Workflow({
name: "Switch String Cases",
path: "VMware/PSCoE",
description: "Switch test with string conditions and exception handling",
attributes: {
status: {
type: "string"
},
}
})
export class SwitchStringCases {

@SwitchItem({
cases: [
{ condition: "active", target: "processActive", variable: "status", type: "string", comparator: "equals" },
{ condition: "pending", target: "processPending", variable: "status", type: "string", comparator: "different" },
{ condition: "inactive", target: "processInactive", variable: "status", type: "string", comparator: "equals" }
],
target: "handleUnknownStatus",
exception: "handleError"
})
public switchByStatus(status: string) {
// Switch logic for string conditions
if (status === null || status === undefined) {
throw new Error("Status cannot be null");
}
}

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

public processPending() {
System.log("Processing pending status");
}

public processInactive() {
System.log("Processing inactive status");
}

public handleUnknownStatus() {
System.log("Unknown status encountered");
}

public handleError() {
System.log("Error occurred in switch processing");
}
}
````

#### `@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.

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

@Workflow({
name: "switch all",
path: "VMware/PSCoE",
description: "Comprehensive switch test with all comparator types",
attributes: {
var_str: {
type: "string"
},
var_num: {
type: "number"
},
var_bool: {
type: "boolean"
},
}
})
export class SwitchAll {

@SwitchItem({
cases: [
// String comparisons
{ condition: "", target: "handleEmpty", variable: "var_str", type: "string", comparator: "equals" },
{ condition: "test", target: "handleStringOp", variable: "var_str", type: "string", comparator: "contains" },
{ condition: "pattern", target: "handleStringOp", variable: "var_str", type: "string", comparator: "match" },
{ condition: "value", target: "handleStringOp", variable: "var_str", type: "string", comparator: "different" },

// Number comparisons
{ condition: 1, target: "handleNumeric", variable: "var_num", type: "number", comparator: "different" },
{ condition: 5, target: "handleNumeric", variable: "var_num", type: "number", comparator: "greater" },
{ condition: 10, target: "handleNumeric", variable: "var_num", type: "number", comparator: "smaller" },
{ condition: 0, target: "handleNumeric", variable: "var_num", type: "number", comparator: "greater or equals" },
{ condition: 100, target: "handleNumeric", variable: "var_num", type: "number", comparator: "smaller or equals" },

// Boolean comparisons
{ condition: true, target: "handleBoolean", variable: "var_bool", type: "boolean", comparator: "equals" },
{ condition: false, target: "handleBoolean", variable: "var_bool", type: "boolean", comparator: "different" }
],
target: "handleDefault"
})
public switchElement() {
// Switch logic will be generated automatically
}

public handleEmpty() {
System.log("Handling empty string");
}

public handleStringOp() {
System.log("Handling string operation");
}

public handleNumeric() {
System.log("Handling numeric operation");
}

public handleBoolean() {
System.log("Handling boolean operation");
}

public handleDefault() {
System.log("Handling default case");
}
}
Loading
Loading