labimotion 0.3.3 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/lib/labimotion/api.rb +19 -0
  3. data/lib/labimotion/apis/generic_dataset_api.rb +3 -4
  4. data/lib/labimotion/apis/generic_element_api.rb +8 -56
  5. data/lib/labimotion/apis/labimotion_hub_api.rb +4 -13
  6. data/lib/labimotion/apis/segment_api.rb +3 -4
  7. data/lib/labimotion/entities/element_entity.rb +0 -1
  8. data/lib/labimotion/entities/generic_public_entity.rb +0 -2
  9. data/lib/labimotion/helpers/dataset_helpers.rb +6 -14
  10. data/lib/labimotion/helpers/element_helpers.rb +10 -30
  11. data/lib/labimotion/helpers/generic_helpers.rb +13 -13
  12. data/lib/labimotion/helpers/segment_helpers.rb +8 -20
  13. data/lib/labimotion/libs/converter.rb +27 -53
  14. data/lib/labimotion/libs/export_dataset.rb +3 -8
  15. data/lib/labimotion/libs/nmr_mapper.rb +15 -39
  16. data/lib/labimotion/libs/nmr_mapper_repo.rb +278 -0
  17. data/lib/labimotion/libs/template_hub.rb +4 -8
  18. data/lib/labimotion/models/concerns/attachment_converter.rb +9 -10
  19. data/lib/labimotion/models/concerns/datasetable.rb +1 -1
  20. data/lib/labimotion/models/concerns/segmentable.rb +4 -3
  21. data/lib/labimotion/models/concerns/workflow.rb +0 -9
  22. data/lib/labimotion/models/element.rb +8 -17
  23. data/lib/labimotion/models/element_klass.rb +8 -0
  24. data/lib/labimotion/models/segment_klass.rb +0 -2
  25. data/lib/labimotion/{collection → utils}/export.rb +1 -32
  26. data/lib/labimotion/{collection → utils}/import.rb +71 -53
  27. data/lib/labimotion/version.rb +3 -7
  28. data/lib/labimotion.rb +2 -5
  29. metadata +10 -10
  30. data/lib/labimotion/models/hub_log.rb +0 -8
  31. data/lib/labimotion/utils/import_utils.rb +0 -116
@@ -7,12 +7,10 @@ module Labimotion
7
7
  class Element < ApplicationRecord
8
8
  acts_as_paranoid
9
9
  self.table_name = :elements
10
- include PgSearch if Labimotion::IS_RAILS5 == true
11
- include PgSearch::Model if Labimotion::IS_RAILS5 == false
10
+ include PgSearch::Model
12
11
  include ElementUIStateScopes
13
12
  include Collectable
14
13
  ## include AnalysisCodes
15
- include ElementCodes
16
14
  include Taggable
17
15
  include Workflow
18
16
  include Segmentable
@@ -59,7 +57,7 @@ module Labimotion
59
57
 
60
58
 
61
59
  def attachments
62
- Attachment.where(attachable_id: self.id, attachable_type: self.class.name)
60
+ Attachment.where(attachable_id: self.id, attachable_type: 'Element')
63
61
  end
64
62
 
65
63
  def self.get_associated_samples(element_ids)
@@ -101,20 +99,13 @@ module Labimotion
101
99
  end
102
100
 
103
101
  def thumb_svg
104
- if Labimotion::IS_RAILS5 == true
105
- image_atts = attachments.select do |a_img|
106
- a_img&.content_type&.match(Regexp.union(%w[jpg jpeg png tiff tif]))
107
- end
108
-
109
- attachment = image_atts[0] || attachments[0]
110
- preview = attachment.read_thumbnail if attachment
111
- preview && Base64.encode64(preview) || 'not available'
112
- else
113
- image_atts = attachments.select(&:type_image?)
114
- attachment = image_atts[0] || attachments[0]
115
- preview = attachment&.read_thumbnail
116
- (preview && Base64.encode64(preview)) || 'not available'
102
+ image_atts = attachments.select do |a_img|
103
+ a_img&.content_type&.match(Regexp.union(%w[jpg jpeg png tiff tif]))
117
104
  end
