Skip to content
This repository has been archived by the owner on Mar 8, 2020. It is now read-only.

Commit

Permalink
Get All/Resolve All Feature for Retrieve Action, issue #76 (#78)
Browse files Browse the repository at this point in the history
Get All/Resolve All Feature for Retrieve Action

added "get all" feature to retrieve action if payload has no id property
use getAll instead of resolveAll for retrieval of participants
added node info text for getAll/resolveAll feature

Signed-off-by: marcus <wittigmarcus@gmail.com>
  • Loading branch information
mwittig authored and cazfletch committed Apr 24, 2018
1 parent 7ad2fdf commit 50c6643
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 14 deletions.
12 changes: 6 additions & 6 deletions packages/node-red-contrib-composer/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#node-red-contrib-hyperledger-composer
# node-red-contrib-hyperledger-composer
A set of nodes for interacting with Hyperledger Composer

*Note : These node will only work if you are running node red locally. It won't work if you are using node red on bluemix.*

##Hyperledger-Composer-Out
## Hyperledger-Composer-Out
A node red output node that allows you to create, update or delete assets or participants and submit transactions.

###Example Usage
### Example Usage
This example uses the Car Auction Sample Network that can be obtained from [here](https://github.com/hyperledger/composer-sample-networks/tree/master/packages/carauction-network)

The Car Auction Sample, simulates a car auction. It has two kinds of participant. An Auctioneer, who is responsible for conducting the auction, and a member who can bid on cars in the auction.
Expand All @@ -26,10 +26,10 @@ In this example we will create a participant, the participant .

5. Using the playground or command line you should now be able to see the participant that has been created.

##Hyperledger-Composer-Mid
## Hyperledger-Composer-Mid
A node red mid flow node that allows you to create, retrieve, update, or delete assets and participants from a registry.

###Example Usage
### Example Usage
This example follows on from the above example. It will retrieve the participant that was created above.

1. Create a `hyperledger-composer-mid node`
Expand All @@ -44,7 +44,7 @@ This example follows on from the above example. It will retrieve the participant

4. Use a `debug node` to capture the output from the `hyperledger-composer-mid node`

##Hyperledger-Composer-In
## Hyperledger-Composer-In
A node red input node that subscribes to events from a blockchain

1. On `Composer Card` click the pencil top add a new config node. Specify the `card name`, or use the drop down to use one previous created.
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@
<p>Hyperledger-Composer node. Gets an asset, or participant using the <code>msg.payload</code>.</p>
<p>The name of the resource or transaction should be set in <code>msg.payload.$class</code></p>
<p>The id of the resource should be set in <code>msg.payload.id</code></p>
<p>If <code>msg.payload.id</code> is not set and the action type is set to <code>retrieve</code>,
all resources of the given type <code>msg.payload.$class</code> will be retrieved. Additionally,
all resources will be resolved if the <code>retrieve</code> checkbox is checked.</p>
</script>

<script type="text/javascript">
Expand Down
34 changes: 26 additions & 8 deletions packages/node-red-contrib-composer/nodes/hyperledger-composer.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,19 @@ module.exports = function (RED) {
node.log('got asset registry');

if (resolve) {
return assetRegistry.resolve(id);
if (id == null) {
return assetRegistry.resolveAll();
}
else {
return assetRegistry.resolve(id);
}
} else {
if (id == null) {
return assetRegistry.getAll();
}
else {
return assetRegistry.get(id);
}
}
})
.then((result) => {
Expand All @@ -213,7 +223,21 @@ module.exports = function (RED) {
return businessNetworkConnection.getParticipantRegistry(modelName)
.then((participantRegistry) => {
node.log('got participant registry');
return participantRegistry.get(id);
if (resolve) {
if (id == null) {
return participantRegistry.resolveAll();
}
else {
return participantRegistry.resolve(id);
}
} else {
if (id == null) {
return participantRegistry.getAll();
}
else {
return participantRegistry.get(id);
}
}
})
.then((result) => {
node.log('got participant');
Expand Down Expand Up @@ -379,12 +403,6 @@ module.exports = function (RED) {
if (!payLoad.$class) {
throw new Error('$class not set in payload');
}

if (type === RETRIEVE) {
if (!payLoad.id) {
throw new Error('id not set in payload');
}
}
});
}

Expand Down

0 comments on commit 50c6643

Please sign in to comment.