OL Learn

Sample Flows available

Hi,

are there some sample flows, like typical print/web etc. available?

1 Like

Not yet, but we’re planning on making some available as development progresses.

1 Like

Hi Phil,
Any new sample workflows you can share, just a taste would be good!! A simple csv upload to all-in-one to output a pdf.

The following is a basic example showing how to show a PDF generated by a Connect template in your browser. The flow consists of three nodes: http in, preview pdf, http response

node-red-serve-pdf-travel-flow

The following assumes you run everything on your local machine (Node-RED and OL Connect software).

The flow
To install the sample flow:

  1. Copy the JSON data below.
  2. Launch your browser and visit your Node-RED editor (prob sitting here: http://localhost:1880)
  3. Choose Import from the menu in the upper right corner (the ‘hamburger’-icon).
  4. Paste the JSON data in the textarea and click Import. This adds the flow to your editor.

node-red-serve-pdf-travel-import

The preview pdf node will show a red error triangle because it doesn’t have a Connect Server configured. Double click the node and make sure it refers to your Connect Server configuration. It requires the URL to your OL Connect Server (by default on port 9340, for example http://localhost:9340) and the credentials of the account you created on the installation of OL Connect.

People running Node-RED in a Docker Container would need to replace ‘localhost’ with the IP address of the machine running the OL Connect Server software (in my case http://192.168.2.206:9340). This would approachj would also work for users that installed Node-RED using the OL Connect Node-RED stack installer.

The Connect template
The preview node refers to the travel.OL-template but where do I put it? Well… you will need to upload the sample template to the Connect Server first in order for it to work. One way to achieve this is via OL Connect Designer (it can be automated using a Startup flow but let’s take one step at a time :slight_smile: ):

  1. Open the travel.OL-template in Connect Designer.
  2. Choose Send to Server option from the File menu.
  3. Select your Connect Server at the bottom (by default this runs on http://localhost:9340).
  4. Click Send, this will upload the template straight to the File Store of the Connect Server.

Testing the flow
Click the Deploy button in the upper right corner of the Node-RED interface to send the flow to the Node-RED server.

The flow can be triggered in your web browser via:
http://localhost:1880/travel

You can even pass data via URL parameters: http://localhost:1880/travel?first=Peter. These parameters are captured in msg.payload, which is one of the data sources of the preview pdf node. It will feed the data straight into the Data Model of the template.

Guess that wraps it up.

Hope this is of some help,

Erik

travel.OL-template (3.4 MB)

[{"id":"4c559303926269c0","type":"http in","z":"52848583.0ca234","name":"","url":"/travel","method":"get","upload":false,"swaggerDoc":"","x":130,"y":600,"wires":[["392069e2f1b157e7"]]},{"id":"392069e2f1b157e7","type":"olcnr-preview-pdf","z":"52848583.0ca234","connect_server":"","template":"travel.OL-template","x":310,"y":600,"wires":[["e24fdfaa90386c4a"]]},{"id":"e24fdfaa90386c4a","type":"http response","z":"52848583.0ca234","name":"","statusCode":"","headers":{},"x":470,"y":600,"wires":[]}]

A flow to process an uploaded .csv file (POST) via the all-in-one could look something like the one below (left in some Debug steps).

Handling the uploaded file
It takes an uploaded csv file and writes this to the Connect File Store using the file upload node. This node returns the ID of the data file in msg.managedFileId.

When the http in node receives files the information and data is stored in msg.req.files. The change node moves the data of the first file to msg.payload (e.g. moves req.files[0].buffer to msg.payload) and stores the original name of the file in msg.basename (e.g. moves req.files[0].originalname to msg.basename). Sounds a bit heavy but the beauty of this approach is that it doesn’t leave a temp file on disk.

node-red-http-in-files

The file upload node is designed to either take buffer data from msg.payload or a file path in msg.filename. In this case we use the first approach so we don’t need to create a temp file and cleanup after we’re done.

Creating and downloading the output
The all-in-one node takes ID to load the data from the File Store. Once the output is ready the all-in-one node returns the ID of the output data in msg.managedFileId, the file is sitting in the Connect File Store. The file download node downloads the respective file and returns it to the http response node for download.

Sample files
Below the flow in JSON format and the template, datamapper and output preset. Use the Node-RED Import feature to add it to your flow and use Send to Server option of Connect Designer to upload the Connect resources to Connect Server.

Connect resources

Node-RED flow
[{"id":"7bd0cfc21a11cae7","type":"http in","z":"2836ae56.a71f42","name":"","url":"/csv","method":"post","upload":true,"swaggerDoc":"","x":140,"y":620,"wires":[["de58e80989760d50","335c3277e0bd2547"]]},{"id":"c20c0b3d4762e899","type":"http response","z":"2836ae56.a71f42","name":"","statusCode":"","headers":{},"x":1070,"y":620,"wires":[]},{"id":"ac19660f778f5c2a","type":"olcnr-file-upload","z":"2836ae56.a71f42","connect_server":"","filename":"","fileDuration":"temporary","name":"","x":550,"y":620,"wires":[["011077ee9ae5adf4","7d1ddbc6d3c64311"]]},{"id":"de58e80989760d50","type":"change","z":"2836ae56.a71f42","name":"","rules":[{"t":"move","p":"req.files[0].buffer","pt":"msg","to":"payload","tot":"msg"},{"t":"move","p":"req.files[0].originalname","pt":"msg","to":"basename","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":620,"wires":[["ac19660f778f5c2a","29423788e2425946"]]},{"id":"011077ee9ae5adf4","type":"olcnr-all-in-one","z":"2836ae56.a71f42","connect_server":"","dmConfiguration":"travel.csv.OL-datamapper","template":"travel.OL-template","jobPreset":"","outputPreset":"pdf.OL-outputpreset","dataStorage":"none","name":"","x":740,"y":620,"wires":[["ded88a64c7cf7cab","23b02cdeb3e9672e","6b639cd020e27ba9"]]},{"id":"ded88a64c7cf7cab","type":"olcnr-file-download","z":"2836ae56.a71f42","connect_server":"","managedFileId":"","name":"","outputType":"buffer","x":930,"y":620,"wires":[["c20c0b3d4762e899"]]},{"id":"23b02cdeb3e9672e","type":"debug","z":"2836ae56.a71f42","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":930,"y":520,"wires":[]},{"id":"6b639cd020e27ba9","type":"debug","z":"2836ae56.a71f42","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"managedFileId","targetType":"msg","statusVal":"","statusType":"auto","x":950,"y":560,"wires":[]},{"id":"7d1ddbc6d3c64311","type":"debug","z":"2836ae56.a71f42","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"managedFileId","targetType":"msg","statusVal":"","statusType":"auto","x":770,"y":680,"wires":[]},{"id":"29423788e2425946","type":"debug","z":"2836ae56.a71f42","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"basename","targetType":"msg","statusVal":"","statusType":"auto","x":560,"y":560,"wires":[]},{"id":"335c3277e0bd2547","type":"debug","z":"2836ae56.a71f42","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"req.files[0]","targetType":"msg","statusVal":"","statusType":"auto","x":340,"y":680,"wires":[]}]

Thanks Eric for the samples. I will get them downloaded and play with them.
Much appreciated!
Jim

No problem, let me know how things go. I’m currently using Node-RED + Connect as the backend for an online solution, so in the middle of this stuff.