105
+
106
+ attachment = image_atts[0] || attachments[0]
107
+ preview = attachment.read_thumbnail if attachment
108
+ preview && Base64.encode64(preview) || 'not available'
118
109
  end
119
110
 
120
111
 
@@ -23,5 +23,13 @@ module Labimotion
23
23
  )
24
24
  end
25
25
 
26
+ def migrate_workflow
27
+ return if properties_template.nil? || properties_release.nil?
28
+
29
+ return if properties_template['flow'].nil? && properties_release['flow'].nil?
30
+
31
+ update_column(:properties_template, split_workflow(properties_template)) if properties_template['flow']
32
+ update_column(:properties_release, split_workflow(properties_release)) if properties_release['flow']
33
+ end
26
34
  end
27
35
  end
@@ -1,13 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
  require 'labimotion/models/concerns/generic_klass_revisions'
3
- require 'labimotion/models/concerns/workflow'
4
3
 
5
4
  module Labimotion
6
5
  class SegmentKlass < ApplicationRecord
7
6
  self.table_name = :segment_klasses
8
7
  acts_as_paranoid
9
8
  include GenericKlassRevisions
10
- include Workflow
11
9
  belongs_to :element_klass, class_name: 'Labimotion::ElementKlass'
12
10
  has_many :segments, dependent: :destroy, class_name: 'Labimotion::Segment'
13
11
  has_many :segment_klasses_revisions, dependent: :destroy, class_name: 'Labimotion::SegmentKlassesRevision'
@@ -22,29 +22,6 @@ module Labimotion
22
22
  fetch_many.call(klasses, {'created_by' => 'User'})
23
23
  end
24
24
 
25
- def self.fetch_elements(collection, segments, attachments, fetch_many, fetch_one, fetch_containers)
26
- # fetch_many.call(collection.elements, {
27
- # 'element_klass_id' => 'Labimotion::ElementKlass',
28
- # 'created_by' => 'User',
29
- # })
30
- # fetch_many.call(collection.collections_elements, {
31
- # 'collection_id' => 'Collection',
32
- # 'element_id' => 'Labimotion::Element',
33
- # })
34
- collection.elements.each do |element|
35
- element, attachments = Labimotion::Export.fetch_properties(data, element, attachments, &fetch_one)
36
- fetch_one.call(element, {
37
- 'element_klass_id' => 'Labimotion::ElementKlass',
38
- 'created_by' => 'User',
39
- })
40
- fetch_containers.call(element)
41
- segment, @attachments = Labimotion::Export.fetch_segments(element, attachments, &fetch_one)
42
- segments += segment if segment.present?
43
- end
44
-
45
- [segments, attachments]
46
-
47
- end
48
25
 
49
26
  def self.fetch_segments(element, attachments, &fetch_one)
50
27
  element_type = element.class.name
@@ -94,15 +71,6 @@ module Labimotion
94
71
  mol = Molecule.find(id) unless id.nil?
95
72
  properties['layers'][key]['fields'][idx]['value']['el_id'] = fetch_one.call(mol) unless mol.nil?
96
73
  end
97
-
98
- field_samples = layer['fields'].select { |ss| ss['type'] == 'drag_sample' }
99
- field_samples.each do |field|
100
- # idx = properties['layers'][key]['fields'].index(field)
101
- # id = field["value"] && field["value"]["el_id"] unless idx.nil?
102
- # ss = Sample.find(id) unless id.nil?
103
- # properties['layers'][key]['fields'][idx]['value']['el_id'] = fetch_one.call(ss) unless ss.nil?
104
- end
105
-
106
74
  field_uploads = layer['fields'].select { |ss| ss['type'] == 'upload' }
