labimotion 1.3.0.rc2 → 1.3.0.rc4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ee43dfba01f84786e6b1dc59d125c6c8cd3a7594e6f3d9e5179268995b8366dd
4
- data.tar.gz: e15bf2f064a847b950f3320a2707de508f3c8169a966519280b71f8426a20f3e
3
+ metadata.gz: 99c322d38e4cd89d9983147d40d2ceb98aee8342fe9d036f6757034a52fc8b81
4
+ data.tar.gz: ccf53a3066ff47347a29f45594fbac4436fb6161078c56ef5461a672fa99e0db
5
5
  SHA512:
6
- metadata.gz: da54fef539dfc89675a40f1e1de1ab3a58a77f0e23a494912852ab78a29546af83ceeb1ef9e3b1a8f1d77d78adcc55e77a8d986b28f43810966264bdab89c230
7
- data.tar.gz: db9c675738091bd749bdea7ece8eb3e555b6063694691d81a58832b19be3f92618d61a69228ad8a820c11a4b14d7ff8b77ef817378740e0f2af108aa43867316
6
+ metadata.gz: ce7a434025855de8eafc83450b4bb8808d77e237f306bc5c0f986bdbfb7cc72f46199d615eca43085353af365ea4315ca89f44bedc2ff487dc24d1c69e9a781d
7
+ data.tar.gz: fff821b8cf75223a50feb3d630eb229bb709de42c8644e1175cbe5c0cfad7a560e6ac9ca2548bfdecb1f2b6372c1e6ba9739ffbd712f82d017793b61e8b0e85b
@@ -46,11 +46,19 @@ module Labimotion
46
46
  namespace :export do
47
47
  desc 'export element'
48
48
  params do
49
- optional :id, type: Integer, desc: 'element id'
49
+ requires :id, type: Integer, desc: 'element id'
50
+ requires :klass, type: String, desc: 'Klass', values: %w[Element Segment Dataset]
50
51
  optional :export_format, type: String, desc: 'export format'
51
52
  end
52
53
  get do
53
- element = Labimotion::Element.find(params[:id])
54
+ case params[:klass]
55
+ when 'Element'
56
+ element = Labimotion::Element.find(params[:id])
57
+ when 'Segment'
58
+ element = Labimotion::Segment.find(params[:id])
59
+ when 'Dataset'
60
+ element = Labimotion::Dataset.find(params[:id])
61
+ end
54
62
  ## byebug
55
63
  export = Labimotion::ExportElement.new current_user, element, params[:export_format]
56
64
  env['api.format'] = :binary
@@ -340,21 +348,14 @@ module Labimotion
340
348
 
341
349
  get do
342
350
  element = Labimotion::Element.find(params[:id])
343
- if Labimotion::IS_RAILS5 == true
344
- {
345
- element: ElementPermissionProxy.new(current_user, element, user_ids).serialized,
346
- attachments: attach_thumbnail(element&.attachments)
347
- }
348
- else
349
- {
350
- element: Labimotion::ElementEntity.represent(
351
- element,
352
- detail_levels: ElementDetailLevelCalculator.new(user: current_user, element: element).detail_levels,
353
- policy: @element_policy
354
- ),
355
- attachments: attach_thumbnail(element&.attachments)
356
- }
357
- end
351
+ {
352
+ element: Labimotion::ElementEntity.represent(
353
+ element,
354
+ detail_levels: ElementDetailLevelCalculator.new(user: current_user, element: element).detail_levels,
355
+ policy: @element_policy
356
+ ),
357
+ attachments: attach_thumbnail(element&.attachments)
358
+ }
358
359
  rescue StandardError => e
359
360
  Labimotion.log_exception(e, current_user)
360
361
  end
@@ -89,7 +89,7 @@ module Labimotion
89
89
  sk_id = sk_obj["identifier"]
90
90
  ek_obj = data.fetch(Labimotion::Prop::L_ELEMENT_KLASS).fetch(sk_obj["element_klass_id"])
91
91
  element_klass = Labimotion::ElementKlass.find_by(name: ek_obj['name']) if ek_obj.present?
92
- next if element_klass.nil? || ek_obj.nil? || ek_obj['is_generic'] == true
92
+ next if element_klass.nil? || ek_obj.nil? # || ek_obj['is_generic'] == true
93
93
 
94
94
  element_uuid = fields.fetch('element_id')
95
95
  element_type = fields.fetch('element_type')
@@ -99,7 +99,7 @@ module Labimotion
99
99
 
