Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vrotsc] (#325) Add Workflow canvas Workflow item #334

Merged
merged 17 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from 15 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 @@ -46,54 +46,79 @@ This decorator is used to specify a decision item.
- `target` - The name of the next in line item. Same as `@Item`.
- `else` - The name of the next in line item if the decision is false. 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 wf. If this is set to a string, but it does not exist in the workflow, it will point to the end of the wf.

#### `@WorkflowItem`

The decorator is used to specify a 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 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.

#### `@RootItem`

This is a meta decorator. Add this to whichever function you want to be the entry point of the workflow.

### Example Workflow

```ts
import {
Workflow,
Out,
In,
Item,
RootItem,
DecisionItem,
WaitingTimerItem,
} 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"
},
second: {
type: "number"
},
},
result: {
type: "number"
}
}
})
export class HandleNetworkConfigurationBackup {
@DecisionItem({
target: "waitForEvent",
else: null, // null means end
})
@DecisionItem({ target: "waitForEvent", else: "prepareItems" })
public decisionElement(waitingTimer: Date) {
return waitingTimer !== null;
}

@Item({
target: "decisionElement",
exception: "",
@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);
Expand All @@ -105,18 +130,14 @@ export class HandleNetworkConfigurationBackup {
System.log("Waiting Timer: " + waitingTimer);
}

@Item({
target: "execute",
exception: "",
})
@Item({ target: "execute", exception: "" })
@RootItem()
public start() {
System.log("Starting workflow");
}

@WaitingTimerItem({
target: "execute",
})
public waitForEvent(@In waitingTimer: Date) {}
@WaitingTimerItem({ target: "execute" })
public waitForEvent(@In waitingTimer: Date) {
}
}
```
91 changes: 91 additions & 0 deletions docs/versions/latest/Release.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,97 @@

[//]: # (Improvements -> Bugfixes/hotfixes or general improvements)

### *New `WorkflowItem` decorator for Workflows

The new Decorator gives you the ability to specify a canvas item that calls a Workflow.

- `@WorkflowItem({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.

Example:

```typescript
import { Workflow, Out, In, Item, RootItem, DecisionItem, WaitingTimerItem, WorkflowItem } 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"
}
}
})
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) {
}
}
```

## Improvements

[//]: # (### *Improvement Name* )
Expand Down
77 changes: 77 additions & 0 deletions typescript/vrotsc/e2e/cases/canvas-items/workflow.wf.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { Workflow, Out, In, Item, RootItem, DecisionItem, WaitingTimerItem, WorkflowItem } from "vrotsc-annotations";

@Workflow({
name: "Workflow Test",
path: "VMware/PSCoE",
description: "Calling another workflow and binding values correctly",
attributes: {
waitingTimer: {
type: "Date"
},
counter: {
type: "number"
},
first: {
type: "number"
},
second: {
type: "number"
},
result: {
type: "number"
}
}
})
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) {
}
}
Loading
Loading