107
75
  field_uploads.each do |upload|
108
76
  idx = properties['layers'][key]['fields'].index(upload)
@@ -135,6 +103,7 @@ module Labimotion
135
103
  end
136
104
  end
137
105
  end
106
+
138
107
  end
139
108
  instance.properties = properties
140
109
  [instance, attachments]
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'labimotion/utils/import_utils'
4
3
  module Labimotion
5
4
  class Import
6
5
 
@@ -51,7 +50,7 @@ module Labimotion
51
50
  element_type = fields.fetch('element_type')
52
51
  element = instances.fetch(element_type).fetch(element_uuid)
53
52
 
54
- dataset_klass = Labimotion::DatasetKlass.find_by(identifier: dk_id) if dk_id.present?
53
+ dataset_klass = Labimotion::DatasetKlass.find_by(identifier: dk_id)
55
54
  next if gt == true && dataset_klass.nil?
56
55
 
57
56
  dkr = Labimotion::DatasetKlassesRevision.find_by(uuid: fields.fetch('klass_uuid'))
@@ -89,21 +88,33 @@ module Labimotion
89
88
  ek_obj = data.fetch('Labimotion::ElementKlass').fetch(sk_obj["element_klass_id"])
90
89
  element_klass = Labimotion::ElementKlass.find_by(name: ek_obj['name']) if ek_obj.present?
91
90
  next if element_klass.nil? || ek_obj.nil? || ek_obj['is_generic'] == true
92
-
93
91
  element_uuid = fields.fetch('element_id')
94
92
  element_type = fields.fetch('element_type')
95
93
  element = instances.fetch(element_type).fetch(element_uuid)
96
- segment_klass = Labimotion::SegmentKlass.find_by(identifier: sk_id) if sk_id.present?
97
- segment_klass = Labimotion::SegmentKlass.find_by(uuid: fields.fetch('klass_uuid')) if segment_klass.nil?
98
-
99
- if segment_klass.nil?
100
- skr = Labimotion::SegmentKlassesRevision.find_by(uuid: fields.fetch('klass_uuid'))
101
- segment_klass = skr.segment_klass if segment_klass.nil? && skr.present?
102
- end
103
-
104
- next if segment_klass.nil? || element.nil?
105
-
106
- ## segment_klass = Labimotion::ImportUtils.create_segment_klass(sk_obj, segment_klass, element_klass, current_user_id)
94
+ segment_klass = Labimotion::SegmentKlass.find_by(identifier: sk_id)
95
+ next if gt == true && segment_klass.nil?
96
+
97
+ skr = Labimotion::SegmentKlassesRevision.find_by(uuid: fields.fetch('klass_uuid'))
98
+ segment_klass = skr.segment_klass if segment_klass.nil? && skr.present?
99
+
100
+ # segment_klass = Labimotion::SegmentKlass.create!(sk_obj.slice(
101
+ # 'label',
102
+ # 'desc',
103
+ # 'properties_template',
104
+ # 'is_active',
105
+ # 'place',
106
+ # 'properties_release',
107
+ # 'uuid',
108
+ # 'identifier',
109
+ # 'sync_time'
110
+ # ).merge(
111
+ # element_klass: element_klass,
112
+ # created_by: current_user_id,
113
+ # released_at: DateTime.now
114
+ # )
115
+ # ) if segment_klass.nil?
116
+
117
+ next if segment_klass.nil?
107
118
 
108
119
  segment = Labimotion::Segment.create!(
109
120
  fields.slice(
@@ -117,7 +128,52 @@ module Labimotion
117
128
  )
118
129
  )
119
130
 
120
- properties = Labimotion::ImportUtils.properties_handler(data, segment.properties)
131
+ properties = segment.properties
132
+ properties['layers'].keys.each do |key|
133
+ layer = properties['layers'][key]
134
+ field_molecules = layer['fields'].select { |ss| ss['type'] == 'drag_molecule' }
135
+ field_molecules.each do |field|
136
+ idx = properties['layers'][key]['fields'].index(field)
137
+ id = field["value"] && field["value"]["el_id"] unless idx.nil?
138
+ mol = Molecule.find_or_create_by_molfile(data.fetch('Molecule')[id]['molfile']) unless id.nil?
139
+ unless mol.nil?
140
+ properties['layers'][key]['fields'][idx]['value']['el_id'] = mol.id
141
+ properties['layers'][key]['fields'][idx]['value']['el_tip'] = "#{mol.inchikey}@@#{mol.cano_smiles}"
142
+ properties['layers'][key]['fields'][idx]['value']['el_label'] = mol.iupac_name
143
+ end
144
+ end
145
+
146
+ field_tables = layer['fields'].select { |ss| ss['type'] == 'table' }
147
+ field_tables&.each do |field|
148
+ tidx = layer['fields'].index(field)
149
+ next unless field['sub_values'].present? && field['sub_fields'].present?
150
+
151
+ field_table_molecules = field['sub_fields'].select { |ss| ss['type'] == 'drag_molecule' }
152
+ if field_table_molecules.present?
153
+ col_ids = field_table_molecules.map { |x| x.values[0] }
154
+ col_ids.each do |col_id|
155
+ field['sub_values'].each_with_index do |sub_value, vdx|
156
+ next unless sub_value[col_id].present? && sub_value[col_id]['value'].present? && sub_value[col_id]['value']['el_id'].present?
157
+
158
+ svalue = sub_value[col_id]['value']
159
+ next unless svalue['el_id'].present? && svalue['el_inchikey'].present?
160
+
161
+ tmol = Molecule.find_or_create_by_molfile(data.fetch('Molecule')[svalue['el_id']]['molfile']) unless svalue['el_id'].nil?
162
+ unless tmol.nil?
163
+ properties['layers'][key]['fields'][tidx]['sub_values'][vdx][col_id]['value']['el_id'] = tmol.id
164
+ properties['layers'][key]['fields'][tidx]['sub_values'][vdx][col_id]['value']['el_tip'] = "#{tmol.inchikey}@@#{tmol.cano_smiles}"
165
+ properties['layers'][key]['fields'][tidx]['sub_values'][vdx][col_id]['value']['el_label'] = tmol.cano_smiles
166
+ properties['layers'][key]['fields'][tidx]['sub_values'][vdx][col_id]['value']['el_smiles'] = tmol.cano_smiles
167
+ properties['layers'][key]['fields'][tidx]['sub_values'][vdx][col_id]['value']['el_iupac'] = tmol.iupac_name
168
+ properties['layers'][key]['fields'][tidx]['sub_values'][vdx][col_id]['value']['el_inchikey'] = tmol.inchikey
169
+ properties['layers'][key]['fields'][tidx]['sub_values'][vdx][col_id]['value']['el_svg'] = File.join('/images', 'molecules', tmol.molecule_svg_file)
170
+ properties['layers'][key]['fields'][tidx]['sub_values'][vdx][col_id]['value']['el_molecular_weight'] = tmol.molecular_weight
171
+ end
172
+ end
173
+ end
174
+ end
175
+ end
176
+ end
121
177
  segment.update!(properties: properties)
122
178
  update_instances.call(uuid, segment)
123
179
  end
@@ -126,43 +182,5 @@ module Labimotion
126
182
  raise
127
183
  end
128
184
  end
