Contents


Overview

Skill Level: Intermediate

Recommended to See Prior Tutorials

We will use Node to create a response server and access a cloud database that is set up through the Bluemix catalog. This response server will be hit and the result will be passed through HTML to BPM

Ingredients

  • IBM BPM
  • ClearDB via Bluemix
  • SDK for NodeJS via Bluemix

Step-by-step

  1. Set Up Server and DB

    ClearDB

    1. Start Via Bluemix
    2. Create a table users
    3. Add a column emailaddress
    4. Populate with some data via the console

    NodeJS

    1. Get Server running utilizing code similar to this
    var cfenv = require('cfenv'); // Our CloudFoundry Required code
    var appEnv = cfenv.getAppEnv(); // Part of our Server code required
    var pg = require('pg'); //PostgreSQL Client
    var pgp = require('pg-promise')(); //additional PostGreSQL Interfacing module
    var restify = require('restify');


    function responddatabaseemail(req, res, next) {
    //Response Printed to Browser
    //res.send('This is a database query');

    /////////////////////////////////////////StartDBInteraction
    var cn = {
    host: 'jumbo.db.elephantsql.com',
    port: 5432,
    database: 'bletrspr',
    user: 'bletrspr',
    password: 'bADZG73F28DFBs1si3roWaRz6ol'
    };


    var db = pgp(cn);
    db.query('select emailaddress from users')
    .then(function (data) {
    // success;
    res.send(data);
    })
    .catch(function (error) {
    // error;
    });
    pgp.end();


    next();
    }




    var server = restify.createServer();
    server.get('/emaildb',responddatabaseemail);
    server.listen(appEnv, function() {
    console.log('%s listening at %s', server.name, server.url);
    });

         3. Push to Bluemix

  2. BPM

    1. Start up your instance of BPM
    2. Inside a process create an implementation service called Pull and Parse DB
    3. Add rawOutput as an output of Type String
    4. Click Implementation in the Systems Data Toolkit
    5. Select Read from HTTP and drop inside the Email Pull Implementation Service
    6. Inside the URL, map it to the BluemixURL given with emaildb as the subdirectory.
      1. Ex. 'ZASDWRecipe.mybluemix.net/emaildb'
    7. Map the output of Read from HTTP to rawOutput
    8. Add all DataMapping and connect all services
    9. Create a Client Side HumanService called View Database Output
    10. In the HS add a private output called databaseOutput as type string
    11. Add your implementation service before the coach
    12. In the coach add a text box and bind it to databaseOutput
    13. map rawOutput to databaseOutput of the integration service at the clientSide.

    Screen-Shot-2016-12-11-at-12.17.00-PM

  3. Test!

    1. Run your service and ensure that it pulls all the information you need!
    2. If you have any questions reach out to me at Zachary.Silverstein@ibm.com

    NOTE PART 2 concerning parsing is located here Parsing (Part 2)

Join The Discussion