100
100
  if segment_klass.nil?
101
101
  skr = Labimotion::SegmentKlassesRevision.find_by(uuid: fields.fetch('klass_uuid'))
102
- segment_klass = skr.segment_klass if segment_klass.nil? && skr.present?
102
+ segment_klass = Labimotion::SegmentKlass.find_by(id: skr.segment_klass_id) if skr.present?
103
103
  end
104
104
 
105
105
  next if segment_klass.nil? || element.nil?
@@ -133,7 +133,7 @@ module Labimotion
133
133
  data.fetch('Labimotion::Element', {}).each do |uuid, fields|
134
134
  klass_id = fields["element_klass_id"]
135
135
  ek_obj = data.fetch('Labimotion::ElementKlass', {})[klass_id]
136
- ek_id = ek_obj["identifier"]
136
+ ek_id = ek_obj["identifier"] if ek_obj.present?
137
137
  element_klass = Labimotion::ElementKlass.find_by(identifier: ek_id) if ek_id.present?
138
138
  element_klass = Labimotion::ElementKlass.find_by(uuid: fields.fetch('klass_uuid')) if element_klass.nil?
139
139
 
@@ -176,11 +176,6 @@ module Labimotion
176
176
  )
177
177
  end
178
178
  (attach_ary << att_ary).flatten! unless att_ary&.empty?
179
-
180
- if Labimotion::IS_RAILS5 == true
181
- TransferThumbnailToPublicJob.set(queue: "transfer_thumbnail_to_public_#{current_user.id}").perform_now(attach_ary) unless attach_ary.empty?
182
- TransferFileFromTmpJob.set(queue: "transfer_file_from_tmp_#{current_user.id}").perform_now(attach_ary) unless attach_ary.empty?
183
- end
184
179
  true
185
180
  rescue StandardError => e
186
181
  Labimotion.log_exception(e, current_user)
@@ -27,18 +27,10 @@ module Labimotion
27
27
 
28
28
  dsr = []
29
29
  ols = nil
30
- if Labimotion::IS_RAILS5 == true
31
- Zip::File.open(att.store.path) do |zip_file|
32
- res = Labimotion::Converter.collect_metadata(zip_file) if att.filename.split('.')&.last == 'zip'
33
- ols = res[:o] unless res&.dig(:o).nil?
34
- dsr.push(res[:d]) unless res&.dig(:d).nil?
35
- end
36
- else
37
- Zip::File.open(att.attachment_attacher.file.url) do |zip_file|
38
- res = Labimotion::Converter.collect_metadata(zip_file) if att.filename.split('.')&.last == 'zip'
39
- ols = res[:o] unless res&.dig(:o).nil?
40
- dsr.push(res[:d]) unless res&.dig(:d).nil?
41
- end
30
+ Zip::File.open(att.attachment_attacher.file.url) do |zip_file|
31
+ res = Labimotion::Converter.collect_metadata(zip_file) if att.filename.split('.')&.last == 'zip'
32
+ ols = res[:o] unless res&.dig(:o).nil?
33
+ dsr.push(res[:d]) unless res&.dig(:d).nil?
42
34
  end
43
35
  dsr.flatten!
44
36
  dataset = build_ds(att.attachable_id, ols)
@@ -145,16 +137,9 @@ module Labimotion
145
137
  created_by: oat.created_by,
146
138
  created_for: oat.created_for,
147
139
  )
148
- # att.attachment_attacher.attach(tmp_file)
149
- if att.valid? && Labimotion::IS_RAILS5 == false
150
- ## att.attachment_attacher.create_derivatives
151
- att.save!
152
- end
153
- if att.valid? && Labimotion::IS_RAILS5 == true
154
- att.save!
155
- primary_store = Rails.configuration.storage.primary_store
156
- att.update!(storage: primary_store)
157
- end
140
+
141
+ att.save! if att.valid?
142
+
158
143
  process_ds(att.id)
159
144
  rescue StandardError => e
160
145
  raise e
@@ -168,11 +153,7 @@ module Labimotion
168
153
  response = nil
169
154
  begin
170
155
  ofile = Rails.root.join(data[:f], data[:a].filename)
171
- if Labimotion::IS_RAILS5 == true
172
- FileUtils.cp(data[:a].store.path, ofile)
173
- else
174
- FileUtils.cp(data[:a].attachment_url, ofile)
175
- end
156
+ FileUtils.cp(data[:a].attachment_url, ofile)
176
157
 
