put

package module
v0.1.1-0...-4a489c3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 27, 2021 License: BSD-3-Clause Imports: 10 Imported by: 0

README

Fabric Put activity

This Flogo activity contribution can be configured to perform write operations on Hyperledger Fabric distributed ledger and private data collections. Most of the write operations are demonstrated in the contract example.

Insert or update one or more ledger states

This operation requires input data of one or an array of key-value pairs, and optionally defintions of one or more composite-keys. For insert-only operations, you can turn on the createOnly flag, e.g.,

    "activity": {
        "ref": "#put",
        "settings": {
            "compositeKeys": {
                "mapping": {
                    "color~name": ["docType", "color", "name"],
                    "owner~name": ["docType", "owner", "name"]
                }
            },
            "createOnly": true
        },
        "input": {
            "data": {
                "mapping": {
                    "key": "=$flow.parameters.name",
                    "value": {
                        "color": "=$flow.parameters.color",
                        "docType": "marble",
                        "name": "=$flow.parameters.name",
                        "owner": "=$flow.parameters.owner",
                        "size": "=$flow.parameters.size"
                    }
                }
            }
        }
    }

This example creates a new record on the ledger using the specified state key and value. It also creates 2 composite keys of color~name and owner~name for indexed search. The request will be rejected if the specified state key already exists because createOnly is set to true.

The following example will, however, create or update multiple ledger records and the associated composite key owner~name.

    "activity": {
        "ref": "#put",
        "settings": {
            "compositeKeys": {
                "mapping": {
                    "owner~name": ["docType", "owner", "name"]
                }
            }
        },
        "input": {
            "data": {
                "mapping": {
                    "@foreach($activity[get_1].result)": {
                        "key": "=$loop.key",
                        "value": {
                            "color": "=$loop.value.color",
                            "docType": "=$loop.value.docType",
                            "name": "=$loop.value.name",
                            "owner": "=$flow.parameters.newOwner",
                            "size": "=$loop.value.size"
                        }
                    }
                }
            }
        }
    }

Create or update one or more composite keys

This operation requires one or more composite-key definition, and input data used to construct composite-keys, e.g.,

    "activity": {
        "ref": "#put",
        "settings": {
            "keysOnly": true,
            "compositeKeys": {
                "mapping": {
                    "color~name": ["docType", "color", "name"]
                }
            }
        },
        "input": {
            "data": {
                "mapping": {
                    "@foreach($activity[get_1].result)": {
                        "color": "=$loop.value.color",
                        "docType": "=$loop.value.docType",
                        "name": "=$loop.value.name"
                    }
                }
            }
        }
    }

This example will create the composite-key color~name for each of the input data records. It will not create any ledger records. This operation may be used to add search capability for existing ledger states, or used to store temperary data as composite-keys, which can be aggregated later in batches.

Create or update records on private data collection

When a private data collection is specified in the input, data will be created/updated in the specified private data collection, e.g.,

    "activity": {
        "ref": "#put",
        "input": {
            "data": {
                "mapping": {
                    "key": "=$activity[get_1].result[0].value.name",
                    "value": {
                        "docType": "marblePrivate",
                        "name": "=$activity[get_1].result[0].value.name",
                        "price": "=$flow.transient.marble.price"
                    }
                }
            },
            "privateCollection": "_implicit"
        }
    }

This example will create/update data in the client's implicit private collection, i.e., _implicit_org_<mspid>.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

New creates a new Activity

Types

type Activity

type Activity struct {
	// contains filtered or unexported fields
}

Activity is a stub for executing Hyperledger Fabric put operations

func (*Activity) Eval

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

Eval implements activity.Activity.Eval

func (*Activity) Metadata

func (a *Activity) Metadata() *activity.Metadata

Metadata implements activity.Activity.Metadata

func (*Activity) String

func (a *Activity) String() string

type Input

type Input struct {
	Data              interface{} `md:"data,required"`
	PrivateCollection string      `md:"privateCollection"`
}

Input of the activity

func (*Input) FromMap

func (i *Input) FromMap(values map[string]interface{}) error

FromMap sets activity input values from a map

func (*Input) ToMap

func (i *Input) ToMap() map[string]interface{}

ToMap converts activity input to a map

type Output

type Output struct {
	Code    int           `md:"code"`
	Message string        `md:"message"`
	Result  []interface{} `md:"result"`
}

Output of the activity

func (*Output) FromMap

func (o *Output) FromMap(values map[string]interface{}) error

FromMap sets activity output values from a map

func (*Output) ToMap

func (o *Output) ToMap() map[string]interface{}

ToMap converts activity output to a map

type Settings

type Settings struct {
	CompositeKeys map[string][]string `md:"compositeKeys"`
	KeysOnly      bool                `md:"keysOnly"`
	CreateOnly    bool                `md:"createOnly"`
}

Settings of the activity

func (*Settings) FromMap

func (h *Settings) FromMap(values map[string]interface{}) error

FromMap sets settings from a map construct composite key definition of format {"index": ["field1, "field2"]}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL