labimotion 0.1.12 → 0.1.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a7407e7996f74f24add8270076561baf80e5d0ea09a7617f1ad6bd8726fce4f0
4
- data.tar.gz: 7579b7fea1a56eab9f8899a6d7f153926eea31493effac70b57c13b31b868062
3
+ metadata.gz: 4462059ccf7843ed6aee9d493e2fcadf9cb6675fd2e71652eb8ce670cd3e3630
4
+ data.tar.gz: bf3f3b3c664117b679b19ba27171ed37f45371e267a44988e0a709c98b9b66e7
5
5
  SHA512:
6
- metadata.gz: b85976e6caf972dc33ce38b2ae128f3270c3f5b594485503d01c1ee3f4100c3cf6ec3352d51c755895a5e12bd19624a604221f9c69a3a4a5d2c0c4fc5bfc0bfb
7
- data.tar.gz: f3a777ef610da20216929d7e3278229c848dd56fa8c5a458e88667a6b524313d625fbd09127c96d32f32d99f53673505591129aeb4f6f49e2d4c71f1980f14dd
6
+ metadata.gz: ec3bfa245f202a31bb6e1a46104296b7ed7eab6500eabc7832adcaf0ded162492d46403459a476f89468ae8a513af83e5f8d23e057efd0820829be745c150e55
7
+ data.tar.gz: 04f4c1e4856c2a9909a487dfa4e2764aac737ac76379e892d07fd66da5347be2c55ec94281b7241bae57736c2667fe03250c945930295285b447850b9039fd92
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Labimotion
2
4
  ## Generic Dataset API
3
5
  class GenericDatasetAPI < Grape::API
@@ -21,6 +21,8 @@ module Labimotion
21
21
  get do
22
22
  ek = Labimotion::ElementKlass.find_by(name: params[:name])
23
23
  present ek, with: Labimotion::ElementKlassEntity, root: 'klass'
24
+ rescue StandardError => e
25
+ Labimotion.log_exception(e, current_user)
24
26
  end
25
27
  end
26
28
 
@@ -32,6 +34,8 @@ module Labimotion
32
34
  get do
33
35
  list = klass_list(params[:generic_only])
34
36
  present list, with: Labimotion::ElementKlassEntity, root: 'klass'
37
+ rescue StandardError => e
38
+ Labimotion.log_exception(e, current_user)
35
39
  end
36
40
  end
37
41
 
@@ -67,6 +71,9 @@ module Labimotion
67
71
  post do
68
72
  authenticate_admin!('elements')
69
73
  update_element_klass(current_user, params)
74
+ rescue StandardError => e
75
+ Labimotion.log_exception(e, current_user)
76
+ raise e
70
77
  end
71
78
  end
72
79
 
@@ -79,6 +86,9 @@ module Labimotion
79
86
  get do
80
87
  list = list_klass_revisions(params)
81
88
  present list, with: Labimotion::KlassRevisionEntity, root: 'revisions'
89
+ rescue StandardError => e
90
+ Labimotion.log_exception(e, current_user)
91
+ []
82
92
  end
83
93
  end
84
94
 
@@ -90,6 +100,9 @@ module Labimotion
90
100
  get do
91
101
  list = element_revisions(params)
92
102
  present list, with: Labimotion::ElementRevisionEntity, root: 'revisions'
103
+ rescue StandardError => e
104
+ Labimotion.log_exception(e, current_user)
105
+ []
93
106
  end
94
107
  end
95
108
 
@@ -104,6 +117,9 @@ module Labimotion
104
117
  authenticate_admin!(params[:klass].gsub(/(Klass)/, 's').downcase)
105
118
  delete_klass_revision(params)
106
119
  status 201
120
+ rescue StandardError => e
121
+ Labimotion.log_exception(e, current_user)
122
+ raise e
107
123
  end
108
124
  end
109
125
 
@@ -117,6 +133,9 @@ module Labimotion
117
133
  post do
118
134
  delete_revision(params)
119
135
  status 201
136
+ rescue StandardError => e
137
+ Labimotion.log_exception(e, current_user)
138
+ raise e
120
139
  end
121
140
  end
122
141
 
@@ -129,6 +148,9 @@ module Labimotion
129
148
  klass = Labimotion::Segment.find(params[:id])
130
149
  list = klass.segments_revisions unless klass.nil?
131
150
  present list&.sort_by(&:created_at).reverse, with: Labimotion::SegmentRevisionEntity, root: 'revisions'
151
+ rescue StandardError => e
152
+ Labimotion.log_exception(e, current_user)
153
+ []
132
154
  end
133
155
  end
134
156
 
@@ -152,6 +174,8 @@ module Labimotion
152
174
  post do
153
175
  upload_generics_files(current_user, params)
154
176
  true
177
+ rescue StandardError => e
178
+ Labimotion.log_exception(e, current_user)
155
179
  end
156
180
  end
157
181
 
@@ -160,6 +184,30 @@ module Labimotion
160
184
  get do
161
185
  list = Labimotion::ElementKlass.all.sort_by { |e| e.place }
162
186
  present list, with: Labimotion::ElementKlassEntity, root: 'klass'
187
+ rescue StandardError => e
188
+ Labimotion.log_exception(e, current_user)
189
+ []
190
+ end
191
+ end
192
+
193
+ namespace :fetch_repo do
194
+ desc 'fetch Generic Element Klass from Chemotion Repository'
195
+ get do
196
+ fetch_repo('ElementKlass')
197
+ end
198
+ end
199
+
200
+ namespace :create_repo_klass do
201
+ desc 'create Generic Element Klass'
202
+ params do
203
+ requires :identifier, type: String, desc: 'Identifier'
204
+ end
205
+ post do
206
+ create_repo_klass(params, current_user)
207
+ present ElementKlass.all, with: Labimotion::ElementKlassEntity, root: 'klass'
208
+ rescue StandardError => e
209
+ Labimotion.log_exception(e, current_user)
210
+ { error: e.message }
163
211
  end
164
212
  end
165
213
 
@@ -176,6 +224,8 @@ module Labimotion
176
224
  end
177
225
  post do
178
226
  deactivate_klass(params)
227
+ rescue StandardError => e
228
+ Labimotion.log_exception(e, current_user)
179
229
  end
180
230
  end
181
231
 
@@ -188,6 +238,9 @@ module Labimotion
188
238
  delete ':id' do
189
239
  delete_klass(params)
190
240
  status 201
241
+ rescue StandardError => e
242
+ Labimotion.log_exception(e, current_user)
243
+ raise e
191
244
  end
192
245
  end
193
246
 
@@ -197,14 +250,17 @@ module Labimotion
197
250
  requires :klass, type: String, desc: 'Klass', values: %w[ElementKlass SegmentKlass DatasetKlass]
198
251
  requires :id, type: Integer, desc: 'Klass ID'
199
252
  requires :properties_template, type: Hash
200
- optional :is_release, type: Boolean, default: false
253
+ optional :release, type: String, default: 'draft', desc: 'release status', values: %w[draft major minor patch]
201
254
  end
202
255
  after_validation do
203
256
  authenticate_admin!(params[:klass].gsub(/(Klass)/, 's').downcase)
204
257
  @klz = fetch_klass(params[:klass], params[:id])
205
258
  end
206
259
  post do
