Class: Labimotion::VocabularyHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/labimotion/libs/vocabulary_handler.rb

Class Method Summary collapse

Class Method Details

.load_all_vocabulariesObject



63
64
65
66
67
# File 'lib/labimotion/libs/vocabulary_handler.rb', line 63

def self.load_all_vocabularies
  file_data = load_from_files
  db_data = load_from_database
  file_data + db_data
end

.load_app_vocabulariesObject



69
70
71
# File 'lib/labimotion/libs/vocabulary_handler.rb', line 69

def self.load_app_vocabularies
  load_from_files
end

.update_vocabularies(properties, current_user, element) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
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
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/labimotion/libs/vocabulary_handler.rb', line 6

def self.update_vocabularies(properties, current_user, element)
  properties[Labimotion::Prop::LAYERS].keys.each do |key|
    layer = properties[Labimotion::Prop::LAYERS][key]
    field_vocabularies = layer[Labimotion::Prop::FIELDS].select { |ss| ss['is_vocabulary'] == true && ss['opid'] == 9}
    field_vocabularies.each do |field|
      idx = properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS].index(field)
      val = ''
      orig_val = properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx]['value']
      case field['source']
      when 'System'
        val = Time.now.strftime('%d/%m/%Y %H:%M') if field['identifier'] == 'dateTime.update'
        val = Time.now.strftime('%d/%m/%Y %H:%M') if field['identifier'] == 'dateTime.create' && orig_val.blank?
      when 'User'
        val = current_user.name if field['identifier'] == 'user.name' && current_user.present?
      when 'Element'
        val = element.id.to_s if field['identifier'] == 'element.id'
        val = element.short_label if element.has_attribute?(:short_label) && field['identifier'] == 'element.short_label'
      when 'Segment'
        segments = element.segments.joins(:segment_klass).find_by('segment_klasses.identifier = ?', field['source_id'])
        next if segments.nil?

        seg_prop = segments.properties
        fields = seg_prop[Labimotion::Prop::LAYERS][field['layer_id']][Labimotion::Prop::FIELDS].select { |ss| ss['field'] == field['field_id'] }
        val = fields.first['value']
      when 'Dataset'
        byebug
      end
      # case field['identifier']
      # when 'dateTime.now'
      #   val = Time.now.strftime('%d/%m/%Y %H:%M')
      # when 'user.name'
      #   val = current_user.name
      # when 'element.id'
      #   val = element.id.to_s
      # when 'element.short_label'
      #   val = element.short_label
      # end
      # ontology = {
      #   id: "ncit:class:http://purl.obolibrary.org/obo/#{field['term_id']}",
      #   iri: "http://purl.obolibrary.org/obo/#{field['term_id']}",
      #   type: "class",
      #   label: field['name'],
      #   obo_id: field['term_id'],
      #   short_form: field['term_id'],
      #   description: field['label'],
      # }
      # properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx]['ontology'] = ontology if ontology.present?
      properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx]['value'] = val if val.present?
      ## properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx]['placeholder'] = val if val.present?
    end
  end
  properties
rescue StandardError => e
  Labimotion.log_exception(e, current_user)
  properties
end