Skip to content

Commit

Permalink
Merge pull request #4 from project-flogo/master
Browse files Browse the repository at this point in the history
update
  • Loading branch information
skothari-tibco authored Apr 12, 2019
2 parents 0ee27a9 + 7b523f1 commit dd0857b
Show file tree
Hide file tree
Showing 79 changed files with 869 additions and 290 deletions.
29 changes: 29 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
BSD 3-Clause License

Copyright (c) 2018, TIBCO Software Inc.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of TIBCO Software Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
67 changes: 66 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,66 @@
EXPERIMENTAL, DO NOT USE
# Flogo Contrib

[![Build Status](https://travis-ci.org/project-flogo/contrib.svg?branch=master)](https://travis-ci.org/project-flogo/contrib.svg?branch=master)

Core collection of Flogo contributions. This repository consists of activities, triggers and functions.

## Contributions

### Activities
* [actreply](activity/actreply): Action Reply
* [actreturn](activity/actreturn): Action Return
* [appdata](activity/actreturn): App Shared Data
* [channel](activity/channel): Send internal engine messages
* [counter](activity/counter): Simple Counter
* [error](activity/error): Throw error
* [jsexec](activity/jsexec): Execute Javascript
* [log](activity/log): Log Message
* [mapper](activity/mapper): Mapper
* [noop](activity/noop): No-Op
* [rest](activity/rest): Basic REST invoker

### Triggers
* [channel](trigger/channel): Listen to internal engine messages
* [cli](trigger/cli): CLI
* [loadtester](trigger/loadtester): Basic load tester
* [rest](trigger/rest): REST
* [timer](trigger/timer): Timer

### Functions
* [coerce](function/coerce): Type Conversion
* [json](function/json): JSON functions
* [number](function/number): Number functions
* [string](function/string): Basic string functions

## Installation

#### Install Activity
Example: install **log** activity

```bash
flogo install github.com/project-flogo/contrib/activity/log
```
#### Install Trigger
Example: install **rest** trigger

```bash
flogo install github.com/project-flogo/contrib/trigger/rest
```
#### Install Functions
Example: install **string** functions

```bash
flogo install github.com/project-flogo/contrib/function/string
```

## Contributing and support

### Contributing

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).

## License
The contrib repository is licensed under a BSD-type license. See [LICENSE](LICENSE) for license text.

### Support
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)
3 changes: 0 additions & 3 deletions activity/actreply/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ This activity allows you to reply to a trigger invocation and map output values.

## Installation

### Flogo Web
This activity comes out of the box with the Flogo Web UI

### Flogo CLI
```bash
flogo install github.com/project-flogo/contrib/activity/actreply
Expand Down
2 changes: 1 addition & 1 deletion activity/actreply/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func init() {
activity.Register(&Activity{}, New)
_ = activity.Register(&Activity{}, New)
}

type Settings struct {
Expand Down
2 changes: 1 addition & 1 deletion activity/actreply/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/project-flogo/contrib/activity/actreply

require (
github.com/project-flogo/core v0.9.0-beta.1
github.com/project-flogo/core v0.9.0-beta.2
github.com/stretchr/testify v1.3.0
)
5 changes: 3 additions & 2 deletions activity/actreply/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/project-flogo/core v0.9.0-beta.1 h1:tiRv5Lv6U1SnDJh6vB10y8AnEdF8/Zmahj8WgCDqS6I=
github.com/project-flogo/core v0.9.0-beta.1/go.mod h1:dzmBbQfNNC0g0KClKYQxxGJLe53MHafg75Vhmw2TW8U=
github.com/project-flogo/core v0.9.0-beta.2 h1:L5VLOfF3YfAFVJwn/tL3x0835sZIedrHcrPkYxHbPl4=
github.com/project-flogo/core v0.9.0-beta.2/go.mod h1:dzmBbQfNNC0g0KClKYQxxGJLe53MHafg75Vhmw2TW8U=
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
Expand Down
3 changes: 0 additions & 3 deletions activity/actreturn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ This activity allows you to reply to a trigger invocation and map output values.

## Installation

### Flogo Web
This activity comes out of the box with the Flogo Web UI

### Flogo CLI
```bash
flogo install github.com/project-flogo/contrib/activity/actreturn
Expand Down
2 changes: 1 addition & 1 deletion activity/actreturn/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func init() {
activity.Register(&Activity{}, New)
_ = activity.Register(&Activity{}, New)
}

