Skip to content

Commit

Permalink
Add Initial Trigger docs
Browse files Browse the repository at this point in the history
  • Loading branch information
pdhar-tibco committed Apr 5, 2018
1 parent b3f1986 commit ea6f58f
Show file tree
Hide file tree
Showing 5 changed files with 825 additions and 5 deletions.
16 changes: 13 additions & 3 deletions docs/content/extensions/organizing-code/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,27 @@ The extensions for TCI Flogo consist of a bunch of files that all have a very sp
| Runtime | Go | [activity.go<br/>activity_test.go](./activity-go) | Every extension must write the runtime code in Go (activity.go). You can, and really should, leverage the Go testing framework for writing unit test cases (activity_test.go) for your extension.
| UI (_optional_) | TypeScript | [activity.ts<br/>activity.module.ts](./activity-ts) | The activity.ts file handles the validation and actions for the fields described in the model. For example it validates that a valid connection has been chosen, or retrieves additional information based on values in certain fields. This part is optional and you can rely on the out of the box UI as well!

## Trigger

| Component | Technology | Filename | Description
| --------------- | ---------- | ---------------------------------- | -----------
| Model | JSON | [trigger.json](./trigger-json) | The trigger.json describes the model, the meta data, of the trigger. It describes, among other things, what the input and outputs are, who built it and which version you're using.
| Runtime | Go | [trigger.go<br/>trigger_test.go](./trigger-go) | Every extension must write the runtime code in Go (trigger.go). You can, and really should, leverage the Go testing framework for writing unit test cases (trigger_test.go) for your extension.
| UI (_optional_) | TypeScript | [trigger.ts<br/>trigger.module.ts](./trigger-ts) | The trigger.ts file handles the validation and actions for the fields described in the model. For example it validates that a valid connection has been chosen, or retrieves additional information based on values in certain fields. This part is optional and you can rely on the out of the box UI as well!

## Folder Layout

The layout of your folder has to follow a specific structure.
```
<category>
├───activity
│ └───<activity>
│ └───<activity name>
└───connector
└───<connector>
│ └───<connector name>
└───trigger
└───<trigger name>
```
The category you want your activities to be in should be the name of your top level folder. Your activities will be in separate folders under the **activity** folder and your connectors will be subfolders of the **connector** folder. Please note that names of activities and connectors should be in lowercase
The category you want your activities to be in should be the name of your top level folder. Your activities will be in separate folders under the **activity** folder and your connectors will be subfolders of the **connector** folder and the triggers will be under the **trigger** folder. Please note that names of activities connectors and triggers should be in lowercase

{{% notice warning %}}
Please note that names of activities and connectors should be in lowercase
Expand Down
4 changes: 2 additions & 2 deletions docs/content/extensions/organizing-code/display-settings.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
date: 2016-04-09T16:50:16+02:00
title: Display settings
weight: 57
weight: 60
---

The **display** element in the activity.json and the connector.json can be used to enhance the user experience even more!
The **display** element in the activity.json, connector.json and the trigger.json can be used to enhance the user experience even more!

## Types
Each display element has a type associated with it. The below table displays the types you can use and the **Go type** column shows how that translates into Go data types you can use in your activity.go file
Expand Down
184 changes: 184 additions & 0 deletions docs/content/extensions/organizing-code/trigger-go.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@

---
date: 2016-04-09T16:50:16+02:00
title: trigger.go
weight: 59
---

Every extension must write the runtime code in Go (trigger.go). You can, and really should, leverage the Go testing framework for writing unit test cases (trigger_test.go) for your extension. The code here give you an overview of what files are structured like, but for samples you should really check out the samples section!

**trigger.go**
```go
package sample

import (
"github.com/TIBCOSoftware/flogo-lib/core/action"
"github.com/TIBCOSoftware/flogo-lib/core/trigger"
"github.com/TIBCOSoftware/flogo-lib/logger"
)

// Create a logger for the Sample Trigger
// Logger Name : <category>-trigger-<type>
var triggerLog = logger.GetLogger("demo-trigger-sample")

// Trigger must define a struct
type SampleTrigger struct {
// Trigger Metadata
metadata *trigger.Metadata
// Flow action that would create a flow instance
runner action.Runner
// Trigger configuration
config *trigger.Config
}

// Sample Trigger factory
// Trigger must define a factory
type SampleTriggerFactory struct {
// Trigger Metadata
metadata *trigger.Metadata
}

// NewFactory create a new Trigger factory
// Trigger must define this function
func NewFactory(md *trigger.Metadata) trigger.Factory {
return &SampleTriggerFactory{metadata: md}
}

// Creates a new trigger instance for a given id
// Trigger must define this method
func (t *SampleTriggerFactory) New(config *trigger.Config) trigger.Trigger {
return &SampleTrigger{metadata: t.metadata, config: config}
}

// Returns trigger metadata
// Trigger must define this method
func (t *SampleTrigger) Metadata() *trigger.Metadata {
return t.metadata
}

// Set flow runner
// Trigger must define this method
func (t *SampleTrigger) Init(runner action.Runner) {
// Flow runner must be stored
t.runner = runner
}

// Start trigger. Start will be called once engine is started successfully.
func (t *SampleTrigger) Start() error {
return nil
}

// Stop trigger. Stop will be called in case engine is gracefully stopped.
func (t *SampleTrigger) Stop() error {
return nil
}
```

#### How to read trigger configuration in runtime code?
Any trigger configuration defined in the trigger model can be accessed through *trigger.Config.

**trigger.json**
```json
{
"name":"Sample Trigger",
......
"settings":[
{
"name": "field1",
"type": "string",
"required": true,
"value": "This is field1 value"
}
],
"handler":{
.....
},
"outputs":[
]
}
```
**trigger.go**
```go
package sample

import (
"github.com/TIBCOSoftware/flogo-lib/core/action"
"github.com/TIBCOSoftware/flogo-lib/core/trigger"
"github.com/TIBCOSoftware/flogo-lib/logger"
)

const (
ivField1 = "field1"
)


type SampleTrigger struct {
// Trigger Metadata
metadata *trigger.Metadata
// Flow action that would create a flow instance
runner action.Runner
// Trigger configuration
config *trigger.Config
}
......
func (t *SampleTrigger) Init(runner action.Runner) {
t.runner = runner
field1 := t.config.Settings[ivField1].(string) // Type casting is required
}
```
### How to read handler configuration in runtime code?
Any handler configuration defined in the trigger model can be accessed through `*trigger.Config`.

**trigger.json**
```json
{
"name":"Sample Trigger",
......
"settings":[
....
],
"handler":{
"settings":[
{
"name": "field1",
"type": "string",
"required": true,
"value": "This is field1 value"
}
]
},
"outputs":[
]
}
```
**trigger.go**
```go
package sample

import (
"github.com/TIBCOSoftware/flogo-lib/core/action"
"github.com/TIBCOSoftware/flogo-lib/core/trigger"
"github.com/TIBCOSoftware/flogo-lib/logger"
)

const (
ivField1 = "field1"
)


type SampleTrigger struct {
// Trigger Metadata
metadata *trigger.Metadata
// Flow action that would create a flow instance
runner action.Runner
// Trigger configuration
config *trigger.Config
}
......
func (t *SampleTrigger) Init(runner action.Runner) {
t.runner = runner
for _, handler := range t.config.Handlers { // For trigger, there would be one or more handlers
field1 := handler.Settings[ivField1].(string) // Type casting is required
}
}
```
Loading

0 comments on commit ea6f58f

Please sign in to comment.