177
158
  File.open(ofile, 'r') do |f|
178
159
  body = { file: f }
@@ -145,18 +145,9 @@ module Labimotion
145
145
  sheet_name = "Sheet#{idx+1}"
146
146
  sheet = @xfile.workbook.add_worksheet(name: sheet_name)
147
147
  name_mapping.push([sheet_name, att.filename])
148
-
149
- if Labimotion::IS_RAILS5 == true
150
- File.open(att.store.path) do |fi|
151
- fi.each_line do |line|
152
- sheet.add_row(line.split(','))
153
- end
154
- end
155
- else
156
- File.open(att.attachment_url) do |fi|
157
- fi.each_line do |line|
158
- sheet.add_row(line.split(','))
159
- end
148
+ File.open(att.attachment_url) do |fi|
149
+ fi.each_line do |line|
150
+ sheet.add_row(line.split(','))
160
151
  end
161
152
  end
162
153
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  require 'export_table'
3
3
  require 'labimotion/version'
4
+ require 'labimotion/utils/units'
4
5
  require 'sablon'
5
6
 
6
7
  module Labimotion
@@ -8,6 +9,25 @@ module Labimotion
8
9
  def initialize(current_user, element, export_format)
9
10
  @current_user = current_user
10
11
  @element = element
12
+ @parent =
13
+ case element.class.name
14
+ when 'Labimotion::Segment'
15
+ element&.element
16
+ when 'Labimotion::Dataset'
17
+ element&.element&.root_element
18
+ end
19
+ @element_klass =
20
+ case element.class.name
21
+ when 'Labimotion::Element'
22
+ element.element_klass
23
+ when 'Labimotion::Segment'
24
+ element.segment_klass
25
+ when 'Labimotion::Dataset'
26
+ element.dataset_klass
27
+ end
28
+ @name = @element.instance_of?(Labimotion::Element) ? element.name : @parent&.name
29
+ @short_label = @element.instance_of?(Labimotion::Element) ? element.short_label : @parent&.short_label
30
+ @element_name = "#{@element_klass.label}_#{@short_label}".gsub(/\s+/, '')
11
31
  @properties = element.properties
12
32
  @options = element.properties_release[Labimotion::Prop::SEL_OPTIONS]
13
33
  @export_format = export_format
@@ -17,7 +37,12 @@ module Labimotion
17
37
 
18
38
  def build_layers
19
39
  objs = []
20
- @properties[Labimotion::Prop::LAYERS]&.keys&.sort_by { |key| @properties[Labimotion::Prop::LAYERS][key]['position'] }&.each do |key|
40
+ @properties[Labimotion::Prop::LAYERS]&.keys&.sort_by do |key|
41
+ [
42
+ @properties[Labimotion::Prop::LAYERS].fetch(key, nil)&.fetch('position', 0) || 0,
43
+ @properties[Labimotion::Prop::LAYERS].fetch(key, nil)&.fetch('wf_position', 0) || 0
44
+ ]
45
+ end&.each do |key|
21
46
  layer = @properties[Labimotion::Prop::LAYERS][key] || {}
22
47
 
23
48
  ## Build fields html
@@ -53,23 +78,25 @@ module Labimotion
53
78
  field_obj[:value] = (field['value'] && field['value']['el_label']) || ''
54
79
  field_obj[:obj] = field['value'] ### change to object
55
80
  when Labimotion::FieldType::DRAG_SAMPLE
56
- val = field.fetch('value', {})
57
- instance = Sample.find_by(id: val['el_id'])
58
- field_obj[:value] = val['el_label']
59
- field_obj[:has_structure] = true
60
- obj_os = Entities::SampleReportEntity.new(
61
- instance,
62
- current_user: @current_user,
63
- detail_levels: ElementDetailLevelCalculator.new(user: @current_user, element: instance).detail_levels,
64
- ).serializable_hash
65
- obj_final = OpenStruct.new(obj_os)
66
- field_obj[:structure] = Reporter::Docx::DiagramSample.new(obj: obj_final, format: 'png').generate
81
+ val = field.fetch('value', nil)
82
+ if val.present?
83
+ instance = Sample.find_by(id: val['el_id'])
84
+ field_obj[:value] = val['el_label']
85
+ field_obj[:has_structure] = true
86
+ obj_os = Entities::SampleReportEntity.new(
87
+ instance,
88
+ current_user: @current_user,
89
+ detail_levels: ElementDetailLevelCalculator.new(user: @current_user, element: instance).detail_levels,
90
+ ).serializable_hash
91
+ obj_final = OpenStruct.new(obj_os)
92
+ field_obj[:structure] = Reporter::Docx::DiagramSample.new(obj: obj_final, format: 'png').generate
93
+ end
67
94
  when Labimotion::FieldType::DRAG_MOLECULE
