-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ac5fe21
commit 28048d5
Showing
3 changed files
with
163 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,130 @@ This .zip file is necessary to carry on with this example and those are availabl | |
- [**phycusTeselagenNodeRed.zip**](https://raw.githubusercontent.com/TeselaGen/fsml.org/main/website/static/phycus-tg-nodered-example-01.zip) | ||
|
||
|
||
## Node-RED Server | ||
|
||
In order to get started with using Node-RED flows you will need a Node-RED server running. | ||
|
||
TeselaGen offers one such server at https://biomade.teselagen.com/node-red-editor to all Biomade members logged into TeselaGen. | ||
|
||
_NOTE: If you are a Biomade member looking to get an account to the app feel free to contact the TeselaGen Team at [email protected]._ | ||
## Node-RED Flow | ||
|
||
Included in the [**phycusTeselagenNodeRed.zip**](https://raw.githubusercontent.com/TeselaGen/fsml.org/main/website/static/phycus-tg-nodered-example-01.zip) file you will find the Node-RED Flow JSON file called `phycus-teselagen-flow.json` that you can import into any Node-RED editor as new Node-Red flow. The flow should like the following screenshot: | ||
|
||
 | ||
|
||
|
||
As you can observe, the Flow is pretty simple with just a few functional nodes and I/O http ones. | ||
|
||
The first function node (FSML --> TG) contains code that imports an npm package called [tgExporter](https://www.npmjs.com/package/tg-exporter) that exports an [FSML Plugin Exporter](/software/plugins/exporter). It takes in an FSML Manifest and returns a TeselaGen Data Grid _(a data grid in TeselaGen is a an object specific to TeselaGen used to represent data as data cells)_. | ||
|
||
```javascript | ||
/** FSML --> TG Node-Red Function Node. **/ | ||
|
||
// Imports the tgExporter public npm package which exports an FSML Plugin Exporter | ||
const tgExporter = global.get("tgExporter") | ||
|
||
const { manifest } = msg.payload | ||
|
||
msg.payload = tgExporter.run(manifest) | ||
|
||
return msg; | ||
``` | ||
|
||
The second functional node called `Prepare Data grid Body` is just TeselaGen specific code to format the body request of a POST /data-grids endpoint to create a Data Grid in TeselaGen's TEST Module app. | ||
|
||
## FSML TeselaGen Exporter Plugin | ||
|
||
The first function node in the above flow, imports the `tgExporter` npm package. This publicly available and works by generating a TeselaGen Data Grid by parsing any FSML data manifest. The implementation of such Exporter can be seen below: | ||
|
||
<details> | ||
<summary>TeselaGen's FSML Plugin Exporter</summary> | ||
|
||
```javascript | ||
|
||
import * as fs from 'fs'; | ||
import lodash from 'lodash'; | ||
import * as fsml_utils from 'fsml-utils'; | ||
import * as fsml_standard from 'fsml-standard'; | ||
import papaparse from 'papaparse'; | ||
|
||
const { get, flatMap } = lodash; | ||
|
||
const tgExporter = { | ||
name: 'tgExporter', | ||
type: 'exporter', | ||
run: (manifest) => { | ||
|
||
// Leverages the FSML SDK to validate the provided manifest object. | ||
const { isValid } = fsml_utils.validateType( | ||
fsml_standard.Manifest, | ||
manifest | ||
); | ||
if (!isValid) throw new Error('Invalid FSML manifest'); | ||
const manifestRows = get(manifest, 'supplementalInfo.data[0].rows'); | ||
|
||
const dataRows = manifestRows.map((row) => | ||
row.values.map((rowValue) => rowValue.value) | ||
); | ||
|
||
const dataGridCells = flatMap( | ||
dataRows.map((dataRow, rowPosition) => | ||
dataRow.map((cellValue, columnPosition) => ({ | ||
rowPosition, | ||
columnPosition, | ||
value: cellValue, | ||
})) | ||
) | ||
); | ||
|
||
const dataGrid = { | ||
name: 'fsml-datagrid', | ||
dataCells: dataGridCells, | ||
}; | ||
|
||
const csvData = papaparse.unparse(dataRows); | ||
|
||
const csvDataBuffer = Buffer.from(csvData, 'utf-8'); | ||
|
||
return { data: dataGrid, file: csvDataBuffer }; | ||
}, | ||
}; | ||
|
||
export default tgExporter; | ||
``` | ||
|
||
</details> | ||
|
||
The above implementation leverages the FSML SDK for validation and parsing of an FSML Manifest file. The SDK is distributed into the following publicly available npm packages: | ||
|
||
- [fsml-standard](https://www.npmjs.com/package/fsml-standard) | ||
* Exports all the FSML manifest schemas to build different parts of the FSML manifest. | ||
- [fsml-plugins](https://www.npmjs.com/package/fsml-plugins) | ||
* Exports some typing functions for easier implementation of different FSML Plugins, mostly beneficial for TypeScript developers. | ||
- [fsml-utils](https://www.npmjs.com/package/fsml-utils) | ||
* Exports several utility function to work with FSML, such as the `validateType` and `createTemplateForType` functions | ||
|
||
|
||
## Import FSML into TeselaGen | ||
|
||
Finally, we are going to trigger the above Node-RED flow to get the FSML Phycus manifest into a TeselaGen Data Grid. Since Node-RED flows are essentially HTTP endpoints, we can trigger them with any kind of tool that allows calling http requests. If you are a Biomade member you can leverage TeselaGen's Biomade app, if not you can hit the endpoint of any Node-RED server you might have access to. | ||
|
||
The next steps of the example are for Biomade members only. | ||
|
||
### Log into the Teselaegn Biomade app | ||
|
||
Head to https://biomade.teselagen.com and log in with your credentials _(if you are a Biomade member and don't own an account, contact [email protected] to get one)_. | ||
|
||
|
||
After logging into the app, head to [Setting > Intergations](https://biomade.teselagen.com/test/client/settings/integrations-management), you shall see the Integrations Management Panel, where you can upload an existing Integration. Included in the [**phycusTeselagenNodeRed.zip**](https://raw.githubusercontent.com/TeselaGen/fsml.org/main/website/static/phycus-tg-nodered-example-01.zip) file you should find a JSON file called `phycus-teselagen-integration.json` that you can use to uploading in the `Upload Existing` button shown below. | ||
|
||
|
||
 | ||
|
||
After so, and if you scroll down to the `API Integration` subsection you shall a see a new TeselaGen Integration called `fsml` as shown here. | ||
|
||
 | ||
|
||
|
||
The TeselaGen app runs its own dedicated Node-RED Server, you can open its Node-RED editor and look at the Node-RED flow by clicking in the View in Node Red button shown above, which should take you the same Node-RED flow explained at the beginning. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.