Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Методы, которые выполняют отправку GET, POST и PUT запросов к бэкенду HydraOMS:

Code Block
languageruby
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

...

Прокси-контроллеры служат прослойкой между внешней системой и HydraOMS. Они проверяют параметры, переданные из виджета, и передают их в бэкенд HydraOMS, добавляя к ним заголовок аутентификации и другие данные, необходимые для работы стыковки.

 

Code Block
languageruby
# 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

 

...