type Settings struct {
Expand Down
2 changes: 1 addition & 1 deletion activity/actreturn/activity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestSimpleReturn(t *testing.T) {

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

ac := &test.TestActivityHost{
HostId: "1",
Expand Down
2 changes: 1 addition & 1 deletion activity/actreturn/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/project-flogo/contrib/activity/actreturn

require (
github.com/project-flogo/core v0.9.0-beta.1
github.com/project-flogo/core v0.9.0-beta.2
github.com/stretchr/testify v1.3.0
)
5 changes: 3 additions & 2 deletions activity/actreturn/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/project-flogo/core v0.9.0-beta.1 h1:tiRv5Lv6U1SnDJh6vB10y8AnEdF8/Zmahj8WgCDqS6I=
github.com/project-flogo/core v0.9.0-beta.1/go.mod h1:dzmBbQfNNC0g0KClKYQxxGJLe53MHafg75Vhmw2TW8U=
github.com/project-flogo/core v0.9.0-beta.2 h1:L5VLOfF3YfAFVJwn/tL3x0835sZIedrHcrPkYxHbPl4=
github.com/project-flogo/core v0.9.0-beta.2/go.mod h1:dzmBbQfNNC0g0KClKYQxxGJLe53MHafg75Vhmw2TW8U=
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
Expand Down
69 changes: 69 additions & 0 deletions activity/appdata/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# AppData
This activity allows you to set and get global App attributes\.

## Installation

### Flogo CLI
```bash
flogo install github.com/project-flogo/contrib/activity/appdata
```

## Configuration

### Settings:
| Name | Type | Description
|:--- | :--- | :---
| name | string | The name of the shared attribute - **REQUIRED**
| op | string | The operation (get or set), 'get' is the default
| type | string | The data type of the shared value, default is 'any'

### Input:
| Name | Type | Description
|:--- | :--- | :---
| value | object | The value of the shared attribute


### Output:
| Name | Type | Description
|:--- | :--- | :---
| value | object | The value of the shared attribute


## Examples

### Get
Get the value of the 'myAttr' attribute:

```json
{
"id": "get_app_attr",
"name": "Get App Attr",
"activity": {
"ref": "github.com/project-flogo/contrib/activity/appdata",
"settings": {
"attribute": "myAttr",
"operation": "get"
}
}
}
```

### Set
Update the value of the 'myAttr' attribute to _bar_:

```json
{
"id": "set_app_attr",
"name": "Set App Attr",
"activity": {
"ref": "github.com/project-flogo/contrib/activity/appdata",
"settings": {
"attribute": "myAttr",
"operation": "set"
},
"input": {
"value": "bar"
}
}
}
```
109 changes: 109 additions & 0 deletions activity/appdata/activity.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package appdata

import (
"github.com/project-flogo/core/activity"
"github.com/project-flogo/core/app"
"github.com/project-flogo/core/data"
"github.com/project-flogo/core/data/coerce"
"github.com/project-flogo/core/data/metadata"
)

const (
opGet int = 0
opSet int = 1

ivValue = "value"
ovValue = "value"
)

type Settings struct {
Name string `md:"name,required"` // The name of the shared attribute
Op string `md:"op,allowed(get,set)"` // The operation (get or set), 'get' is the default
Type string `md:"type"` // The data type of the shared value, default is 'any'
}

type Input struct {
Value interface{} `md:"value"` // The value of the shared attribute
}

type Output struct {
Value interface{} `md:"value"` // The value of the shared attribute
}

func init() {
_ = activity.Register(&Activity{}, New)
}

var activityMd = activity.ToMetadata(&Settings{}, &Output{})

// Activity is a Counter Activity implementation
type Activity struct {
op int
dt data.Type
attrName string
}

func New(ctx activity.InitContext) (activity.Activity, error) {
s := &Settings{}
err := metadata.MapToStruct(ctx.Settings(), s, true)
if err != nil {
return nil, err
}

act := &Activity{attrName: s.Name}

if s.Op == "set" {
act.op = opSet
}

if s.Type != "" {
t, err := data.ToTypeEnum(s.Type)
if err != nil {
return nil, err
}
act.dt = t
}

return act, nil
}

// Metadata implements activity.Activity.Metadata
func (a *Activity) Metadata() *activity.Metadata {
return activityMd
}

// Eval implements activity.Activity.Eval
func (a *Activity) Eval(ctx activity.Context) (done bool, err error) {

switch a.op {
case opGet:

val, exists := app.GetValue(a.attrName)
if exists && a.dt > 1 {
val, err = coerce.ToType(val, a.dt)
if err != nil {
return false, err
}
}
err = ctx.SetOutput(ovValue, val)
if err != nil {
return false, err
}
case opSet:
val := ctx.GetInput(ivValue)

if a.dt > 1 {
val, err = coerce.ToType(val, a.dt)
if err != nil {
return false, err
}
}

err = app.SetValue(a.attrName, val)
if err != nil {
return false, err
}
}

return true, nil
}
Loading

0 comments on commit dd0857b

Please sign in to comment.