129
-
130
- def self.import_elements(data, instances, gt, current_user_id, fetch_many, &update_instances)
131
- data.fetch('Labimotion::Element', {}).each do |uuid, fields|
132
- klass_id = fields["element_klass_id"]
133
- ek_obj = data.fetch('Labimotion::ElementKlass', {})[klass_id]
134
- ek_id = ek_obj["identifier"]
135
- element_klass = Labimotion::ElementKlass.find_by(identifier: ek_id) if ek_id.present?
136
- element_klass = Labimotion::ElementKlass.find_by(uuid: fields.fetch('klass_uuid')) if element_klass.nil?
137
-
138
- if element_klass.nil?
139
- ekr = Labimotion::ElementKlassesRevision.find_by(uuid: fields.fetch('klass_uuid'))
140
- element_klass = ekr.element_klass if element_klass.nil? && ekr.present?
141
- end
142
- next if element_klass.nil?
143
-
144
- element = Labimotion::Element.create!(
145
- fields.slice(
146
- 'name', 'properties', 'properties_release'
147
- ).merge(
148
- created_by: current_user_id,
149
- element_klass: element_klass,
150
- collections: fetch_many.call(
151
- 'Collection', 'Labimotion::CollectionsElement', 'element_id', 'collection_id', uuid
152
- ),
153
- uuid: SecureRandom.uuid,
154
- klass_uuid: ekr&.uuid || element_klass.uuid
155
- )
156
- )
157
-
158
- properties = Labimotion::ImportUtils.properties_handler(data, element.properties)
159
- element.update!(properties: properties)
160
- update_instances.call(uuid, element)
161
- element.container = Container.create_root_container
162
- end
163
- rescue StandardError => e
164
- Rails.logger.error(e.backtrace)
165
- raise
166
- end
167
185
  end
168
186
  end
@@ -1,11 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- ## Labimotion Version
4
3
  module Labimotion
5
- IS_RAILS5 = true
6
- VERSION_ELN = '1.0.17'
7
- VERSION_REPO = '0.3.3'
8
-
9
- VERSION = Labimotion::VERSION_REPO if Labimotion::IS_RAILS5 == true
10
- VERSION = Labimotion::VERSION_ELN if Labimotion::IS_RAILS5 == false
4
+ # VERSION = '0.1.4'
5
+ VERSION = '1.0.0'
6
+ IS_RAILS5 = false
11
7
  end
data/lib/labimotion.rb CHANGED
@@ -61,11 +61,8 @@ module Labimotion
61
61
  autoload :ConState, 'labimotion/utils/con_state'
62
62
  autoload :Serializer, 'labimotion/utils/serializer'
63
63
  autoload :Search, 'labimotion/utils/search'
64
-
65
-
66
- ######## Collection
67
- autoload :Export, 'labimotion/collection/export'
68
- autoload :Import, 'labimotion/collection/import'
64
+ autoload :Export, 'labimotion/utils/export'
65
+ autoload :Import, 'labimotion/utils/import'
69
66
 
70
67
  ######## Models
71
68
  autoload :Element, 'labimotion/models/element'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: labimotion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chia-Lin Lin
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-10-19 00:00:00.000000000 Z
12
+ date: 2023-08-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: 5.2.0
20
+ version: 6.1.7
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: 5.2.0
27
+ version: 6.1.7
28
28
  description:
29
29
  email:
30
30
  - chia-lin.lin@kit.edu
@@ -34,13 +34,12 @@ extensions: []
34
34
  extra_rdoc_files: []
35
35
  files:
36
36
  - lib/labimotion.rb
37
+ - lib/labimotion/api.rb
37
38
  - lib/labimotion/apis/converter_api.rb
38
39
  - lib/labimotion/apis/generic_dataset_api.rb
39
40
  - lib/labimotion/apis/generic_element_api.rb
40
41
  - lib/labimotion/apis/labimotion_hub_api.rb
41
42
  - lib/labimotion/apis/segment_api.rb
42
- - lib/labimotion/collection/export.rb
43
- - lib/labimotion/collection/import.rb
44
43
  - lib/labimotion/entities/application_entity.rb
45
44
  - lib/labimotion/entities/dataset_entity.rb
46
45
  - lib/labimotion/entities/dataset_klass_entity.rb
@@ -66,6 +65,7 @@ files:
66
65
  - lib/labimotion/libs/converter.rb