68
- val = field.fetch('value', {})
69
- obj = Molecule.find_by(id: val['el_id'])
70
- field_obj[:value] = val['el_label']
71
- # field_obj[:has_structure] = true
72
- # field_obj[:structure] = Reporter::Docx::DiagramSample.new(obj: obj, format: 'png').generate
95
+ val = field.fetch('value', nil)
96
+ if val.present?
97
+ obj = Molecule.find_by(id: val['el_id'])
98
+ field_obj[:value] = val['el_label']
99
+ end
73
100
  when Labimotion::FieldType::SELECT
74
101
  field_obj[:value] = @options.fetch(field['option_layers'], nil)&.fetch('options', nil)&.find { |ss| ss['key'] == field['value'] }&.fetch('label', nil) || field['value']
75
102
  when Labimotion::FieldType::UPLOAD
@@ -82,7 +109,6 @@ module Labimotion
82
109
  tbl = []
83
110
  ## tbl_idx = []
84
111
  header = {}
85
-
86
112
  sub_fields = field.fetch('sub_fields', [])
87
113
  sub_fields.each_with_index do |sub_field, idx|
88
114
  header["col#{idx}"] = sub_field['col_name']
@@ -107,6 +133,25 @@ module Labimotion
107
133
  end
108
134
  end
109
135
  field_obj[:value] = val.join(' ')
136
+ when Labimotion::FieldType::WF_NEXT
137
+ if field['value'].present? && field['wf_options'].present?
138
+ field_obj[:value] = field['wf_options'].find { |ss| ss['key'] == field['value'] }&.fetch('label', nil)&.split('(')&.first&.strip
139
+ end
140
+ when Labimotion::FieldType::SYSTEM_DEFINED
141
+ _field = field
142
+ unit = Labimotion::Units::FIELDS.find { |o| o[:field] == _field['option_layers'] }&.fetch(:units, []).find { |u| u[:key] == _field['value_system'] }&.fetch(:label, '')
143
+ val = _field['value'].to_s + ' ' + unit
144
+ val = Sablon.content(:html, "<div>" + val + "</div>") if val.include? '<'
145
+ field_obj[:value] = val
146
+ when Labimotion::FieldType::TEXT_FORMULA
147
+ field.fetch('text_sub_fields', []).each do |sub_field|
148
+ va = @properties['layers'][sub_field.fetch('layer','')]['fields'].find { |f| f['field'] == sub_field.fetch('field','') }&.fetch('value',nil)
149
+ field_obj[:value] = (field_obj[:value] || '') + va.to_s + sub_field.fetch('separator','') if va.present?
150
+ end
151
+ # field_obj[:value] = (field['value'] && field['value']['el_label']) || ''
152
+ # field_obj[:obj] = field['value'] ### change to object
153
+ else
154
+ field_obj[:value] = field['value']
110
155
  end
111
156
  field_obj
112
157
  rescue StandardError => e
@@ -117,10 +162,27 @@ module Labimotion
117
162
  return '' if sub_field.fetch('id', nil).nil? || sub_val[sub_field['id']].nil?
118
163
 
119
164
  case sub_field['type']
165
+ when Labimotion::FieldType::DRAG_SAMPLE
166
+ val = sub_val[sub_field['id']]['value'] || {}
167
+ label = val['el_label'].present? ? "Short Label: [#{val['el_label']}] \n" : ''
168
+ name = val['el_name'].present? ? "Name: [#{val['el_name']}] \n" : ''
169
+ ext = val['el_external_label'].present? ? "Ext. Label: [#{val['el_external_label']}] \n" : ''
170
+ mass = val['el_molecular_weight'].present? ? "Mass: [#{val['el_molecular_weight']}] \n" : ''
171
+ "#{label}#{name}#{ext}#{mass}"
172
+ when Labimotion::FieldType::DRAG_MOLECULE
173
+ val = sub_val[sub_field['id']]['value'] || {}
174
+ smile = val['el_smiles'].present? ? "SMILES: [#{val['el_smiles']}] \n" : ''
175
+ inchikey = val['el_inchikey'].present? ? "InChiKey:[#{val['el_inchikey']}] \n" : ''
176
+ iupac = val['el_iupac'].present? ? "IUPAC:[#{val['el_iupac']}] \n" : ''
177
+ mass = val['el_molecular_weight'].present? ? "MASS: [#{val['el_molecular_weight']}] \n" : ''
178
+ "#{smile}#{inchikey}#{iupac}#{mass}"
120
179
  when Labimotion::FieldType::SELECT
