Config parameters
These params are used for connection third-party application to HydraOMS:
hbw_url
– HydraOMS usl (e.g., http://localhost:3000);hbw_assets_path
– url for HydraOMS static files include (usually the same ashbw_url
);hbw_login
– login (e.g., user@example.com);hbw_token
– token (e.g., renewmeplease).
Fixed parameters
These params correspond to the certain third-party application and entity type will be used by running business process:
entity_class
– integration type (e.g., billing_customer, crm_account, self_care_customer, customer_care_portal or other string value);entity_type
– entity type (e.g., customer, account, operator or other string value).
Dynamic parameters
These params correspond to the certain entity which identifier will be used for starting a business process instance:
entity_code
– unique entity identifier or code;initial_variables
– additinal variables will be set while starting a business process instance.
Helpers
The following methods need to be implemented for sending requests ted for sending GET, POST and PUT requests to the HydraOMS backend:
def get_bpm_backend(path, parameters = {}) params = request_params(path).merge( method: :get, payload: parameters ) return response(params) end def post_bpm_backend(path, parameters = {}) params = request_params(path).merge( method: :post, payload: parameters ) return response(params) end def put_bpm_backend(path, parameters = {}) params = request_params(path).merge( method: :put, payload: parameters ) return response(params) end private def response(params) response = RestClient::Request.execute(params) return { code: response.code, headers: response.headers, body: response.body } end def request_params(path) return { url: build_bpm_widget_path(path), user: configuration[:login], password: configuration[:password], headers: { 'Content-Type': 'application/json' } } end def build_bpm_widget_path(path = '') return URI.join(configuration[:url], '/widget/', path) end def configuration return { url: "http://localhost:3000", # hbw_url login: "user@example.com", # hbw_login password: "renewmeplease" # hbw_token } end def with_user_identifier(parameters) return parameters.merge( user_identifier: session[:email] # email of current user ) end def allow_params(*allowed_params) return with_user_identifier(params.slice(*allowed_params)) end
GET parameters should be passed as query part of url, e.g.:
GET /widget/tasks?user_identifier=user@example.com&entity_type=&entity_code=ORD-6&entity_class=billing_customer
;
POST and PUT parameters should be passed as body part of request.
Proxy controllers
Proxy controllers are used as an middleware for requests from third-party application to HydraOMS. They check data send by widget and pass it to HydraOMS backend with adding auth headers and other necessary information.
# Buttons controller # GET /widget/buttons def list_buttons(params) return get_bpm_backend('buttons', allow_params('entity_class', 'entity_type', 'entity_code')) end # POST /widget/buttons def start_process(params) return post_bpm_backend('buttons', allow_params('entity_class', 'entity_type', 'entity_code', 'bp_code', 'initial_variables')) end # Tasks controller # GET /widget/tasks def list_tasks(params) return get_bpm_backend('tasks', allow_params('entity_class', 'entity_code')) end # GET /widget/tasks/:id/form def fetch_task_form(params) return get_bpm_backend('tasks/#{params[:id]}/form', allow_params('entity_class', 'id')) end # PUT /widget/tasks/:id/form def save_task_form(params) return put_bpm_backend('tasks/#{params[:id]}/form', allow_params('entity_class', 'form_data', 'id')) end # GET /widget/tasks/:id/lookup def fetch_lookup_value(params) return get_bpm_backend('tasks/#{params[:id]}/lookup', allow_params('entity_class', 'name', 'q', 'id')) end # Users controller # GET /widget/users/check def check_user_access(params) return get_bpm_backend('users/check') end
Embedding JS
Here you can find an example of embedding HydraOMS widget into HTML page of third-party application. After external JS and CSS are loaded, HydraOMS widget will be initialized with application and entity data and then render()
function is being called.
<html> <head> <title>HydraOMS Widget</title> <script type="text/javascript" src="${hbw_assets_path}/assets/hbw.js"></script> <link rel="stylesheet" type="text/css" href="${hbw_assets_path}/assets/hbw.css"> </head> <body> <div id='hbw-container'></div> <script type="text/javascript"> var config = { entity_class: 'crm_account', entity_type: 'customer', container_id: 'hbw-container', // Same as <div> id locale: 'en' }; var entityId = ...; // Set here id or other uniq value of entity, like customerId window.hbw_widget = new (modulejs.require('HBW'))({ widgetContainer: `#${config.container_id}`, widgetPath: '/widget', entity_class: config.entity_class, entity_type: config.entity_type, entity_code: `${entityId}`, locale: config.locale, payload: { variables: { someInitialVariable: { // You can pass other useful information to process initial variables value: 'initialValue', type: 'string' } } } }); window.hbw_widget.render(); // If you use some kind ot SPA (Single Page Application), call this before exiting current page: // window.hbw_widget.unmountWidget(); </script> </body> </html>