207
- update_template(params)
260
+ update_template(params, current_user)
261
+ rescue StandardError => e
262
+ Labimotion.log_exception(e, current_user)
263
+ raise e
208
264
  end
209
265
  end
210
266
 
@@ -216,10 +272,10 @@ module Labimotion
216
272
  optional :from_date, type: Integer, desc: 'created_date from in ms'
217
273
  optional :to_date, type: Integer, desc: 'created_date to in ms'
218
274
  optional :filter_created_at, type: Boolean, desc: 'filter by created at or updated at'
275
+ optional :sort_column, type: String, desc: 'sort by updated_at or selected layers property'
219
276
  end
220
277
  paginate per_page: 7, offset: 0, max_per_page: 100
221
278
  get do
222
-
223
279
  scope = list_serialized_elements(params, current_user)
224
280
 
225
281
  reset_pagination_page(scope)
@@ -235,6 +291,9 @@ module Labimotion
235
291
  end
236
292
  end
237
293
  { generic_elements: generic_elements }
294
+ rescue StandardError => e
295
+ Labimotion.log_exception(e, current_user)
296
+ { generic_elements: [] }
238
297
  end
239
298
 
240
299
  desc 'Return serialized element by id'
@@ -262,6 +321,8 @@ module Labimotion
262
321
  attachments: Entities::AttachmentEntity.represent(element.attachments),
263
322
  }
264
323
  end
324
+ rescue StandardError => e
325
+ Labimotion.log_exception(e, current_user)
265
326
  end
266
327
  end
267
328
 
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'open-uri'
4
+ require 'labimotion/models/hub_log'
4
5
 
5
6
  # Belong to Chemotion module
6
7
  module Labimotion
@@ -19,20 +20,25 @@ module Labimotion
19
20
  list = "Labimotion::#{params[:klass]}".constantize.where(is_active: true).where.not(released_at: nil)
20
21
  list = list.where(is_generic: true) if params[:klass] == 'ElementKlass'
21
22
  entities = Labimotion::GenericPublicEntity.represent(list, displayed: params[:with_props])
22
- # entities.length > 1 ? de_encode_json(entities) : []
23
+ rescue StandardError => e
24
+ Labimotion.log_exception(e, current_user)
25
+ []
23
26
  end
24
27
  end
25
28
  namespace :fetch do
26
29
  desc "get active generic templates"
27
30
  params do
28
31
  requires :klass, type: String, desc: 'Klass', values: %w[ElementKlass SegmentKlass DatasetKlass]
29
- # requires :fqdn, type: Integer, desc: 'FQDN'
32
+ requires :origin, type: String, desc: 'origin'
30
33
  requires :identifier, type: String, desc: 'Identifier'
31
34
  end
32
- get do
35
+ post do
33
36
  entity = "Labimotion::#{params[:klass]}".constantize.find_by(identifier: params[:identifier])
37
+ Labimotion::HubLog.create(klass: entity, origin: params[:origin], uuid: entity.uuid, version: entity.version)
34
38
  "Labimotion::#{params[:klass]}Entity".constantize.represent(entity)
35
- # entities.length > 1 ? de_encode_json(entities) : []
39
+ rescue StandardError => e
40
+ Labimotion.log_exception(e, current_user)
41
+ raise e
36
42
  end
37
43
  end
38
44
 
@@ -45,6 +51,9 @@ module Labimotion
45
51
  list = Labimotion::ElementKlass.where(is_active: true) if params[:generic_only].present? && params[:generic_only] == true
46
52
  list = Labimotion::ElementKlass.where(is_active: true) unless params[:generic_only].present? && params[:generic_only] == true
47
53
  list.pluck(:name)
54
+ rescue StandardError => e
55
+ Labimotion.log_exception(e, current_user)
56
+ []
48
57
  end
49
58
  end
50
59
 
@@ -4,7 +4,7 @@ require 'labimotion/entities/application_entity'
4
4
  module Labimotion
5
5
  # GenericKlassEntity
6
6
  class GenericKlassEntity < ApplicationEntity
7
- expose :id, :uuid, :label, :desc, :properties_template, :properties_release, :is_active,
7
+ expose :id, :uuid, :label, :desc, :properties_template, :properties_release, :is_active, :version,
8
8
  :place, :released_at, :identifier, :sync_time, :created_by, :updated_by, :created_at, :updated_at
9
9
  expose_timestamps(timestamp_fields: [:released_at])
10
10
  expose_timestamps(timestamp_fields: [:created_at])
@@ -5,6 +5,7 @@ require 'labimotion/entities/application_entity'
5
5
  # Entity module
6
6
  module Labimotion
7
7
  class GenericPublicEntity < Labimotion::ApplicationEntity
8
+ expose! :uuid
8
9
  expose! :name
9
10
  expose! :desc
10
11
  expose! :icon_name
@@ -12,6 +13,7 @@ module Labimotion
12
13
  expose! :klass_name
13
14
  expose! :label
14
15
  expose! :identifier
16
+ expose! :version
15
17
  expose! :released_at
16
18
  expose! :properties_release, if: :displayed
17
19
  expose :element_klass do |obj|
@@ -3,7 +3,7 @@
3
3
  module Labimotion
4
4
  # KlassRevisionEntity
5
5
  class KlassRevisionEntity < ApplicationEntity
6
- expose :id, :uuid, :properties_release, :released_at
6
+ expose :id, :uuid, :properties_release, :version, :released_at
7
7
 
8
8
  expose :klass_id do |object|
9
9
  klass_id = object.element_klass_id if object.respond_to? :element_klass_id
@@ -15,8 +15,9 @@ module Labimotion
15
15
 
16
16
  def create_repo_klass(params, current_user)
17
17
  response = Labimotion::TemplateHub.fetch_identifier('DatasetKlass', params[:identifier])
18
- attributes = response.slice('ols_term_id', 'label', 'desc', 'uuid', 'identifier') # .except(:id, :is_active, :place, :created_by, :created_at, :updated_at)
19
- attributes['properties_template'] = response['properties_release']
18
+ attributes = response.slice('ols_term_id', 'label', 'desc', 'uuid', 'identifier', 'properties_release', 'version') # .except(:id, :is_active, :place, :created_by, :created_at, :updated_at)
19
+ attributes['properties_release']['identifier'] = attributes['identifier']
20
+ attributes['properties_template'] = attributes['properties_release']
20
21
  attributes['place'] = ((Labimotion::DatasetKlass.all.length * 10) || 0) + 10
21
22
  attributes['is_active'] = false
22
23
  attributes['updated_by'] = current_user.id
@@ -27,8 +28,9 @@ module Labimotion
27
28
  ds.update!(attributes)
28
29
  else
29
30
  attributes['created_by'] = current_user.id
30
- Labimotion::DatasetKlass.create!(attributes)
31
+ ds = Labimotion::DatasetKlass.create!(attributes)
31
32
  end
33
+ ds.create_klasses_revision(current_user)
32
34
  rescue StandardError => e
33
35
  Labimotion.log_exception(e, current_user)
34
36
  # { error: e.message }
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'grape'
4
- require 'labimotion/version'
4
+ require 'labimotion/utils/utils'
5
5
  # require 'labimotion/models/element_klass'
6
6
  module Labimotion
7
7
  ## ElementHelpers
