Skip to content

Commit dd0857b

Browse files
Merge pull request #4 from project-flogo/master
update
2 parents 0ee27a9 + 7b523f1 commit dd0857b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+869
-290
lines changed

LICENSE

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
BSD 3-Clause License
2+
3+
Copyright (c) 2018, TIBCO Software Inc.
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are met:
8+
9+
* Redistributions of source code must retain the above copyright notice, this
10+
list of conditions and the following disclaimer.
11+
12+
* Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
16+
* Neither the name of TIBCO Software Inc. nor the names of its
17+
contributors may be used to endorse or promote products derived from
18+
this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

+66-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,66 @@
1-
EXPERIMENTAL, DO NOT USE
1+
# Flogo Contrib
2+
3+
[![Build Status](https://travis-ci.org/project-flogo/contrib.svg?branch=master)](https://travis-ci.org/project-flogo/contrib.svg?branch=master)
4+
5+
Core collection of Flogo contributions. This repository consists of activities, triggers and functions.
6+
7+
## Contributions
8+
9+
### Activities
10+
* [actreply](activity/actreply): Action Reply
11+
* [actreturn](activity/actreturn): Action Return
12+
* [appdata](activity/actreturn): App Shared Data
13+
* [channel](activity/channel): Send internal engine messages
14+
* [counter](activity/counter): Simple Counter
15+
* [error](activity/error): Throw error
16+
* [jsexec](activity/jsexec): Execute Javascript
17+
* [log](activity/log): Log Message
18+
* [mapper](activity/mapper): Mapper
19+
* [noop](activity/noop): No-Op
20+
* [rest](activity/rest): Basic REST invoker
21+
22+
### Triggers
23+
* [channel](trigger/channel): Listen to internal engine messages
24+
* [cli](trigger/cli): CLI
25+
* [loadtester](trigger/loadtester): Basic load tester
26+
* [rest](trigger/rest): REST
27+
* [timer](trigger/timer): Timer
28+
29+
### Functions
30+
* [coerce](function/coerce): Type Conversion
31+
* [json](function/json): JSON functions
32+
* [number](function/number): Number functions
33+
* [string](function/string): Basic string functions
34+
35+
## Installation
36+
37+
#### Install Activity
38+
Example: install **log** activity
39+
40+
```bash
41+
flogo install github.com/project-flogo/contrib/activity/log
42+
```
43+
#### Install Trigger
44+
Example: install **rest** trigger
45+
46+
```bash
47+
flogo install github.com/project-flogo/contrib/trigger/rest
48+
```
49+
#### Install Functions
50+
Example: install **string** functions
51+
52+
```bash
53+
flogo install github.com/project-flogo/contrib/function/string
54+
```
55+
56+
## Contributing and support
57+
58+
### Contributing
59+
60+
New activities, triggers and functions are welcomed. If you would like to contribute, please following the [contribution guidelines](https://github.com/TIBCOSoftware/flogo/blob/master/CONTRIBUTING.md). If you have any questions, issues, etc feel free to chat with us on [Gitter](https://gitter.im/project-flogo/Lobby?utm_source=share-link&utm_medium=link&utm_campaign=share-link).
61+
62+
## License
63+
The contrib repository is licensed under a BSD-type license. See [LICENSE](LICENSE) for license text.
64+
65+
### Support
66+
For Q&A you can post your questions on [Gitter](https://gitter.im/project-flogo/Lobby?utm_source=share-link&utm_medium=link&utm_campaign=share-link)

activity/actreply/README.md

-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ This activity allows you to reply to a trigger invocation and map output values.
88

99
## Installation
1010

11-
### Flogo Web
12-
This activity comes out of the box with the Flogo Web UI
13-
1411
### Flogo CLI
1512
```bash
1613
flogo install github.com/project-flogo/contrib/activity/actreply

activity/actreply/activity.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
func init() {
10-
activity.Register(&Activity{}, New)
10+
_ = activity.Register(&Activity{}, New)
1111
}
1212

1313
type Settings struct {

activity/actreply/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/project-flogo/contrib/activity/actreply
22

33
require (
4-
github.com/project-flogo/core v0.9.0-beta.1
4+
github.com/project-flogo/core v0.9.0-beta.2
55
github.com/stretchr/testify v1.3.0
66
)

activity/actreply/go.sum

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
44
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
55
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
66
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
7-
github.com/project-flogo/core v0.9.0-beta.1 h1:tiRv5Lv6U1SnDJh6vB10y8AnEdF8/Zmahj8WgCDqS6I=
8-
github.com/project-flogo/core v0.9.0-beta.1/go.mod h1:dzmBbQfNNC0g0KClKYQxxGJLe53MHafg75Vhmw2TW8U=
7+
github.com/project-flogo/core v0.9.0-beta.2 h1:L5VLOfF3YfAFVJwn/tL3x0835sZIedrHcrPkYxHbPl4=
8+
github.com/project-flogo/core v0.9.0-beta.2/go.mod h1:dzmBbQfNNC0g0KClKYQxxGJLe53MHafg75Vhmw2TW8U=
9+
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
910
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
1011
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
1112
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=

activity/actreturn/README.md

-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ This activity allows you to reply to a trigger invocation and map output values.
88

99
## Installation
1010

11-
### Flogo Web
12-
This activity comes out of the box with the Flogo Web UI
13-
1411
### Flogo CLI
1512
```bash
1613
flogo install github.com/project-flogo/contrib/activity/actreturn

activity/actreturn/activity.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
func init() {
10-
activity.Register(&Activity{}, New)
10+
_ = activity.Register(&Activity{}, New)
1111
}
1212

1313
type Settings struct {

activity/actreturn/activity_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func TestSimpleReturn(t *testing.T) {
6666

6767
func newActionContext() *test.TestActivityHost {
6868
input := map[string]data.TypedValue{"Input1": data.NewTypedValue(data.TypeString, "")}
69-
output := map[string]data.TypedValue{"Output1": data.NewTypedValue(data.TypeString, ""), "Output2": data.NewTypedValue(data.TypeInt, "")}
69+
output := map[string]data.TypedValue{"Output1": data.NewTypedValue(data.TypeString, "")}
7070

7171
ac := &test.TestActivityHost{
7272
HostId: "1",

activity/actreturn/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/project-flogo/contrib/activity/actreturn
22

33
require (
4-
github.com/project-flogo/core v0.9.0-beta.1
4+
github.com/project-flogo/core v0.9.0-beta.2
55
github.com/stretchr/testify v1.3.0
66
)

activity/actreturn/go.sum

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
44
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
55
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
66
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
7-
github.com/project-flogo/core v0.9.0-beta.1 h1:tiRv5Lv6U1SnDJh6vB10y8AnEdF8/Zmahj8WgCDqS6I=
8-
github.com/project-flogo/core v0.9.0-beta.1/go.mod h1:dzmBbQfNNC0g0KClKYQxxGJLe53MHafg75Vhmw2TW8U=
7+
github.com/project-flogo/core v0.9.0-beta.2 h1:L5VLOfF3YfAFVJwn/tL3x0835sZIedrHcrPkYxHbPl4=
8+
github.com/project-flogo/core v0.9.0-beta.2/go.mod h1:dzmBbQfNNC0g0KClKYQxxGJLe53MHafg75Vhmw2TW8U=
9+
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
910
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
1011
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
1112
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=

activity/appdata/README.md

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# AppData
2+
This activity allows you to set and get global App attributes\.
3+
4+
## Installation
5+
6+
### Flogo CLI
7+
```bash
8+
flogo install github.com/project-flogo/contrib/activity/appdata
9+
```
10+
11+
## Configuration
12+
13+
### Settings:
14+
| Name | Type | Description
15+
|:--- | :--- | :---
16+
| name | string | The name of the shared attribute - **REQUIRED**
17+
| op | string | The operation (get or set), 'get' is the default
18+
| type | string | The data type of the shared value, default is 'any'
19+
20+
### Input:
21+
| Name | Type | Description
22+
|:--- | :--- | :---
23+
| value | object | The value of the shared attribute
24+
25+
26+
### Output:
27+
| Name | Type | Description
28+
|:--- | :--- | :---
29+
| value | object | The value of the shared attribute
30+
31+
32+
## Examples
33+
34+
### Get
35+
Get the value of the 'myAttr' attribute:
36+
37+
```json
38+
{
39+
"id": "get_app_attr",
40+
"name": "Get App Attr",
41+
"activity": {
42+
"ref": "github.com/project-flogo/contrib/activity/appdata",
43+
"settings": {
44+
"attribute": "myAttr",
45+
"operation": "get"
46+
}
47+
}
48+
}
49+
```
50+
51+
### Set
52+
Update the value of the 'myAttr' attribute to _bar_:
53+
54+
```json
55+
{
56+
"id": "set_app_attr",
57+
"name": "Set App Attr",
58+
"activity": {
59+
"ref": "github.com/project-flogo/contrib/activity/appdata",
60+
"settings": {
61+
"attribute": "myAttr",
62+
"operation": "set"
63+
},
64+
"input": {
65+
"value": "bar"
66+
}
67+
}
68+
}
69+
```

activity/appdata/activity.go

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
package appdata
2+
3+
import (
4+
"github.com/project-flogo/core/activity"
5+
"github.com/project-flogo/core/app"
6+
"github.com/project-flogo/core/data"
7+
"github.com/project-flogo/core/data/coerce"
8+
"github.com/project-flogo/core/data/metadata"
9+
)
10+
11+
const (
12+
opGet int = 0
13+
opSet int = 1
14+
15+
ivValue = "value"
16+
ovValue = "value"
17+
)
18+
19+
type Settings struct {
20+
Name string `md:"name,required"` // The name of the shared attribute
21+
Op string `md:"op,allowed(get,set)"` // The operation (get or set), 'get' is the default
22+
Type string `md:"type"` // The data type of the shared value, default is 'any'
23+
}
24+
25+
type Input struct {
26+
Value interface{} `md:"value"` // The value of the shared attribute
27+
}
28+
29+
type Output struct {
30+
Value interface{} `md:"value"` // The value of the shared attribute
31+
}
32+
33+
func init() {
34+
_ = activity.Register(&Activity{}, New)
35+
}
36+
37+
var activityMd = activity.ToMetadata(&Settings{}, &Output{})
38+
39+
// Activity is a Counter Activity implementation
40+
type Activity struct {
41+
op int
42+
dt data.Type
43+
attrName string
44+
}
45+
46+
func New(ctx activity.InitContext) (activity.Activity, error) {
47+
s := &Settings{}
48+
err := metadata.MapToStruct(ctx.Settings(), s, true)
49+
if err != nil {
50+
return nil, err
51+
}
52+
53+
act := &Activity{attrName: s.Name}
54+
55+
if s.Op == "set" {
56+
act.op = opSet
57+
}
58+
59+
if s.Type != "" {
60+
t, err := data.ToTypeEnum(s.Type)
61+
if err != nil {
62+
return nil, err
63+
}
64+
act.dt = t
65+
}
66+
67+
return act, nil
68+
}
69+
70+
// Metadata implements activity.Activity.Metadata
71+
func (a *Activity) Metadata() *activity.Metadata {
72+
return activityMd
73+
}
74+
75+
// Eval implements activity.Activity.Eval
76+
func (a *Activity) Eval(ctx activity.Context) (done bool, err error) {
77+
78+
switch a.op {
79+
case opGet:
80+
81+
val, exists := app.GetValue(a.attrName)
82+
if exists && a.dt > 1 {
83+
val, err = coerce.ToType(val, a.dt)
84+
if err != nil {
85+
return false, err
86+
}
87+
}
88+
err = ctx.SetOutput(ovValue, val)
89+
if err != nil {
90+
return false, err
91+
}
92+
case opSet:
93+
val := ctx.GetInput(ivValue)
94+
95+
if a.dt > 1 {
96+
val, err = coerce.ToType(val, a.dt)
97+
if err != nil {
98+
return false, err
99+
}
100+
}
101+
102+
err = app.SetValue(a.attrName, val)
103+
if err != nil {
104+
return false, err
105+
}
106+
}
107+
108+
return true, nil
109+
}

0 commit comments

Comments
 (0)