121
180
  sub_val[sub_field['id']]['value']
122
181
  when Labimotion::FieldType::SYSTEM_DEFINED
123
- "#{sub_val[sub_field['id']]['value']} #{sub_val[sub_field['id']]['value_system']}"
182
+ unit = Labimotion::Units::FIELDS.find { |o| o[:field] == sub_field['option_layers'] }&.fetch(:units, [])&.find { |u| u[:key] == sub_field['value_system'] }&.fetch(:label, '')
183
+ val = sub_val[sub_field['id']]['value'].to_s + ' ' + unit
184
+ val = Sablon.content(:html, "<div>" + val + "</div>") if val.include? '<'
185
+ val
124
186
  else
125
187
  sub_val[sub_field['id']]
126
188
  end
@@ -148,8 +210,11 @@ module Labimotion
148
210
  template = Sablon.template(location)
149
211
  layers = build_layers
150
212
  context = {
151
- name: @element.name,
152
- short_label: @element.short_label,
213
+ label: @element_klass.label,
214
+ desc: @element_klass.desc,
215
+ name: @name,
216
+ parent_klass: @parent.present? ? "#{@parent&.class&.name&.split('::')&.last}: " : '',
217
+ short_label: @short_label,
153
218
  date: Time.now.strftime('%d/%m/%Y'),
154
219
  author: @current_user.name,
155
220
  layers: layers
@@ -162,14 +227,13 @@ module Labimotion
162
227
  Labimotion.log_exception(e)
163
228
  ensure
164
229
  # Close and delete the temporary file
165
- tempfile.close
166
- tempfile.unlink
230
+ tempfile&.close
231
+ tempfile&.unlink
167
232
  end
168
233
 
169
234
 
170
235
  def res_name
171
- element_name = @element.short_label
172
- "#{element_name}_#{Time.now.strftime('%Y%m%d%H%M')}.docx"
236
+ "#{@element_name}_#{Time.now.strftime('%Y%m%d%H%M')}.docx"
173
237
  rescue StandardError => e
174
238
  Labimotion.log_exception(e)
175
239
  end
@@ -28,8 +28,8 @@ module Labimotion
28
28
  att = Attachment.find_by(id: id, con_state: Labimotion::ConState::NMR)
29
29
  return if att.nil?
30
30
 
31
- if Labimotion::IS_RAILS5 == true
32
- Zip::File.open(att.store.path) do |zip_file|
31
+ if att&.attachment_attacher&.file&.url
32
+ Zip::File.open(att.attachment_attacher.file.url) do |zip_file|
33
33
  zip_file.each do |entry|
34
34
  if entry.name.include?('/pdata/') && entry.name.include?('parm.txt')
35
35
  metadata = entry.get_input_stream.read.force_encoding('UTF-8')
@@ -39,19 +39,6 @@ module Labimotion
39
39
  end
40
40
  end
41
41
  end
42
- else
43
- if att&.attachment_attacher&.file&.url
44
- Zip::File.open(att.attachment_attacher.file.url) do |zip_file|
45
- zip_file.each do |entry|
46
- if entry.name.include?('/pdata/') && entry.name.include?('parm.txt')
47
- metadata = entry.get_input_stream.read.force_encoding('UTF-8')
48
- return { is_bagit: false, metadata: metadata }
49
- elsif entry.name.include?('metadata/') && entry.name.include?('converter.json')
50
- return { is_bagit: true, metadata: nil }
51
- end
52
- end
53
- end
54
- end
55
42
  end
56
43
  { is_bagit: false, metadata: nil }
57
44
  end
@@ -8,6 +8,8 @@ module Labimotion
8
8
  SELECT = 'select'.freeze
9
9
  INTEGER = 'integer'.freeze
10
10
  INPUT_GROUP = 'input-group'.freeze
11
+ WF_NEXT = 'wf-next'.freeze
12
+ TEXT_FORMULA = 'text-formula'.freeze
11
13
  SYSTEM_DEFINED = 'system-defined'.freeze
12
14
  DRAG = 'drag'.freeze
13
15
  DRAG_ELEMENT = 'drag_element'.freeze