@@ -20,11 +20,10 @@ module Labimotion
20
20
  uuid = SecureRandom.uuid
21
21
  template = { uuid: uuid, layers: {}, select_options: {} }
22
22
  attributes = declared(params, include_missing: false)
23
- attributes[:properties_template]['uuid'] = uuid if attributes[:properties_template].present?
24
- attributes[:properties_template] = template unless attributes[:properties_template].present?
25
- attributes[:properties_template]['eln'] = Chemotion::Application.config.version if attributes[:properties_template].present?
26
- attributes[:properties_template]['labimotion'] = Labimotion::VERSION if attributes[:properties_template].present?
27
- attributes[:properties_template]['klass'] = 'ElementKlass' if attributes[:properties_template].present?
23
+ attributes[:properties_template] = template if attributes[:properties_template].nil?
24
+ attributes[:properties_template]['uuid'] = uuid
25
+ attributes[:properties_template]['pkg'] = Labimotion::Utils.pkg(attributes[:properties_template]['pkg'])
26
+ attributes[:properties_template]['klass'] = 'ElementKlass'
28
27
  attributes[:is_active] = false
29
28
  attributes[:uuid] = uuid
30
29
  attributes[:released_at] = DateTime.now
@@ -33,8 +32,8 @@ module Labimotion
33
32
 
34
33
  new_klass = Labimotion::ElementKlass.create!(attributes)
35
34
  new_klass.reload
36
- new_klass.create_klasses_revision(current_user.id)
37
- klass_names_file = Rails.root.join('config', 'klasses.json')
35
+ new_klass.create_klasses_revision(current_user)
36
+ klass_names_file = Rails.root.join('app/packs/klasses.json')
38
37
  klasses = Labimotion::ElementKlass.where(is_active: true)&.pluck(:name) || []
39
38
  File.write(klass_names_file, klasses)
40
39
  klasses
@@ -68,11 +67,12 @@ module Labimotion
68
67
  uuid = SecureRandom.uuid
69
68
  params[:properties]['uuid'] = uuid
70
69
  params[:properties]['klass_uuid'] = klass[:uuid]
71
- params[:properties]['eln'] = Chemotion::Application.config.version
72
- params[:properties]['labimotion'] = Labimotion::VERSION
70
+ params[:properties]['pkg'] = Labimotion::Utils.pkg(params[:properties]['pkg'])
73
71
  params[:properties]['klass'] = 'Element'
72
+ params[:properties]['identifier'] = klass[:identifier]
74
73
  properties = params[:properties]
75
74
  properties.delete('flow') unless properties['flow'].nil?
75
+ properties.delete('flowObject') unless properties['flowObject'].nil?
76
76
  properties.delete('select_options') unless properties['select_options'].nil?
77
77
  attributes = {
78
78
  name: params[:name],
@@ -109,14 +109,14 @@ module Labimotion
109
109
  params.delete(:container)
110
110
  params.delete(:properties)
111
111
  attributes = declared(params.except(:segments), include_missing: false)
112
- properties['eln'] = Chemotion::Application.config.version
113
- properties['labimotion'] = Labimotion::VERSION
112
+ properties['pkg'] = Labimotion::Utils.pkg(properties['pkg'])
114
113
  if element.klass_uuid != properties['klass_uuid'] || element.properties != properties || element.name != params[:name]
115
114
  properties['klass'] = 'Element'
116
115
  uuid = SecureRandom.uuid
117
116
  properties['uuid'] = uuid
118
117
 
119
118
  properties.delete('flow') unless properties['flow'].nil?
119
+ properties.delete('flowObject') unless properties['flowObject'].nil?
120
120
  properties.delete('select_options') unless properties['select_options'].nil?
121
121
 
122
122
  attributes['properties'] = properties
@@ -180,7 +180,7 @@ module Labimotion
180
180
  def element_revisions(params)
181
181
  klass = Labimotion::Element.find(params[:id])
182
182
  list = klass.elements_revisions unless klass.nil?
183
- list&.sort_by(&:created_at)&.reverse
183
+ list&.sort_by(&:created_at)&.reverse&.first(10)
184
184
  rescue StandardError => e
185
185
  Labimotion.log_exception(e, current_user)
186
186
  raise e
@@ -245,7 +245,7 @@ module Labimotion
245
245
  .where(
246
246
  element_klasses: { name: params[:el_type] },
247
247
  collections_elements: { collection_id: collection_id },
248
- ).includes(:tag, collections: :sync_collections_users).order('created_at DESC')
248
+ ).includes(:tag, collections: :sync_collections_users)
249
249
  else
250
250
  Labimotion::Element.none
251
251
  end
@@ -254,14 +254,65 @@ module Labimotion
254
254
  from = params[:from_date]
255
255
  to = params[:to_date]
256
256
  by_created_at = params[:filter_created_at] || false
257
- scope = scope.created_time_from(Time.at(from)) if from && by_created_at
258
- scope = scope.created_time_to(Time.at(to) + 1.day) if to && by_created_at
259
- scope = scope.updated_time_from(Time.at(from)) if from && !by_created_at
260
- scope = scope.updated_time_to(Time.at(to) + 1.day) if to && !by_created_at
257
+ if params[:sort_column]&.include?('.')
258
+ layer, field = params[:sort_column].split('.')
259
+
260
+ element_klass = Labimotion::ElementKlass.find_by(name: params[:el_type])
261
+ allowed_fields = element_klass.properties_release.dig('layers', layer, 'fields')&.pluck('field') || []
262
+
263
+ if field.in?(allowed_fields)
264
+ query = ActiveRecord::Base.sanitize_sql(
265
+ [
266
+ "LEFT JOIN LATERAL(
267
+ SELECT field->'value' AS value
268
+ FROM jsonb_array_elements(properties->'layers'->:layer->'fields') a(field)
269
+ WHERE field->>'field' = :field
270
+ ) a ON true",
271
+ { layer: layer, field: field },
272
+ ],
273
+ )
274
+ scope = scope.joins(query).order('value ASC NULLS FIRST')
275
+ else
276
+ scope = scope.order(updated_at: :desc)
277
+ end
278
+ else
279
+ scope = scope.order(updated_at: :desc)
280
+ end
281
+
282
+ scope = scope.elements_created_time_from(Time.at(from)) if from && by_created_at
283
+ scope = scope.elements_created_time_to(Time.at(to) + 1.day) if to && by_created_at
284
+ scope = scope.elements_updated_time_from(Time.at(from)) if from && !by_created_at
285
+ scope = scope.elements_updated_time_to(Time.at(to) + 1.day) if to && !by_created_at
261
286
  scope
262
287
  rescue StandardError => e
263
288
  Labimotion.log_exception(e, current_user)
264
289
  raise e
265
290
  end
