To integrate the HBW widget in an external system, you need to:
make proxy controllers through which the built-in widget will make requests to the HOMS backend with basic authentication (using the password and login from the config);
build in JS widget and render it.
...
Config parameters
These params are used for connection third-party application to HydraOMS:
hbw_url
– HOMS url HydraOMS usl (e.g. , http://localhost:3002, from config file3000);hbw_assets_path
– address to HOMS url for HydraOMS static files HOMS (from config fileinclude (usually the same ashbw_url
);hbw_login
– login (e.g. user@example, user@example.com, from config file);hbw_token
– token – token (e.g. renewmeplease, from config file renewmeplease); entity- .
Fixed parameters
These params correspond to the certain third-party application and entity type will be used by running business process:
entity_class
– integration name (from config filetype (e.g., billing_customer, crm_account, self_care_customer, customer_care_portal or other string value);entity_type – entity type – order type (specified in the config file or mount location);entity(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 code to create an order;bp_code
– business process code;entity identifier or code;
initial_variables
– the parameters with which the business process is created.
Proxy controllers
Proxy controller is a intermediary for requests from external systems to HOMS, where the necessary parameters for working with orders and user authentication are set
additinal variables will be set while starting a business process instance.
Helpers
The following methods need to be developed:
- methods, which make
GET
,POST
andPUT
requests to HOMS backend:- parameters that are passed to the
GET
requests must be specified in the request url, e.g.GET /widget/tasks?user_identifier=user@example.com&entity_type=&entity_code=ORD-6&entity_class=billing_customer
; - parameters that are are passed to the
POST
andPUT
requests must be specified in the request body.
- parameters that are passed to the
...
implemented for sending requests ted for sending GET, POST and PUT requests to the HydraOMS backend:
Code Block |
---|
def get_bpm_backend(path, parameters = {}) params = request_params(path).merge( method: :get, headers: { params: payload: parameters } ) rest_rack_return response(params) end def post_request_bpm_backend(path, parameters = {}) params = request_params(path).merge( method: :post, payload: parameters ) rest_rack_return response(params) end def put_request_bpm_backend(path, parameters = {}) params = request_params(path).merge( method: :put, payload: parameters ) rest_rack_return response(params) end private def rest_rack_response(params) response = RestClient::Request.execute(params) return { [code: response.code, headers: response.headers, [response.body]] body: response.body end } end def request_params(path) return { url: build_bpm_widget_path(path), user: configuration[:login], password: configuration[:password], headers: { } 'Content-Type': 'application/json' end } } end def build_bpm_widget_path(path = '') return URI.join(configuration[:url], '/widget/', path).to_s end def configuration end |
where
Code Block |
---|
configuration:return { url: "http://localhost:3002/3000", (# hbw_url), login: "user@example.com", login: # user@example.com (hbw_login), password: "renewmeplease" password: renewmeplease ( # hbw_token) } |
- method in which the user id is added to all request parameters to HOMS
Code Block |
---|
} end def with_user_identifier(parameters) return parameters.merge( 'user_identifier' => GetSession.(params[:payload][:token])[:session]: session[:email] # email of current user ) end def allow_params(*allowed_params) return with_user_identifier(params.slice(*allowed_params)) end |
- methods that work with start buttons of a business process
method that makes a request to get (GET request) buttons to start a business process, the necessary parameters: entity_class, entity_type, entity_code
...
title | get /widget/buttons |
---|
...
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 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.
Code Block | ||
---|---|---|
| ||
# Buttons controller
# GET /widget/buttons
def list_buttons(params)
return get_bpm_backend('buttons', allow_params('entity_class', 'entity_type', 'entity_code')) |
- method that starts a business process
Code Block | ||
---|---|---|
title | postend # POST /widget/buttons | def start_process(params) return post_request_bpm_backend('buttons', allow_params('entity_class', 'entity_type', 'entity_code', 'bp_code', 'initial_variables')) |
- methods for working with order forms
- receiving all orders –
GET
request with parametersentity_class
,entity_code
:
- receiving all orders –
Code Block | ||
---|---|---|
| ||
get_request_ end # Tasks controller # GET /widget/tasks def list_tasks(params) return get_bpm_backend('tasks', allow_params('entity_class', 'entity_code')) |
- getting the current order form –
GET
request with parametersentity_class
,id
:
- getting the current order form –
Code Block | ||
---|---|---|
title | getend # GET /widget/tasks/:id/form | def fetch_task_form(params) return get_request_bpm_backend("'tasks/#{params[:id]}/form"', allow_params('entity_class', 'id')) |
- update the current order form –
PUT
request with parametersentity_class
,form_data
,id
- update the current order form –
Code Block | ||
---|---|---|
title | putend # PUT /widget/tasks/:id/form | def save_task_form(params) return put_request_bpm_backend("'tasks/#{params[:id]}/form"', allow_params('entity_class', 'form_data', 'id')) |
getting information for lookup –
GET
request with parametersentity_class
, name,q
,id
Code Block | ||
---|---|---|
title | getend # GET /widget/tasks/:id/lookup | def fetch_lookup_value(params) return get_request_bpm_backend("'tasks/#{params[:id]}/lookup"', allow_params('entity_class', 'name', 'q', 'id')) |
- method for checking user rights.
Code Block | ||
---|---|---|
title | end # Users controller # GET /widget/users | /check def check_user_access(params) return get_request_bpm_backend('users/check') end |
Embedding JS
...
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.
Code Block | |||||
---|---|---|---|---|---|
| |||||
<html> <head> <title>HydraOMS Widget</title> <script type="text/javascript" src="<%= '\<\%\= ${hbw_assets_path \%\>' %>assets/}/assets/hbw.js"></script> <link reluser_identifierrel="stylesheet" type="text/css" href="<%= '\<\%\= ${hbw_assets_path \%\>' %>assets/}/assets/hbw.css"> |
Add to the <div>
page with a unique ID, for example, bpmWidgetContainer
, so the widget is rendered.
Call the render function on the widget object:
Code Block | ||||
---|---|---|---|---|
| ||||
this.</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: `#${thisconfig.widgetContainerIdcontainer_id}`, widgetPath: '/widget', entity_class: 'your_config.entity_class', entity_type: 'operator'config.entity_type, entity_code: `${identityId}`, locale: i18nconfig.languagelocale, payload: { tokenvariables: cookies.get('token'),{ variablessomeInitialVariable: { // You can pass other useful information to process initial variables id: { value: `${id}`'initialValue', type: 'string', } }, } },); window.hbw_widget.render(); } // If you use some kind ot SPA, call this before page unmount: }); this. // window.hbw_widget.renderunmountWidget(); </script> </body> </html> |