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) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/labimotion/helpers/dataset_helpers.rb', line 16

def create_repo_klass(params, current_user)
  response = Labimotion::TemplateHub.fetch_identifier('DatasetKlass', params[:identifier])
  attributes = response.slice('ols_term_id', 'label', 'desc', 'uuid', 'identifier', 'properties_release', 'version') # .except(:id, :is_active, :place, :created_by, :created_at, :updated_at)
  attributes['properties_template'] = response['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
  if Labimotion::DatasetKlass.find_by(ols_term_id: attributes['ols_term_id']).present?
    ds = Labimotion::DatasetKlass.find_by(ols_term_id: attributes['ols_term_id'])
    ds.update!(attributes)
  else
    attributes['created_by'] = current_user.id
    ds = Labimotion::DatasetKlass.create!(attributes)
  end
  ds.create_klasses_revision(current_user.id)
rescue StandardError => e
  Labimotion.log_exception(e, current_user)
  # { error: e.message }
  raise e
end

#klass_list(is_active) ⇒ Object



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

def klass_list(is_active)
  if is_active == true
    Labimotion::DatasetKlass.where(is_active: true).order('place') || []
  else
    Labimotion::DatasetKlass.all.order('place') || []
  end
end