291
+
292
+ def create_repo_klass(params, current_user)
293
+ response = Labimotion::TemplateHub.fetch_identifier('ElementKlass', params[:identifier])
294
+ attributes = response.slice('name', 'label', 'desc', 'icon_name', 'klass_prefix', 'is_generic', 'identifier', 'properties_release', 'version')
295
+ attributes['properties_release']['identifier'] = attributes['identifier']
296
+ attributes['properties_template'] = attributes['properties_release']
297
+ attributes['place'] = ((Labimotion::DatasetKlass.all.length * 10) || 0) + 10
298
+ attributes['is_active'] = false
299
+ attributes['updated_by'] = current_user.id
300
+ attributes['sync_by'] = current_user.id
301
+ attributes['sync_time'] = DateTime.now
302
+
303
+ element_klass = Labimotion::ElementKlass.find_by(identifier: attributes['identifier'])
304
+ if element_klass.present?
305
+ element_klass.update!(attributes)
306
+ else
307
+ attributes['created_by'] = current_user.id
308
+ element_klass = Labimotion::ElementKlass.create!(attributes)
309
+ end
310
+ element_klass.create_klasses_revision(current_user)
311
+ rescue StandardError => e
312
+ Labimotion.log_exception(e, current_user)
313
+ # { error: e.message }
314
+ raise e
315
+ end
316
+
266
317
  end
267
318
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  require 'grape'
3
- require 'labimotion/version'
3
+ require 'labimotion/utils/utils'
4
4
  # Helper for associated sample
5
5
  module Labimotion
6
6
  ## Generic Helpers
@@ -41,23 +41,22 @@ module Labimotion
41
41
  raise e
42
42
  end
43
43
 
44
- def update_template(params)
44
+ def update_template(params, current_user)
45
45
  klz = fetch_klass(params[:klass], params[:id])
46
46
  uuid = SecureRandom.uuid
47
47
  properties = params[:properties_template]
48
- if Labimotion::IS_RAILS5 == false
49
- properties['uuid'] = uuid unless params[:is_release] == true && @klz.identifier.present?
50
- else
51
- properties['uuid'] = uuid
52
- end
53
- properties['eln'] = Chemotion::Application.config.version
54
- properties['labimotion'] = Labimotion::VERSION
55
- properties['klass'] = @klz.class.name
48
+ properties['uuid'] = uuid
49
+ klz.version = Labimotion::Utils.next_version(params[:release], klz.version)
50
+ properties['version'] = klz.version
51
+ properties['pkg'] = Labimotion::Utils.pkg(params['pkg'] || (klz.properties_template && klz.properties_template['pkg']))
52
+ properties['klass'] = klz.class.name.split('::').last
53
+ properties['identifier'] = klz.identifier
54
+ properties.delete('eln') if properties['eln'].present?
56
55
  klz.updated_by = current_user.id
57
56
  klz.properties_template = properties
58
57
  klz.save!
59
58
  klz.reload
60
- klz.create_klasses_revision(current_user.id) if params[:is_release] == true
59
+ klz.create_klasses_revision(current_user) if params[:release] != 'draft'
61
60
  klz
62
61
  rescue StandardError => e
63
62
  Labimotion.log_exception(e, current_user)
@@ -89,7 +88,7 @@ module Labimotion
89
88
  def list_klass_revisions(params)
90
89
  klass = "Labimotion::#{params[:klass]}".constantize.find_by(id: params[:id])
91
90
  list = klass.send("#{params[:klass].underscore}es_revisions") unless klass.nil?
92
- list.sort_by(&:released_at).reverse
91
+ list&.order(released_at: :desc)&.limit(10)
93
92
  rescue StandardError => e
94
93
  Labimotion.log_exception(e, current_user)
95
94
  raise e
@@ -97,12 +96,8 @@ module Labimotion
97
96
 
98
97
 
99
98
  ###############
100
-
101
-
102
99
  def generate_klass_file
103
- klass_dir = File.join(Rails.root, 'data')
104
- !File.directory?(klass_dir) && FileUtils.mkdir_p(klass_dir)
105
- klass_names_file = File.join(klass_dir, 'klasses.json')
100
+ klass_names_file = Rails.root.join('app/packs/klasses.json')
106
101
  klasses = Labimotion::ElementKlass.where(is_active: true)&.pluck(:name) || []
107
102
  File.write(klass_names_file, klasses)
108
103
  rescue StandardError => e
@@ -193,37 +188,37 @@ module Labimotion
193
188
  raise e
194
189
  end
195
190
 
196
- def create_attachments(files, del_files, type, id, user_id)
191
+ def create_attachments(files, del_files, type, id, identifier, user_id)
197
192
  attach_ary = []
198
- (files || []).each do |file|
193
+ (files || []).each_with_index do |file, index|
199
194
  next unless (tempfile = file[:tempfile])
200
195
 
