# Flow Manager

The flow manager is responsible for the overall orchestration of the various subcomponents which comprise the GPII
personalization architecture. It:

- is able to be notified by the user listener.
- queries the preferences server for user preferences.
- queries the solutions reporter for available solutions.
- communicates with the matchmaker.
- communicates with the launch manager.

## Dependencies

- [infusion](https://github.com/fluid-project/infusion) framework.

## Installation

Run the following command in your newly checked out universal repository. This will pull all dependencies that are
required by universal.

    npm install

## Flow Manager API

The app currently supports the following urls:

    // LOCAL DEPLOYMENT
    {urlToFlowManager}/user/{gpiiKey}/login // GET
    {urlToFlowManager}/user/{gpiiKey}/logout // GET

    // CLOUD BASED DEPLOYMENT
    {urlToFlowManager}/health // GET
    {urlToFlowManager}/ready // GET
    {urlToFlowManager}/revision // GET
    {urlToFlowManager}/access_token // POST
    {urlToFlowManager}/{gpiiKey}/settings/:device // GET
    // where :device is an url encoded {device: "..."} block.
    {urlToFlowManager}/{gpiiKey}/settings/ // PUT

Refer to [GPII OAuth2 Guide](https://wiki.gpii.net/w/GPII_OAuth_2_Guide) for how to use endpoints provided by the cloud
based deployment.

For example:

    {urlToFlowManager}/user/andrei/login // GET
    {urlToFlowManager}/user/andrei/logout // GET

## Cloud based flow manager

The cloud based configuration of the flow manager enables GPII installations on local computers to communicate to the
GPII architecture components and to retrieve the relevant lifecycle instructions filtered/mapped based on the user
preferences, platform and application specification. This configuration of the flow manager is intended for the GPII
apps on platforms without a locally running core framework.

The expected payload contains the lifecycle instructions for the particular solution keyed by the solution id. Those
instructions are produced by the MatchMaker that matches the supplied device/platform information along with the
solutions installed with the current preference set. These settings are transformed to be consumed by the actual
application. For example:

    {
        "http://registry.gpii.net/applications/com.texthelp.readWriteGold": {
            "ApplicationSettings.AppBar.Width.$t": 788,
            "ApplicationSettings.AppBar.ShowText.$t": true,
            "ApplicationSettings.AppBar.optToolbarShowText.$t": true,
            "ApplicationSettings.AppBar.LargeIcons.$t": true,
            "ApplicationSettings.AppBar.optToolbarLargeIcons.$t": true,
            "ApplicationSettings.Speech.optSAPI5Speed.$t": 50,
            "ApplicationSettings.Speech.optAutoUseScreenReading.$t": false
        },
        ...
    }

## Run

To run flow manager app simply type:

    [NODE_ENV={environment}] node node_modules/kettle/lib/init.js path/to/flowManager/configs/folder
    [NODE_ENV={environment}] node node_modules/kettle/lib/init.js path/to/gpii/configs/folder   // That folder contains configs for other configurations that include Flow Manager.

- Default environment is development.
- Path to configs folder can be absolute or relative to the current user directory.

For example:

    node node_modules/kettle/lib/init.js gpii/node_modules/flowManager/configs/
    NODE_ENV=production node node_modules/kettle/lib/init.js /Users/{gpiiKey}/universal/gpii/node_modules/flowManager/configs/
    NODE_ENV=gpii.config.cloudBased.flowManager.production node node_modules/kettle/lib/init.js gpii/configs/
