Значение параметров запросов:
hbw_url
– адрес HOMS(http://localhost:3002);
hbw_assets_path
– адрес статичесаких файлов HOMS;
hbw_login
– fs (user@example.com);
hbw_token
– токен (renewmeplease);entity_class
– идентификатор интеграции (указывается в конфиге);
entity_type
– тип заказа (указывакется в конфиги или в месте монтирования);
entity_code
– уникальный код для создания заказа;
bp_code
– код заказа;
initial_variables
– параматеры, с которыми создается бизнес-процесс.
Прокси-контроллер служит прослойкой между внешней системой и HOMS, где задаются необходимые параметры для работы с заказами и идентификации пользователя.
Необходимо разработать следующие методы:
GET,
POST и PUT
запросы в бэкенд HOMS:GET
запросы должны задаваться в заголовке запроса;POST и PUT
запросы должны задаваться в тело запроса.def get_request_bpm_backend(path, parameters = {}) params = request_params(path).merge( method: :get, headers: { params: parameters } ) rest_rack_response(params) end def post_request_bpm_backend(path, parameters = {}) params = request_params(path).merge( method: :post, payload: parameters ) rest_rack_response(params) end def put_request_bpm_backend(path, parameters = {}) params = request_params(path).merge( method: :put, payload: parameters ) rest_rack_response(params) end private def rest_rack_response(params) response = RestClient::Request.execute(params) [response.code, response.headers, [response.body]] end def request_params(path) { url: build_bpm_widget_path(path), user: configuration[:login], password: configuration[:password] } end def build_bpm_widget_path(path = '') URI.join(configuration[:url], '/widget/', path).to_s end |
где
configuration: { url: App[:config]['system']['hbw_url'], login: App[:config]['system']['hbw_login'], password: App[:config]['system']['hbw_token'] } |
def with_user_identifier(parameters) parameters.merge( 'user_identifier' => Lib::GetSession.(params[:payload][:token])[:session][:email] ) end def allow_params(*allowed_params) with_user_identifier(params.slice(*allowed_params)) end |
метод, который делает запрос для получений (GET) кнопок для начала бизнес-процесса, необходимые параметры: entity_class, entity_type, entity_code
BPMConnector.call.get_request_bpm_backend('buttons', allow_params('entity_class', 'entity_type', 'entity_code')) |
BPMConnector.call.post_request_bpm_backend('buttons', allow_params('entity_class', 'entity_type', 'entity_code', 'bp_code', 'initial_variables')) |
методы для работы с формами заказа
GET
запрос c параметрами entity_class
, entity_code
:
BPMConnector.call.get_request_bpm_backend('tasks', allow_params('entity_class', 'entity_code')) |
GET
запрос c параметрами entity_class
, id
:BPMConnector.call.get_request_bpm_backend("tasks/#{params[:id]}/form", allow_params('entity_class', 'id')) |
entity_class
, form_data
, id
BPMConnector.call.put_request_bpm_backend("tasks/#{params[:id]}/form", allow_params('entity_class', 'form_data', 'id')) |
получение информации для лукапов – GET
запрос с параметрами entity_class
, name, q
, id
BPMConnector.call.get_request_bpm_backend("tasks/#{params[:id]}/lookup", allow_params('entity_class', 'name', 'q', 'id')) |
BPMConnector.call.get_request_bpm_backend('users/check') |
Включить в HTML страницы внешней системы JS и CSS виджета:
<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"> |
render
у объекта виджета:this.widget = new (modulejs.require('HBW'))({ widgetContainer: `#${this.widgetContainerId}`, widgetPath: '/widget', entity_class: 'your_entity_class', entity_type: 'operator', entity_code: `${id}`, locale: i18n.language, payload: { token: cookies.get('token'), variables: { id: { value: `${id}`, type: 'string', }, }, }, }); this.widget.render(); |