201
- a = Attachment.new(
196
+ att = Attachment.new(
202
197
  bucket: file[:container_id],
203
198
  filename: file[:filename],
204
199
  con_state: Labimotion::ConState::NONE,
205
200
  file_path: file[:tempfile],
206
201
  created_by: user_id,
207
202
  created_for: user_id,
203
+ identifier: identifier[index],
208
204
  content_type: file[:type],
209
205
  attachable_type: type,
210
206
  attachable_id: id,
211
207
  )
212
208
  begin
213
- a.save!
214
- attach_ary.push(a.id)
209
+ att.save!
210
+ attach_ary.push(att.id)
215
211
  ensure
216
212
  tempfile.close
217
213
  tempfile.unlink
218
214
  end
219
215
  end
220
216
  unless (del_files || []).empty?
221
- Attachment.where('id IN (?) AND attachable_type = (?)', del_files.map!(&:to_i),
222
- type).update_all(attachable_id: nil)
217
+ Attachment.where('id IN (?) AND attachable_type = (?)', del_files.map!(&:to_i), type).update_all(attachable_id: nil)
223
218
  end
224
219
  attach_ary
225
220
  rescue StandardError => e
226
- Labimotion.log_exception(e, current_user)
221
+ Labimotion.log_exception(e)
227
222
  raise e
228
223
  end
229
224
 
@@ -246,7 +241,7 @@ module Labimotion
246
241
  filter_list || []
247
242
  rescue StandardError => e
248
243
  Labimotion.log_exception(e, current_user)
249
- raise e
244
+ { error: 'Cannot connect to Chemotion Repository' }
250
245
  end
251
246
  end
252
247
  end
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
  require 'grape'
3
3
  require 'labimotion/models/segment_klass'
4
+ require 'labimotion/utils/utils'
5
+
4
6
  module Labimotion
5
7
  ## ElementHelpers
6
8
  module SegmentHelpers
@@ -26,8 +28,7 @@ module Labimotion
26
28
  attributes = declared(params, include_missing: false)
27
29
  attributes[:properties_template]['uuid'] = uuid if attributes[:properties_template].present?
28
30
  template = (attributes[:properties_template].presence || template)
29
- template['eln'] = Chemotion::Application.config.version
30
- template['labimotion'] = Labimotion::VERSION
31
+ template['pkg'] = Labimotion::Utils.pkg(template['pkg'])
31
32
  template['klass'] = 'SegmentKlass'
32
33
  attributes.merge!(properties_template: template, element_klass: @klass, created_by: current_user.id,
33
34
  place: place)
@@ -37,7 +38,7 @@ module Labimotion
37
38
  attributes[:properties_release] = attributes[:properties_template]
38
39
  klass = Labimotion::SegmentKlass.create!(attributes)
39
40
  klass.reload
40
- klass.create_klasses_revision(current_user.id)
41
+ klass.create_klasses_revision(current_user)
41
42
  klass
42
43
  rescue StandardError => e
43
44
  Labimotion.log_exception(e, current_user)
@@ -64,8 +65,9 @@ module Labimotion
64
65
 
65
66
  def create_repo_klass(params, current_user)
66
67
  response = Labimotion::TemplateHub.fetch_identifier('SegmentKlass', params[:identifier])
67
- attributes = response.slice('label', 'desc', 'uuid', 'identifier', 'released_at') # .except(:id, :is_active, :place, :created_by, :created_at, :updated_at)
68
- attributes['properties_template'] = response['properties_release']
68
+ attributes = response.slice('label', 'desc', 'uuid', 'identifier', 'released_at', 'properties_release', 'version')
69
+ attributes['properties_release']['identifier'] = attributes['identifier']
70
+ attributes['properties_template'] = attributes['properties_release']
69
71
  attributes['place'] = ((Labimotion::SegmentKlass.all.length * 10) || 0) + 10
70
72
  attributes['is_active'] = false
71
73
  attributes['updated_by'] = current_user.id
@@ -74,20 +76,21 @@ module Labimotion
74
76
 
75
77
  element_klass = Labimotion::ElementKlass.find_by(identifier: response['element_klass']['identifier'])
76
78
  element_klass = Labimotion::ElementKlass.find_by(name: response['element_klass']['name']) if element_klass.nil?
77
- if element_klass.nil?
78
- el_attributes = response['element_klass'].slice('name', 'label', 'desc', 'uuid', 'identifier', 'icon_name', 'klass_prefix', 'is_generic', 'released_at')
79
- el_attributes['properties_template'] = response['element_klass']['properties_release']
80
- Labimotion::ElementKlass.create!(el_attributes)
81
- end
79
+ return { error: 'ElementKlass not found' } if element_klass.nil?
82
80
 
81
+ # el_attributes = response['element_klass'].slice('name', 'label', 'desc', 'uuid', 'identifier', 'icon_name', 'klass_prefix', 'is_generic', 'released_at')
82
+ # el_attributes['properties_template'] = response['element_klass']['properties_release']
83
+ # Labimotion::ElementKlass.create!(el_attributes)
83
84
 
84
- if Labimotion::SegmentKlass.find_by(ols_term_id: attributes['ols_term_id']).present?
85
- ds = Labimotion::SegmentKlass.find_by(ols_term_id: attributes['ols_term_id'])
86
- ds.update!(attributes)
85
+ attributes['element_klass_id'] = element_klass.id
86
+ segment_klass = Labimotion::SegmentKlass.find_by(identifier: attributes['identifier'])
87
+ if segment_klass.present?
88
+ segment_klass.update!(attributes)
87
89
  else
88
90
  attributes['created_by'] = current_user.id
89
- Labimotion::SegmentKlass.create!(attributes)
91
+ segment_klass = Labimotion::SegmentKlass.create!(attributes)
90
92
  end
93
+ segment_klass.create_klasses_revision(current_user)
91
94
  rescue StandardError => e
92
95
  Labimotion.log_exception(e, current_user)
93
96
  raise e
@@ -5,6 +5,7 @@ require 'uri'
5
5
  require 'json'
6
6
  require 'date'
7
7
  require 'labimotion/version'
8
+ require 'labimotion/utils/utils'
8
9
 
9
10
  # rubocop: disable Metrics/AbcSize
10
11
  # rubocop: disable Metrics/MethodLength
@@ -116,7 +117,7 @@ module Labimotion
116
117
  )
117
118
  # att.attachment_attacher.attach(tmp_file)
118
119
  if att.valid? && Labimotion::IS_RAILS5 == false
119
- att.attachment_attacher.create_derivatives
120
+ ## att.attachment_attacher.create_derivatives
120
121
  att.save!
121
122
  end
122
123
  if att.valid? && Labimotion::IS_RAILS5 == true
@@ -143,12 +144,16 @@ module Labimotion
143
144
  end
144
145
 
145
146
  def self.process(data)
146
- return if data[:a]&.attachable_type != 'Container'
147
-
147
+ return data[:a].con_state if data[:a]&.attachable_type != 'Container'
148
148
  response = nil
149
149
  begin
150
150
  ofile = Rails.root.join(data[:f], data[:a].filename)
151
- FileUtils.cp(data[:a].store.path, ofile)
151
+ if Labimotion::IS_RAILS5 == true
152
+ FileUtils.cp(data[:a].store.path, ofile)
153
+ else
154
+ FileUtils.cp(data[:a].attachment_url, ofile)
155
+ end
156
+
152
157
  File.open(ofile, 'r') do |f|
153
158
  body = { file: f }