67
66
  - lib/labimotion/libs/export_dataset.rb
68
67
  - lib/labimotion/libs/nmr_mapper.rb
68
+ - lib/labimotion/libs/nmr_mapper_repo.rb
69
69
  - lib/labimotion/libs/template_hub.rb
70
70
  - lib/labimotion/models/collections_element.rb
71
71
  - lib/labimotion/models/concerns/attachment_converter.rb
@@ -84,20 +84,20 @@ files:
84
84
  - lib/labimotion/models/elements_element.rb
85
85
  - lib/labimotion/models/elements_revision.rb
86
86
  - lib/labimotion/models/elements_sample.rb
87
- - lib/labimotion/models/hub_log.rb
88
87
  - lib/labimotion/models/segment.rb
89
88
  - lib/labimotion/models/segment_klass.rb
90
89
  - lib/labimotion/models/segment_klasses_revision.rb
91
90
  - lib/labimotion/models/segments_revision.rb
92
91
  - lib/labimotion/utils/con_state.rb
93
- - lib/labimotion/utils/import_utils.rb
92
+ - lib/labimotion/utils/export.rb
93
+ - lib/labimotion/utils/import.rb
94
94
  - lib/labimotion/utils/search.rb
95
95
  - lib/labimotion/utils/serializer.rb
96
96
  - lib/labimotion/utils/utils.rb
97
97
  - lib/labimotion/version.rb
98
- homepage: https://gitlab.kit.edu/kit/labimotion/labimotion
98
+ homepage: https://github.com/phuang26/labimotion
99
99
  licenses:
100
- - GPL-3.0
100
+ - MIT
101
101
  metadata: {}
102
102
  post_install_message:
