Module: Labimotion::DatasetHelpers

Extended by:
Grape::API::Helpers
Defined in:
lib/labimotion/helpers/dataset_helpers.rb

Overview

DatasetHelpers

Instance Method Summary collapse

Instance Method Details

#create_repo_klass(params, current_user, origin) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/labimotion/helpers/dataset_helpers.rb', line 18

def create_repo_klass(params, current_user, origin)
  response = Labimotion::TemplateHub.fetch_identifier('DatasetKlass', params[:identifier], origin)
  attributes = response.slice('ols_term_id', 'label', 'desc', 'uuid', 'identifier', 'properties_release', 'version', 'metadata') # .except(:id, :is_active, :place, :created_by, :created_at, :updated_at)
  attributes['properties_release']['identifier'] = attributes['identifier']
  attributes['properties_template'] = attributes['properties_release']
  attributes['place'] = ((Labimotion::DatasetKlass.all.length * 10) || 0) + 10
  attributes['is_active'] = false
  attributes['updated_by'] = current_user.id
  attributes['sync_by'] = current_user.id
  attributes['sync_time'] = DateTime.now
  dataset_klass = Labimotion::DatasetKlass.find_by(ols_term_id: attributes['ols_term_id'])
  if dataset_klass.present?
    if dataset_klass['uuid'] == attributes['uuid'] && dataset_klass['version'] == attributes['version']
      { status: 'success', message: "This dataset: #{attributes['label']} has the latest version!" }
    else
      ds = Labimotion::DatasetKlass.find_by(ols_term_id: attributes['ols_term_id'])
      ds.update!(attributes)
      ds.create_klasses_revision(current_user)
      { status: 'success',
        message: "This dataset: [#{attributes['label']}] has been upgraded to the version: #{attributes['version']}!" }
    end
  else
    attributes['created_by'] = current_user.id
    ds = Labimotion::DatasetKlass.create!(attributes)
    ds.create_klasses_revision(current_user)
    { status: 'success',
      message: "The dataset: #{attributes['label']} has been created using version: #{attributes['version']}!" }
  end
rescue StandardError => e
  Labimotion.log_exception(e, current_user)
  # { error: e.message }
  raise e
end

#find_best_match_template(ols_term_id) ⇒ Object



52
53
54
55
56
57
58
59
# File 'lib/labimotion/helpers/dataset_helpers.rb', line 52

def find_best_match_template(ols_term_id)
  result = Labimotion::TemplateMatcher.find_best_match(ols_term_id)
  if result[:template]
    build_template_response(result[:template], result[:match_type], result[:info_messages])
  else
    { error: '', data: {}, info: "No matching template found for term id [#{ols_term_id}]" }
  end
end

#klass_list(is_active, displayed_in_list = false) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/labimotion/helpers/dataset_helpers.rb', line 9

def klass_list(is_active, displayed_in_list = false)
  scope = displayed_in_list ? Labimotion::DatasetKlass.for_list_display : Labimotion::DatasetKlass.all
  if is_active == true
    scope.where(is_active: true).order('place') || []
  else
    scope.order('place') || []
  end
end