154
159
  response = HTTParty.post(
@@ -160,12 +165,14 @@ module Labimotion
160
165
  end
161
166
  if response.ok?
162
167
  Labimotion::Converter.handle_response(data[:a], response)
168
+ Labimotion::ConState::PROCESSED
163
169
  else
164
170
  Labimotion::Converter.logger.error ["Converter Response Error: id: [#{data[:a]&.id}], filename: [#{data[:a]&.filename}], response: #{response}"].join($INPUT_RECORD_SEPARATOR)
171
+ Labimotion::ConState::ERROR
165
172
  end
166
- response
167
173
  rescue StandardError => e
168
- raise e
174
+ Labimotion::Converter.logger.error ["process fail: #{id}", e.message, *e.backtrace].join($INPUT_RECORD_SEPARATOR)
175
+ Labimotion::ConState::ERROR
169
176
  ensure
170
177
  FileUtils.rm_f(ofile)
171
178
  end
@@ -174,14 +181,14 @@ module Labimotion
174
181
  def self.jcamp_converter(id)
175
182
  resp = nil
176
183
  begin
184
+
177
185
  data = Labimotion::Converter.vor_conv(id)
178
186
  return if data.nil?
179
187
 
180
- resp = Labimotion::Converter.process(data)
181
- resp&.success? ? Labimotion::ConState::PROCESSED : Labimotion::ConState::ERROR
188
+ Labimotion::Converter.process(data)
182
189
  rescue StandardError => e
183
- Labimotion::ConState::ERROR
184
190
  Labimotion::Converter.logger.error ["jcamp_converter fail: #{id}", e.message, *e.backtrace].join($INPUT_RECORD_SEPARATOR)
191
+ Labimotion::ConState::ERROR
185
192
  end
186
193
  end
187
194
 
@@ -209,8 +216,7 @@ module Labimotion
209
216
  uuid = SecureRandom.uuid
210
217
  props = klass.properties_release
211
218
  props['uuid'] = uuid
212
- props['eln'] = Chemotion::Application.config.version
213
- props['labimotion'] = Labimotion::VERSION
219
+ props['pkg'] = Labimotion::Utils.pkg(props['pkg'])
214
220
  props['klass'] = 'Dataset'
215
221
  Labimotion::Dataset.create!(
216
222
  uuid: uuid,
@@ -228,6 +234,8 @@ module Labimotion
228
234
  new_prop = dataset.properties
229
235
  dsr.each do |ds|
230
236
  layer = layers[ds[:layer]]
237
+ next if layer.nil? || layer['fields'].nil?
238
+
231
239
  fields = layer['fields'].select{ |f| f['field'] == ds[:field] }
232
240
  fi = fields&.first
233
241
  idx = layer['fields'].find_index(fi)
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  require 'export_table'
3
+ require 'labimotion/version'
3
4
 
4
5
  module Labimotion
5
6
  ## ExportDataset
@@ -101,9 +102,18 @@ module Labimotion
101
102
  cds.attachments.where(aasm_state: 'csv').each do |att|
102
103
  name = File.basename(att.filename, '.csv')
103
104
  sheet = @xfile.workbook.add_worksheet(name: name)
104
- File.open(att.store.path) do |fi|
105
- fi.each_line do |line|
106
- sheet.add_row(line.split(','))
105
+
106
+ if Labimotion::IS_RAILS5 == true
107
+ File.open(att.store.path) do |fi|
108
+ fi.each_line do |line|
109
+ sheet.add_row(line.split(','))
110
+ end
111
+ end
112
+ else
113
+ File.open(att.attachment_url) do |fi|
114
+ fi.each_line do |line|
115
+ sheet.add_row(line.split(','))
116
+ end
107
117
  end
108
118
  end
109
119
  end
@@ -1,12 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'labimotion/version'
4
+ require 'labimotion/utils/utils'
5
+
3
6
  module Labimotion
4
7
  ## NmrMapper
5
8
  class NmrMapper
6
9
  def self.is_brucker_binary(id)
7
10
  att = Attachment.find(id)
8
- if att&.attachment_attacher&.file&.url
9
- Zip::File.open(att.attachment_attacher.file.url) do |zip_file|
11
+ if Labimotion::IS_RAILS5 == true
12
+ Zip::File.open(att.store.path) do |zip_file|
10
13
  zip_file.each do |entry|
11
14
  if entry.name.include?('/pdata/') && entry.name.include?('parm.txt')
12
15
  metadata = entry.get_input_stream.read.force_encoding('UTF-8')
@@ -14,6 +17,17 @@ module Labimotion
14
17
  end
15
18
  end
16
19
  end
20
+ else
21
+ if att&.attachment_attacher&.file&.url
22
+ Zip::File.open(att.attachment_attacher.file.url) do |zip_file|
23
+ zip_file.each do |entry|
24
+ if entry.name.include?('/pdata/') && entry.name.include?('parm.txt')
25
+ metadata = entry.get_input_stream.read.force_encoding('UTF-8')
26
+ return metadata
27
+ end
28
+ end
29
+ end
30
+ end
17
31
  end
18
32
  nil
19
33
  end
@@ -247,8 +261,7 @@ module Labimotion
247
261
  uuid = SecureRandom.uuid
248
262
  props = klass.properties_release
249
263
  props['uuid'] = uuid
250
- props['eln'] = Chemotion::Application.config.version
251
- props['labimotion'] = Labimotion::VERSION
264
+ props['pkg'] = Labimotion::Utils.pkg(props['pkg'])
252
265
  props['klass'] = 'Dataset'
253
266
  dataset = Labimotion::Dataset.create!(
254
267
  uuid: uuid,
@@ -1,17 +1,33 @@
1
1
  # frozen_string_literal: true
2
+ require 'labimotion/version'
3
+ require 'labimotion/utils/utils'
2
4
 
3
5
  module Labimotion
4
6
  class NmrMapperRepo
5
7
  def self.is_brucker_binary(id)
6
8
  att = Attachment.find(id)
7
- Zip::File.open(att.store.path) do |zip_file|
8
- zip_file.each do |entry|
9
- if entry.name.include?('/pdata/') && entry.name.include?('parm.txt')
10
- metadata = entry.get_input_stream.read.force_encoding('UTF-8')
11
- return metadata
9
+ if Labimotion::IS_RAILS5 == true
10
+ Zip::File.open(att.store.path) do |zip_file|
11
+ zip_file.each do |entry|
12
+ if entry.name.include?('/pdata/') && entry.name.include?('parm.txt')
13
+ metadata = entry.get_input_stream.read.force_encoding('UTF-8')
14
+ return metadata
15
+ end
16
+ end
17
+ end
18
+ else
19
+ if att&.attachment_attacher&.file&.url
20
+ Zip::File.open(att.attachment_attacher.file.url) do |zip_file|
21
+ zip_file.each do |entry|
22
+ if entry.name.include?('/pdata/') && entry.name.include?('parm.txt')
23
+ metadata = entry.get_input_stream.read.force_encoding('UTF-8')
24
+ return metadata
25
+ end
26
+ end
12
27
  end
13
28
  end
14
29
  end
30
+
15
31
  nil
16
32
  end
17
33
 
@@ -245,8 +261,7 @@ module Labimotion
245
261
  uuid = SecureRandom.uuid
246
262
  props = klass.properties_release
247
263
  props['uuid'] = uuid
248
- props['eln'] = Chemotion::Application.config.version
249
- props['labimotion'] = Labimotion::VERSION
264
+ props['pkg'] = Labimotion::Utils.pkg(props['pkg'])
250
265
  props['klass'] = 'Dataset'
251
266
  dataset = Labimotion::Dataset.create!(
252
267
  uuid: uuid,
@@ -20,7 +20,7 @@ module Labimotion
20
20
 
21
21
 
22
22
  def self.header(opt = {})
23
- opt || {}
23
+ opt || { timeout: 10, headers: { 'Content-Type' => 'text/json' } }
24
24
  end
25
25
 
26
26
  def self.handle_response(oat, response) # rubocop: disable Metrics/PerceivedComplexity
@@ -35,16 +35,22 @@ module Labimotion
35
35
 
36
36
  def self.list(klass)
37
37
  body = { klass: klass }
38
- response = HTTParty.get("#{uri('list')}?klass=#{klass}")
38
+ response = HTTParty.get("#{uri('list')}?klass=#{klass}", timeout: 10)
39
39
  # response.parsed_response if response.code == 200
40
40
  JSON.parse(response.body) if response.code == 200
41
+ rescue StandardError => e
42
+ Labimotion.log_exception(e)
43
+ error!('Cannot connect to Chemotion Repository', 401)
41
44
  end
42
45
 
43
46
  def self.fetch_identifier(klass, identifier)
44
47
  # body = { klass: klass, identifier: identifier }
45
- response = HTTParty.get("#{uri('fetch')}?klass=#{klass}&identifier=#{identifier}")
48
+ response = HTTParty.get("#{uri('fetch')}?klass=#{klass}&identifier=#{identifier}", timeout: 10)
46
49
  # response.parsed_response if response.code == 200
47
50
  JSON.parse(response.body) if response.code == 200
51
+ rescue StandardError => e
52
+ Labimotion.log_exception(e)
53
+ error!('Cannot connect to Chemotion Repository', 401)
48
54
  end
49
55
  end
50
56
  end
@@ -9,7 +9,7 @@ module Labimotion
9
9
  before_create :init_converter
10
10
  after_update :exec_converter
11
11
  def init_converter
12
- return if con_state.present?
12
+ return if self.has_attribute?(:con_state) == false || con_state.present?
13
13
  if Rails.configuration.try(:converter).try(:url) && ACCEPTED_FORMATS.include?(File.extname(filename&.downcase))
14
14
  self.con_state = Labimotion::ConState::WAIT
15
15
  end
@@ -23,7 +23,7 @@ module Labimotion
23
23
 
24
24
  def exec_converter
25
25
  #return if attachable_id.nil?
26
- return if con_state.nil? || con_state == Labimotion::ConState::NONE
26
+ return if self.has_attribute?(:con_state) == false || con_state.nil? || con_state == Labimotion::ConState::NONE
27
27
  case con_state
28
28
  when Labimotion::ConState::NMR
29
29
  content = Labimotion::NmrMapperRepo.is_brucker_binary(id)
@@ -36,6 +36,7 @@ module Labimotion
36
36
  when Labimotion::ConState::WAIT
37
37
  self.con_state = Labimotion::Converter.jcamp_converter(id)
38
38
  end
39
+ update_column(:con_state, con_state)
39
40
  end
40
41
  end
41
42
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Datasetable concern
4
+ require 'labimotion/utils/utils'
4
5
 
5
6
  module Labimotion
6
7
  ## Datasetable concern
@@ -21,23 +22,18 @@ module Labimotion
21
22
  klass = Labimotion::DatasetKlass.find_by(id: args[:dataset_klass_id])
22
23
  uuid = SecureRandom.uuid
23
24
  props = args[:properties]
24
- props['eln'] = Chemotion::Application.config.version
25
- props['labimotion'] = Labimotion::VERSION
25
+ props['pkg'] = Labimotion::Utils.pkg(props['pkg'])
26
+ props['identifier'] = klass.identifier
27
+ props['uuid'] = uuid
28
+ props['klass'] = 'Dataset'
29
+
26
30
  ds = Labimotion::Dataset.find_by(element_type: self.class.name, element_id: id)
27
31
  if ds.present? && (ds.klass_uuid != props['klass_uuid'] || ds.properties != props)
28
- props['uuid'] = uuid
29
- props['eln'] = Chemotion::Application.config.version
30
- props['labimotion'] = Labimotion::VERSION
31
- props['klass'] = 'Dataset'
32
32
  ds.update!(properties_release: klass.properties_release, uuid: uuid, dataset_klass_id: args[:dataset_klass_id], properties: props, klass_uuid: props['klass_uuid'])
33
33
  end
34
34
  return if ds.present?
35
35
 
36
- props['uuid'] = uuid
37
36
  props['klass_uuid'] = klass.uuid
38
- props['eln'] = Chemotion::Application.config.version
39
- props['labimotion'] = Labimotion::VERSION
40
- props['klass'] = 'Dataset'
41
37
  Labimotion::Dataset.create!(properties_release: klass.properties_release, uuid: uuid, dataset_klass_id: args[:dataset_klass_id], element_type: self.class.name, element_id: id, properties: props, klass_uuid: klass.uuid)
42
38
  end
43
39
 
@@ -1,34 +1,42 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Labimotion
4
- module GenericKlassRevisions
4
+ ## Generic Klass Revisions Helpers
5
+ module GenericKlassRevisions
5
6
  extend ActiveSupport::Concern
6
7
  included do
7
8
  # has_many :element_klasses_revisions, dependent: :destroy
8
9
  end
9
10
 
10
- def create_klasses_revision(user_id=0)
11
+ def create_klasses_revision(current_user)
11
12
  properties_release = properties_template
12
- # (properties_release['layers'] || {}).keys.each do |key|
13
- # properties_release['layers'][key]['layer'] = properties_release['layers'][key]['key']
14
- # end
13
+ migrate_workflow if properties_release['flow'].present?
15
14
 
16
- if properties_release['flow'].present?
17
- elements = (properties_release['flow']['elements'] || []).map do |el|
15
+ if properties_release['flowObject'].present?
16
+ elements = (properties_release['flowObject']['nodes'] || []).map do |el|
18
17
  if el['data'].present? && el['data']['lKey'].present?
19
18
  layer = properties_release['layers'][el['data']['lKey']]
20
19
  el['data']['layer'] = layer if layer.present?
21
20
  end
22
21
  el
23
22
  end
24
- properties_release['flow']['elements'] = elements
23
+ properties_release['flowObject']['nodes'] = elements
25
24
  end
25
+ klass_attributes = {
26
+ uuid: properties_template['uuid'],
27
+ properties_template: properties_release,
28
+ properties_release: properties_release,
29
+ released_at: DateTime.now,
30
+ updated_by: current_user&.id,
31
+ released_by: current_user&.id,
32
+ }
26
33
 
27
- self.update!({ uuid: properties_template['uuid'], properties_release: properties_release, released_at: DateTime.now })
34
+ self.update!(klass_attributes)
28
35
  reload
29
36
  attributes = {
30
- released_by: user_id,
37
+ released_by: released_by,
31
38
  uuid: uuid,
39
+ version: version,
32
40
  properties_release: properties_release,
33
41
  released_at: released_at
34
42
  }
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'labimotion/utils/utils'
4
+
3
5
  module Labimotion
4
6
  # Segmentable concern
5
7
  module Segmentable
@@ -45,25 +47,18 @@ module Labimotion
45
47
  klass = Labimotion::SegmentKlass.find_by(id: seg['segment_klass_id'])
46
48
  uuid = SecureRandom.uuid
47
49
  props = seg['properties']
48
- props['eln'] = Chemotion::Application.config.version
49
- props['labimotion'] = Labimotion::VERSION
50
+ props['pkg'] = Labimotion::Utils.pkg(props['pkg'])
51
+ props['identifier'] = identifier
52
+ props['uuid'] = uuid
53
+ props['klass'] = 'Segment'
50
54
  segment = Labimotion::Segment.find_by(element_type: Labimotion::Utils.element_name(self.class.name), element_id: self.id, segment_klass_id: seg['segment_klass_id'])
51
55
  if segment.present? && (segment.klass_uuid != props['klass_uuid'] || segment.properties != props)
52
- props['uuid'] = uuid
53
- props['eln'] = Chemotion::Application.config.version
54
- props['labimotion'] = Labimotion::VERSION
55
- props['klass'] = 'Segment'
56
-
57
56
  segment.update!(properties_release: klass.properties_release, properties: props, uuid: uuid, klass_uuid: props['klass_uuid'])
58
57
  segments.push(segment)
59
58
  end
60
59
  next if segment.present?
61
60
 
62
- props['uuid'] = uuid
63
61
  props['klass_uuid'] = klass.uuid
64
- props['eln'] = Chemotion::Application.config.version
65
- props['labimotion'] = Labimotion::VERSION
66
- props['klass'] = 'Segment'
67
62
  segment = Labimotion::Segment.create!(properties_release: klass.properties_release, segment_klass_id: seg['segment_klass_id'], element_type: Labimotion::Utils.element_name(self.class.name), element_id: self.id, properties: props, created_by: args[:current_user_id], uuid: uuid, klass_uuid: klass.uuid)
68
63
  segments.push(segment)
69
64
  end
@@ -0,0 +1,27 @@
1
+ module Labimotion
2
+ # Segmentable concern
3
+ module Workflow
4
+ extend ActiveSupport::Concern
5
+
6
+ def split_workflow(properties)
7
+ return if properties['flow'].nil?
8
+
9
+ if properties['flow'].present?
10
+ properties['flowObject'] = {}
11
+ elements = properties['flow']['elements'] || {}
12
+ properties['flowObject']['nodes'] = elements.select { |obj| obj['source'].nil? }
13
+ properties['flowObject']['edges'] = elements.select { |obj| obj['source'] && obj['source'] != obj['target'] }.map do |obj|
14
+ obj['markerEnd'] = { 'type': 'arrowclosed' }
15
+ obj
16
+ end
17
+ properties['flowObject']['viewport'] = {
18
+ "x": properties['flow']['position'][0] || 0,
19
+ "y": properties['flow']['position'][1] || 0,
20
+ "zoom": properties['flow']['zoom'] || 1
21
+ }
22
+ properties.delete('flow')
23
+ end
24
+ properties
25
+ end
26
+ end
27
+ end
@@ -1,16 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
  require 'labimotion/models/concerns/generic_revisions'
3
3
  require 'labimotion/models/concerns/segmentable'
4
+ require 'labimotion/models/concerns/workflow'
4
5
 
5
6
  module Labimotion
6
7
  class Element < ApplicationRecord
7
8
  acts_as_paranoid
8
9
  self.table_name = :elements
9
- include PgSearch
10
+ include PgSearch if Labimotion::IS_RAILS5 == true
11
+ include PgSearch::Model if Labimotion::IS_RAILS5 == false
10
12
  include ElementUIStateScopes
11
13
  include Collectable
12
14
  ## include AnalysisCodes
13
15
  include Taggable
16
+ include Workflow
14
17
  include Segmentable
15
18
  include GenericRevisions
16
19
 
@@ -106,6 +109,16 @@ module Labimotion
106
109
  preview && Base64.encode64(preview) || 'not available'
107
110
  end
108
111
 
112
+
113
+ def migrate_workflow
114
+ return if properties.nil? || properties_release.nil?
115
+
116
+ return if properties['flow'].nil? && properties_release['flow'].nil?
117
+
118
+ update_column(:properties, split_workflow(properties)) if properties['flow']
119
+ update_column(:properties_release, split_workflow(properties_release)) if properties_release['flow']
120
+ end
121
+
109
122
  private
110
123
 
111
124
  def delete_attachment
@@ -1,11 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
  require 'labimotion/models/concerns/generic_klass_revisions'
3
+ require 'labimotion/models/concerns/workflow'
3
4
 
4
5
  module Labimotion
5
6
  class ElementKlass < ApplicationRecord
6
- acts_as_paranoid
7
7
  self.table_name = :element_klasses
8
+ acts_as_paranoid
8
9
  include GenericKlassRevisions
10
+ include Workflow
9
11
  has_many :elements, dependent: :destroy, class_name: 'Labimotion::Element'
10
12
  has_many :segment_klasses, dependent: :destroy, class_name: 'Labimotion::SegmentKlass'
11
13
  has_many :element_klasses_revisions, dependent: :destroy, class_name: 'Labimotion::ElementKlassesRevision'
@@ -16,10 +18,18 @@ module Labimotion
16
18
  klasses = []
17
19
  ensure
18
20
  File.write(
19
- Rails.root.join('config', 'klasses.json'),
21
+ Rails.root.join('app/packs/klasses.json'),
20
22
  klasses&.to_json || []
21
23
  )
22
24
  end
23
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
24
34
  end
25
35
  end
@@ -1,9 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'labimotion/models/concerns/workflow'
4
+
3
5
  module Labimotion
4
6
  class ElementKlassesRevision < ApplicationRecord
5
7
  acts_as_paranoid
6
8
  self.table_name = :element_klasses_revisions
9
+ include Workflow
7
10
  has_one :element_klass, class_name: 'Labimotion::ElementKlass'
11
+
12
+
13
+ def migrate_workflow
14
+ return if properties_release.nil? || properties_release['flow'].nil?
15
+
16
+ update_column(:properties_release, split_workflow(properties_release)) if properties_release['flow']
17
+ end
8
18
  end
9
19
  end
@@ -0,0 +1,8 @@
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,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'labimotion/version'
3
4
  module Labimotion
5
+ ## Generic Utils
4
6
  class Utils
5
7
  def self.klass_by_collection(name)
6
8
  names = name.split('::')
@@ -53,5 +55,36 @@ module Labimotion
53
55
  def self.element_name_dc(name)
54
56
  Labimotion::Utils.element_name(name)&.downcase
55
57
  end
58
+
59
+ def self.next_version(release, current_version)
60
+ case release
61
+ when 'draft'
62
+ current_version
63
+ when 'major'
64
+ if current_version.nil? || current_version.split('.').length < 2
65
+ '1.0'
66
+ else
67
+ "#{current_version&.split('.').first.to_i + 1}.0"
68
+ end
69
+ when 'minor'
70
+ if current_version.nil? || current_version&.split('.').length < 2
71
+ '0.1'
72
+ else
73
+ "#{current_version&.split('.').first.to_i.to_s}.#{current_version&.split('.').last.to_i + 1}"
74
+ end
75
+ else
76
+ current_version
77
+ end
78
+ rescue StandardError => e
79
+ Labimotion.log_exception(e)
80
+ current_version
81
+ end
82
+
83
+ def self.pkg(pkg)
84
+ pkg = {} if pkg.nil?
85
+ pkg['eln'] = Chemotion::Application.config.version
86
+ pkg['labimotion'] = Labimotion::VERSION
87
+ pkg
88
+ end
56
89
  end
57
90
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Labimotion
4
- VERSION = '0.1.12'
5
4
  IS_RAILS5 = true
5
+ VERSION = '0.1.14' if Labimotion::IS_RAILS5 == true
6
+ VERSION = '1.0.1' if Labimotion::IS_RAILS5 == false
6
7
  end
data/lib/labimotion.rb CHANGED
@@ -7,7 +7,7 @@ module Labimotion
7
7
  @@labimotion_logger ||= Logger.new(Rails.root.join('log/labimotion.log')) # rubocop:disable Style/ClassVars
8
8
  end
9
9
 
10
- def self.log_exception(exception, current_user = {})
10
+ def self.log_exception(exception, current_user = nil)
11
11
  Labimotion.logger.error("version: #{Labimotion::VERSION}; #{Labimotion::IS_RAILS5}, (#{current_user&.id}) \n Exception: #{exception.message}")
12
12
  Labimotion.logger.error(exception.backtrace.join("\n"))
13
13
  end
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.1.12
4
+ version: 0.1.14
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-08-17 00:00:00.000000000 Z
12
+ date: 2023-08-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -73,6 +73,7 @@ files:
73
73
  - lib/labimotion/models/concerns/generic_klass_revisions.rb
74
74
  - lib/labimotion/models/concerns/generic_revisions.rb
75
75
  - lib/labimotion/models/concerns/segmentable.rb
76
+ - lib/labimotion/models/concerns/workflow.rb
76
77
  - lib/labimotion/models/dataset.rb
77
78
  - lib/labimotion/models/dataset_klass.rb
78
79
  - lib/labimotion/models/dataset_klasses_revision.rb
@@ -83,6 +84,7 @@ files:
83
84
  - lib/labimotion/models/elements_element.rb
84
85
  - lib/labimotion/models/elements_revision.rb
85
86
  - lib/labimotion/models/elements_sample.rb
87
+ - lib/labimotion/models/hub_log.rb
86
88
  - lib/labimotion/models/segment.rb
87
89
  - lib/labimotion/models/segment_klass.rb
88
90
  - lib/labimotion/models/segment_klasses_revision.rb