103
103
  rdoc_options: []
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Labimotion
4
- class HubLog < ApplicationRecord
5
- self.table_name = :hub_logs
6
- belongs_to :klass, polymorphic: true, optional: true
7
- end
8
- end
@@ -1,116 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Labimotion
4
- ## Import Utils
5
- class ImportUtils
6
- def self.proc_sample(layer, key, data, properties)
7
- field_samples = layer['fields'].select { |ss| ss['type'] == 'drag_sample' }
8
- field_samples.each do |field|
9
- idx = properties['layers'][key]['fields'].index(field)
10
- id = field["value"] && field["value"]["el_id"] unless idx.nil?
11
-
12
- # mol = Molecule.find_or_create_by_molfile(data.fetch('Molecule')[id]['molfile']) unless id.nil?
13
- # unless mol.nil?
14
- # properties['layers'][key]['fields'][idx]['value']['el_id'] = mol.id
15
- # properties['layers'][key]['fields'][idx]['value']['el_tip'] = "#{mol.inchikey}@@#{mol.cano_smiles}"
16
- # properties['layers'][key]['fields'][idx]['value']['el_label'] = mol.iupac_name
17
- # end
18
- end
19
- properties
20
- rescue StandardError => e
21
- Rails.logger.error(e.backtrace)
22
- raise
23
- end
24
-
25
- def self.proc_molecule(layer, key, data, properties)
26
- field_molecules = layer['fields'].select { |ss| ss['type'] == 'drag_molecule' }
27
- field_molecules.each do |field|
28
- idx = properties['layers'][key]['fields'].index(field)
29
- id = field["value"] && field["value"]["el_id"] unless idx.nil?
30
- mol = Molecule.find_or_create_by_molfile(data.fetch('Molecule')[id]['molfile']) unless id.nil?
31
- unless mol.nil?
32
- properties['layers'][key]['fields'][idx]['value']['el_id'] = mol.id
33
- properties['layers'][key]['fields'][idx]['value']['el_tip'] = "#{mol.inchikey}@@#{mol.cano_smiles}"
34
- properties['layers'][key]['fields'][idx]['value']['el_label'] = mol.iupac_name
35
- end
36
- end
37
- properties
38
- rescue StandardError => e
39
- Rails.logger.error(e.backtrace)
40
- raise
41
- end
42
-
43
- def self.proc_table(layer, key, data, properties)
44
- field_tables = layer['fields'].select { |ss| ss['type'] == 'table' }
45
- field_tables&.each do |field|
46
- tidx = layer['fields'].index(field)
47
- next unless field['sub_values'].present? && field['sub_fields'].present?
48
-
49
- field_table_molecules = field['sub_fields'].select { |ss| ss['type'] == 'drag_molecule' }
50
- if field_table_molecules.present?
51
- col_ids = field_table_molecules.map { |x| x.values[0] }
52
- col_ids.each do |col_id|
53
- field['sub_values'].each_with_index do |sub_value, vdx|
54
- next unless sub_value[col_id].present? && sub_value[col_id]['value'].present? && sub_value[col_id]['value']['el_id'].present?
55
-
56
- svalue = sub_value[col_id]['value']
57
- next unless svalue['el_id'].present? && svalue['el_inchikey'].present?
58
-
59
- tmol = Molecule.find_or_create_by_molfile(data.fetch('Molecule')[svalue['el_id']]['molfile']) unless svalue['el_id'].nil?
60
- unless tmol.nil?
61
- properties['layers'][key]['fields'][tidx]['sub_values'][vdx][col_id]['value']['el_id'] = tmol.id
62
- properties['layers'][key]['fields'][tidx]['sub_values'][vdx][col_id]['value']['el_tip'] = "#{tmol.inchikey}@@#{tmol.cano_smiles}"
63
- properties['layers'][key]['fields'][tidx]['sub_values'][vdx][col_id]['value']['el_label'] = tmol.cano_smiles
64
- properties['layers'][key]['fields'][tidx]['sub_values'][vdx][col_id]['value']['el_smiles'] = tmol.cano_smiles
65
- properties['layers'][key]['fields'][tidx]['sub_values'][vdx][col_id]['value']['el_iupac'] = tmol.iupac_name
66
- properties['layers'][key]['fields'][tidx]['sub_values'][vdx][col_id]['value']['el_inchikey'] = tmol.inchikey
67
- properties['layers'][key]['fields'][tidx]['sub_values'][vdx][col_id]['value']['el_svg'] = File.join('/images', 'molecules', tmol.molecule_svg_file)
68
- properties['layers'][key]['fields'][tidx]['sub_values'][vdx][col_id]['value']['el_molecular_weight'] = tmol.molecular_weight
69
- end
70
- end
71
- end
72
- end
73
- end
74
- properties
75
- rescue StandardError => e
76
- Rails.logger.error(e.backtrace)
77
- raise
78
- end
79
-
80
- def self.properties_handler(data, properties)
81
- properties && properties['layers'] && properties['layers'].keys&.each do |key|
82
- layer = properties['layers'][key]
83
- properties = proc_molecule(layer, key, data, properties)
84
- properties = proc_table(layer, key, data, properties)
85
- # properties = proc_sample(layer, key, data, properties)
86
- end
87
- properties
88
- rescue StandardError => e
89
- Rails.logger.error(e.backtrace)
90
- raise
91
- end
92
-
93
- def self.create_segment_klass(sk_obj, segment_klass, element_klass, current_user_id)
94
- return if segment_klass.present? || element_klass.nil? || sk_obj.nil?
95
-
96
- segment_klass = Labimotion::SegmentKlass.create!(sk_obj.slice(
97
- 'label',
98
- 'desc',
99
- 'properties_template',
100
- 'is_active',
101
- 'place',
102
- 'properties_release',
103
- 'uuid',
104
- 'identifier',
105
- 'sync_time'
106
- ).merge(
107
- element_klass: element_klass,
108
- created_by: current_user_id,
109
- released_at: DateTime.now
110
- )
111
- )
112
-
113
- segment_klass
114
- end
115
- end
116
- end