labimotion 0.3.1 → 1.0.0

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: 5b8192a47d907ab3aab31d14c951ccfe6a9552f04cc57896dffc592d850c90d0
4
- data.tar.gz: 54be5a8e125a16ebbb8ee8ac48de31e42678c9473da2c7c2e32394585b746ffa
3
+ metadata.gz: 387a4b4a47a140008970b10f005472e8ba882c80ddaab99863ced5acdb0dfa29
4
+ data.tar.gz: 90f5839a92d045e45861a2354354bf5ef1542799a484cda94fa9c1263c206d5e
5
5
  SHA512:
6
- metadata.gz: 1cb3dd9177e8799a2a07c3454587f6ae7d925e99dd22ce0423a3513cf8992def50d7f900992d9c4db217617473b4ec87b0dcdc02551e3841ba66183efae6159d
7
- data.tar.gz: 595b810eee22f50e8ef15db20b2a8b37dc6ad14b2d05d0362568cd235be2cf7358b0ca089722ac09c364a57a5d9e64992fbba5afa342182f9647a602b292467e
6
+ metadata.gz: cca4c43074754aefbe3f2b3ca09b55af69d25ebf2a4b7f456990bc692ee7ab19905020aed4505d6360b720d94e497e91ab5910b8c50d4b5b914a01d23e840796
7
+ data.tar.gz: 5280180e034e2bd2a38000b62e8001ebee247cae2dd29e30f5b66eb3292d11e0e9f0566986c5eb918e6f6dcfc9d95024553204d834da44e7a1aee2b13500d454
@@ -30,7 +30,7 @@ module Labimotion
30
30
  namespace :fetch_repo do
31
31
  desc 'fetch Generic Dataset Klass from Chemotion Repository'
32
32
  get do
33
- fetch_repo('DatasetKlass', current_user)
33
+ fetch_repo('DatasetKlass')
34
34
  end
35
35
  end
36
36
 
@@ -40,9 +40,8 @@ module Labimotion
40
40
  requires :identifier, type: String, desc: 'Identifier'
41
41
  end
42
42
  post do
43
- msg = create_repo_klass(params, current_user, request.headers['Origin'])
44
- klass = Labimotion::DatasetKlassEntity.represent(DatasetKlass.all)
45
- { status: msg[:status], message: msg[:message], klass: klass }
43
+ create_repo_klass(params, current_user)
44
+ present DatasetKlass.all, with: Labimotion::DatasetKlassEntity, root: 'klass'
46
45
  rescue StandardError => e
47
46
  Labimotion.log_exception(e, current_user)
48
47
  { error: e.message }
@@ -21,9 +21,6 @@ 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)
26
- { klass: [] }
27
24
  end
28
25
  end
29
26
 
@@ -35,9 +32,6 @@ module Labimotion
35
32
  get do
36
33
  list = klass_list(params[:generic_only])
37
34
  present list, with: Labimotion::ElementKlassEntity, root: 'klass'
38
- rescue StandardError => e
39
- Labimotion.log_exception(e, current_user)
40
- { klass: [] }
41
35
  end
42
36
  end
43
37
 
@@ -73,9 +67,6 @@ module Labimotion
73
67
  post do
74
68
  authenticate_admin!('elements')
75
69
  update_element_klass(current_user, params)
76
- rescue StandardError => e
77
- Labimotion.log_exception(e, current_user)
78
- raise e
79
70
  end
80
71
  end
81
72
 
@@ -88,9 +79,6 @@ module Labimotion
88
79
  get do
89
80
  list = list_klass_revisions(params)
90
81
  present list, with: Labimotion::KlassRevisionEntity, root: 'revisions'
91
- rescue StandardError => e
92
- Labimotion.log_exception(e, current_user)
93
- []
94
82
  end
95
83
  end
96
84
 
@@ -102,9 +90,6 @@ module Labimotion
102
90
  get do
103
91
  list = element_revisions(params)
104
92
  present list, with: Labimotion::ElementRevisionEntity, root: 'revisions'
105
- rescue StandardError => e
106
- Labimotion.log_exception(e, current_user)
107
- []
108
93
  end
109
94
  end
110
95
 
@@ -119,9 +104,6 @@ module Labimotion
119
104
  authenticate_admin!(params[:klass].gsub(/(Klass)/, 's').downcase)
120
105
  delete_klass_revision(params)
121
106
  status 201
122
- rescue StandardError => e
123
- Labimotion.log_exception(e, current_user)
124
- raise e
125
107
  end
126
108
  end
127
109
 
@@ -135,9 +117,6 @@ module Labimotion
135
117
  post do
136
118
  delete_revision(params)
137
119
  status 201
138
- rescue StandardError => e
139
- Labimotion.log_exception(e, current_user)
140
- raise e
141
120
  end
142
121
  end
143
122
 
@@ -150,9 +129,6 @@ module Labimotion
150
129
  klass = Labimotion::Segment.find(params[:id])
151
130
  list = klass.segments_revisions unless klass.nil?
152
131
  present list&.sort_by(&:created_at).reverse, with: Labimotion::SegmentRevisionEntity, root: 'revisions'
153
- rescue StandardError => e
154
- Labimotion.log_exception(e, current_user)
155
- []
156
132
  end
157
133
  end
158
134
 
@@ -176,9 +152,6 @@ module Labimotion
176
152
  post do
177
153
  upload_generics_files(current_user, params)
178
154
  true
179
- rescue StandardError => e
180
- Labimotion.log_exception(e, current_user)
181
- raise e
182
155
  end
183
156
  end
184
157
 
@@ -187,19 +160,13 @@ module Labimotion
187
160
  get do
188
161
  list = Labimotion::ElementKlass.all.sort_by { |e| e.place }
189
162
  present list, with: Labimotion::ElementKlassEntity, root: 'klass'
190
- rescue StandardError => e
191
- Labimotion.log_exception(e, current_user)
192
- []
193
163
  end
194
164
  end
195
165
 
196
166
  namespace :fetch_repo do
197
167
  desc 'fetch Generic Element Klass from Chemotion Repository'
198
168
  get do
199
- fetch_repo('ElementKlass', current_user)
200
- rescue StandardError => e
201
- Labimotion.log_exception(e, current_user)
202
- []
169
+ fetch_repo('ElementKlass')
203
170
  end
204
171
  end
205
172
 
@@ -209,9 +176,8 @@ module Labimotion
209
176
  requires :identifier, type: String, desc: 'Identifier'
210
177
  end
211
178
  post do
212
- msg = create_repo_klass(params, current_user, request.headers['Origin'])
213
- klass = Labimotion::ElementKlassEntity.represent(ElementKlass.all)
214
- { status: msg[:status], message: msg[:message], klass: klass }
179
+ create_repo_klass(params, current_user)
180
+ present ElementKlass.all, with: Labimotion::ElementKlassEntity, root: 'klass'
215
181
  rescue StandardError => e
216
182
  Labimotion.log_exception(e, current_user)
217
183
  { error: e.message }
@@ -231,9 +197,6 @@ module Labimotion
231
197
  end
232
198
  post do
233
199
  deactivate_klass(params)
234
- rescue StandardError => e
235
- Labimotion.log_exception(e, current_user)
236
- raise e
237
200
  end
238
201
  end
239
202
 
@@ -246,9 +209,6 @@ module Labimotion
246
209
  delete ':id' do
247
210
  delete_klass(params)
248
211
  status 201
249
- rescue StandardError => e
250
- Labimotion.log_exception(e, current_user)
251
- raise e
252
212
  end
253
213
  end
254
214
 
@@ -266,9 +226,6 @@ module Labimotion
266
226
  end
267
227
  post do
268
228
  update_template(params, current_user)
269
- rescue StandardError => e
270
- Labimotion.log_exception(e, current_user)
271
- raise e
272
229
  end
273
230
  end
274
231
 
@@ -299,9 +256,6 @@ module Labimotion
299
256
  end
300
257
  end
301
258
  { generic_elements: generic_elements }
302
- rescue StandardError => e
303
- Labimotion.log_exception(e, current_user)
304
- { generic_elements: [] }
305
259
  end
306
260
 
307
261
  desc 'Return serialized element by id'
@@ -318,7 +272,7 @@ module Labimotion
318
272
  if Labimotion::IS_RAILS5 == true
319
273
  {
320
274
  element: ElementPermissionProxy.new(current_user, element, user_ids).serialized,
321
- attachments: attach_thumbnail(element&.attachments)
275
+ attachments: Entities::AttachmentEntity.represent(element.attachments)
322
276
  }
323
277
  else
324
278
  {
@@ -326,11 +280,9 @@ module Labimotion
326
280
  element,
327
281
  detail_levels: ElementDetailLevelCalculator.new(user: current_user, element: element).detail_levels,
328
282
  ),
329
- attachments: attach_thumbnail(element&.attachments)
283
+ attachments: Entities::AttachmentEntity.represent(element.attachments),
330
284
  }
331
285
  end
332
- rescue StandardError => e
333
- Labimotion.log_exception(e, current_user)
334
286
  end
335
287
  end
336
288
 
@@ -350,7 +302,7 @@ module Labimotion
350
302
  if Labimotion::IS_RAILS5 == true
351
303
  {
352
304
  element: ElementPermissionProxy.new(current_user, element, user_ids).serialized,
353
- attachments: attach_thumbnail(element&.attachments)
305
+ attachments: Entities::AttachmentEntity.represent(element.attachments)
354
306
  }
355
307
  else
356
308
  present(
@@ -386,7 +338,7 @@ module Labimotion
386
338
  if Labimotion::IS_RAILS5 == true
387
339
  {
388
340
  element: ElementPermissionProxy.new(current_user, element, user_ids).serialized,
389
- attachments: attach_thumbnail(element&.attachments)
341
+ attachments: Entities::AttachmentEntity.represent(element.attachments)
390
342
  }
391
343
  else
392
344
  {
@@ -394,7 +346,7 @@ module Labimotion
394
346
  element,
395
347
  detail_levels: ElementDetailLevelCalculator.new(user: current_user, element: element).detail_levels,
396
348
  ),
397
- attachments: attach_thumbnail(element&.attachments),
349
+ attachments: Entities::AttachmentEntity.represent(element.attachments),
398
350
  }
399
351
  end
400
352
  rescue StandardError => e
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'open-uri'
4
- require 'labimotion/models/hub_log'
5
4
 
6
5
  # Belong to Chemotion module
7
6
  module Labimotion
@@ -20,25 +19,20 @@ module Labimotion
20
19
  list = "Labimotion::#{params[:klass]}".constantize.where(is_active: true).where.not(released_at: nil)
21
20
  list = list.where(is_generic: true) if params[:klass] == 'ElementKlass'
22
21
  entities = Labimotion::GenericPublicEntity.represent(list, displayed: params[:with_props])
23
- rescue StandardError => e
24
- Labimotion.log_exception(e, current_user)
25
- []
22
+ # entities.length > 1 ? de_encode_json(entities) : []
26
23
  end
27
24
  end
28
25
  namespace :fetch do
29
26
  desc "get active generic templates"
30
27
  params do
31
28
  requires :klass, type: String, desc: 'Klass', values: %w[ElementKlass SegmentKlass DatasetKlass]
32
- requires :origin, type: String, desc: 'origin'
29
+ # requires :fqdn, type: Integer, desc: 'FQDN'
33
30
  requires :identifier, type: String, desc: 'Identifier'
34
31
  end
35
- post do
32
+ get do
36
33
  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)
38
34
  "Labimotion::#{params[:klass]}Entity".constantize.represent(entity)
39
- rescue StandardError => e
40
- Labimotion.log_exception(e, current_user)
41
- raise e
35
+ # entities.length > 1 ? de_encode_json(entities) : []
42
36
  end
43
37
  end
44
38
 
@@ -51,9 +45,6 @@ module Labimotion
51
45
  list = Labimotion::ElementKlass.where(is_active: true) if params[:generic_only].present? && params[:generic_only] == true
52
46
  list = Labimotion::ElementKlass.where(is_active: true) unless params[:generic_only].present? && params[:generic_only] == true
53
47
  list.pluck(:name)
54
- rescue StandardError => e
55
- Labimotion.log_exception(e, current_user)
56
- []
57
48
  end
58
49
  end
59
50
 
@@ -118,7 +118,7 @@ module Labimotion
118
118
  namespace :fetch_repo do
119
119
  desc 'fetch Generic Segment Klass from Chemotion Repository'
120
120
  get do
121
- fetch_repo('SegmentKlass', current_user)
121
+ fetch_repo('SegmentKlass')
122
122
  rescue StandardError => e
123
123
  Labimotion.log_exception(e, current_user)
124
124
  { error: e.message }
@@ -131,9 +131,8 @@ module Labimotion
131
131
  requires :identifier, type: String, desc: 'Identifier'
132
132
  end
133
133
  post do
134
- msg = create_repo_klass(params, current_user, request.headers['Origin'])
135
- klass = Labimotion::SegmentKlassEntity.represent(SegmentKlass.all)
136
- { status: msg[:status], message: msg[:message], klass: klass }
134
+ create_repo_klass(params, current_user)
135
+ present SegmentKlass.all, with: Labimotion::SegmentKlassEntity, root: 'klass'
137
136
  rescue StandardError => e
138
137
  Labimotion.log_exception(e, current_user)
139
138
  ## { error: e.message }
@@ -5,7 +5,6 @@ require 'labimotion/entities/application_entity'
5
5
  # Entity module
6
6
  module Labimotion
7
7
  class GenericPublicEntity < Labimotion::ApplicationEntity
8
- expose! :uuid
9
8
  expose! :name
10
9
  expose! :desc
11
10
  expose! :icon_name
@@ -13,7 +12,6 @@ module Labimotion
13
12
  expose! :klass_name
14
13
  expose! :label
15
14
  expose! :identifier
16
- expose! :version
17
15
  expose! :released_at
18
16
  expose! :properties_release, if: :displayed
19
17
  expose :element_klass do |obj|
@@ -13,8 +13,8 @@ module Labimotion
13
13
  end
14
14
  end
15
15
 
16
- def create_repo_klass(params, current_user, origin)
17
- response = Labimotion::TemplateHub.fetch_identifier('DatasetKlass', params[:identifier], origin)
16
+ def create_repo_klass(params, current_user)
17
+ response = Labimotion::TemplateHub.fetch_identifier('DatasetKlass', params[:identifier])
18
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
19
  attributes['properties_release']['identifier'] = attributes['identifier']
20
20
  attributes['properties_template'] = attributes['properties_release']
@@ -23,22 +23,14 @@ module Labimotion
23
23
  attributes['updated_by'] = current_user.id
24
24
  attributes['sync_by'] = current_user.id
25
25
  attributes['sync_time'] = DateTime.now
26
- dataset_klass = Labimotion::DatasetKlass.find_by(ols_term_id: attributes['ols_term_id'])
27
- if dataset_klass.present?
28
- if dataset_klass['uuid'] == attributes['uuid'] && dataset_klass['version'] == attributes['version']
29
- { status: 'success', message: "This dataset: #{attributes['label']} has the latest version!" }
30
- else
31
- ds = Labimotion::DatasetKlass.find_by(ols_term_id: attributes['ols_term_id'])
32
- ds.update!(attributes)
33
- ds.create_klasses_revision(current_user)
34
- { status: 'success', message: "This dataset: [#{attributes['label']}] has been upgraded to the version: #{attributes['version']}!" }
35
- end
26
+ if Labimotion::DatasetKlass.find_by(ols_term_id: attributes['ols_term_id']).present?
27
+ ds = Labimotion::DatasetKlass.find_by(ols_term_id: attributes['ols_term_id'])
28
+ ds.update!(attributes)
36
29
  else
37
30
  attributes['created_by'] = current_user.id
38
31
  ds = Labimotion::DatasetKlass.create!(attributes)
39
- ds.create_klasses_revision(current_user)
40
- { status: 'success', message: "The dataset: #{attributes['label']} has been created using version: #{attributes['version']}!" }
41
32
  end
33
+ ds.create_klasses_revision(current_user)
42
34
  rescue StandardError => e
43
35
  Labimotion.log_exception(e, current_user)
44
36
  # { error: e.message }
@@ -159,7 +159,7 @@ module Labimotion
159
159
  att_ary = create_attachments(
160
160
  params[:attfiles],
161
161
  params[:delfiles],
162
- "Labimotion::#{params[:att_type]}",
162
+ params[:att_type],
163
163
  params[:att_id],
164
164
  params[:attfilesIdentifier],
165
165
  current_user.id
@@ -174,7 +174,8 @@ module Labimotion
174
174
  true
175
175
  rescue StandardError => e
176
176
  Labimotion.log_exception(e, current_user)
177
- false
177
+ ## false
178
+ raise e
178
179
  end
179
180
 
180
181
  def element_revisions(params)
@@ -289,9 +290,9 @@ module Labimotion
289
290
  raise e
290
291
  end
291
292
 
292
- def create_repo_klass(params, current_user, origin)
293
- response = Labimotion::TemplateHub.fetch_identifier('ElementKlass', params[:identifier], origin)
294
- attributes = response.slice('name', 'label', 'desc', 'icon_name', 'uuid', 'klass_prefix', 'is_generic', 'identifier', 'properties_release', 'version')
293
+ def create_repo_klass(params, current_user)
294
+ response = Labimotion::TemplateHub.fetch_identifier('ElementKlass', params[:identifier])
295
+ attributes = response.slice('name', 'label', 'desc', 'icon_name', 'klass_prefix', 'is_generic', 'identifier', 'properties_release', 'version')
295
296
  attributes['properties_release']['identifier'] = attributes['identifier']
296
297
  attributes['properties_template'] = attributes['properties_release']
297
298
  attributes['place'] = ((Labimotion::DatasetKlass.all.length * 10) || 0) + 10
@@ -302,38 +303,17 @@ module Labimotion
302
303
 
303
304
  element_klass = Labimotion::ElementKlass.find_by(identifier: attributes['identifier'])
304
305
  if element_klass.present?
305
- if element_klass['uuid'] == attributes['uuid'] && element_klass['version'] == attributes['version']
306
- { status: 'success', message: "This element: #{attributes['name']} has the latest version!" }
307
- else
308
- element_klass.update!(attributes)
309
- element_klass.create_klasses_revision(current_user)
310
- { status: 'success', message: "This element: [#{attributes['name']}] has been upgraded to the version: #{attributes['version']}!" }
311
- end
306
+ element_klass.update!(attributes)
312
307
  else
313
- exist_klass = Labimotion::ElementKlass.find_by(name: attributes['name'])
314
- if exist_klass.present?
315
- { status: 'error', message: "The name [#{attributes['name']}] is already in use." }
316
- else
317
- attributes['created_by'] = current_user.id
318
- element_klass = Labimotion::ElementKlass.create!(attributes)
319
- element_klass.create_klasses_revision(current_user)
320
- { status: 'success', message: "The element: #{attributes['name']} has been created using version: #{attributes['version']}!" }
321
- end
308
+ attributes['created_by'] = current_user.id
309
+ element_klass = Labimotion::ElementKlass.create!(attributes)
322
310
  end
311
+ element_klass.create_klasses_revision(current_user)
323
312
  rescue StandardError => e
324
313
  Labimotion.log_exception(e, current_user)
325
314
  # { error: e.message }
326
315
  raise e
327
316
  end
328
317
 
329
- def attach_thumbnail(_attachments)
330
- attachments = _attachments&.map do |attachment|
331
- _att = Entities::AttachmentEntity.represent(attachment, serializable: true)
332
- _att[:thumbnail] = attachment.thumb ? Base64.encode64(attachment.read_thumbnail) : nil
333
- _att
334
- end
335
- attachments
336
- end
337
-
338
318
  end
339
319
  end
@@ -193,7 +193,7 @@ module Labimotion
193
193
  (files || []).each_with_index do |file, index|
194
194
  next unless (tempfile = file[:tempfile])
195
195
 
196
- att = Attachment.new(
196
+ a = Attachment.new(
197
197
  bucket: file[:container_id],
198
198
  filename: file[:filename],
199
199
  con_state: Labimotion::ConState::NONE,
@@ -205,7 +205,7 @@ module Labimotion
205
205
  attachable_type: type,
206
206
  attachable_id: id,
207
207
  )
208
- begin
208
+ ActiveRecord::Base.transaction do
209
209
  att.save!
210
210
  attach_ary.push(att.id)
211
211
  ensure
@@ -214,11 +214,12 @@ module Labimotion
214
214
  end
215
215
  end
216
216
  unless (del_files || []).empty?
217
- Attachment.where('id IN (?) AND attachable_type = (?)', del_files.map!(&:to_i), type).update_all(attachable_id: nil)
217
+ Attachment.where('id IN (?) AND attachable_type = (?)', del_files.map!(&:to_i),
218
+ type).update_all(attachable_id: nil)
218
219
  end
219
220
  attach_ary
220
221
  rescue StandardError => e
221
- Labimotion.log_exception(e)
222
+ Labimotion.log_exception(e, current_user)
222
223
  raise e
223
224
  end
224
225
 
@@ -230,16 +231,15 @@ module Labimotion
230
231
  Chemotion::Generic::Fetch::Template.list(API::TARGET, name)
231
232
  end
232
233
 
233
- def fetch_repo(name, current_user)
234
- # current_klasses = "Labimotion::#{name}".constantize.where.not(identifier: nil)&.pluck(:identifier) || []
234
+ def fetch_repo(name)
235
+ current_klasses = "Labimotion::#{name}".constantize.where.not(identifier: nil)&.pluck(:identifier) || []
235
236
  response = Labimotion::TemplateHub.list(name)
236
- # if response && response['list'].present? && response['list'].length.positive?
237
- # filter_list = response['list']&.reject do |ds|
238
- # current_klasses.include?(ds['identifier'])
239
- # end || []
240
- # end
241
- # filter_list || []
242
- (response && response['list']) || []
237
+ if response && response['list'].present? && response['list'].length.positive?
238
+ filter_list = response['list']&.reject do |ds|
239
+ current_klasses.include?(ds['identifier'])
240
+ end || []
241
+ end
242
+ filter_list || []
243
243
  rescue StandardError => e
244
244
  Labimotion.log_exception(e, current_user)
245
245
  { error: 'Cannot connect to Chemotion Repository' }
@@ -63,8 +63,8 @@ module Labimotion
63
63
  raise e
64
64
  end
65
65
 
66
- def create_repo_klass(params, current_user, origin)
67
- response = Labimotion::TemplateHub.fetch_identifier('SegmentKlass', params[:identifier], origin)
66
+ def create_repo_klass(params, current_user)
67
+ response = Labimotion::TemplateHub.fetch_identifier('SegmentKlass', params[:identifier])
68
68
  attributes = response.slice('label', 'desc', 'uuid', 'identifier', 'released_at', 'properties_release', 'version')
69
69
  attributes['properties_release']['identifier'] = attributes['identifier']
70
70
  attributes['properties_template'] = attributes['properties_release']
@@ -75,8 +75,8 @@ module Labimotion
75
75
  attributes['sync_time'] = DateTime.now
76
76
 
77
77
  element_klass = Labimotion::ElementKlass.find_by(identifier: response['element_klass']['identifier'])
78
- element_klass = Labimotion::ElementKlass.find_by(name: response['element_klass']['name'], is_generic: false) if element_klass.nil?
79
- return { status: 'error', message: "The element [#{response['element_klass']['name']}] does not exist in this instance" } if element_klass.nil?
78
+ element_klass = Labimotion::ElementKlass.find_by(name: response['element_klass']['name']) if element_klass.nil?
79
+ return { error: 'ElementKlass not found' } if element_klass.nil?
80
80
 
81
81
  # el_attributes = response['element_klass'].slice('name', 'label', 'desc', 'uuid', 'identifier', 'icon_name', 'klass_prefix', 'is_generic', 'released_at')
82
82
  # el_attributes['properties_template'] = response['element_klass']['properties_release']
@@ -85,24 +85,12 @@ module Labimotion
85
85
  attributes['element_klass_id'] = element_klass.id
86
86
  segment_klass = Labimotion::SegmentKlass.find_by(identifier: attributes['identifier'])
87
87
  if segment_klass.present?
88
- if segment_klass['uuid'] == attributes['uuid'] && segment_klass['version'] == attributes['version']
89
- { status: 'success', message: "This segment: #{attributes['label']} has the latest version!" }
90
- else
91
- segment_klass.update!(attributes)
92
- segment_klass.create_klasses_revision(current_user)
93
- { status: 'success', message: "This segment: [#{attributes['label']}] has been upgraded to the version: #{attributes['version']}!" }
94
- end
88
+ segment_klass.update!(attributes)
95
89
  else
96
- exist_klass = Labimotion::SegmentKlass.find_by(label: attributes['label'], element_klass_id: element_klass.id)
97
- if exist_klass.present?
98
- { status: 'error', message: "The segment [#{attributes['label']}] is already in use." }
99
- else
100
- attributes['created_by'] = current_user.id
101
- segment_klass = Labimotion::SegmentKlass.create!(attributes)
102
- segment_klass.create_klasses_revision(current_user)
103
- { status: 'success', message: "The segment: #{attributes['label']} has been created using version: #{attributes['version']}!" }
104
- end
90
+ attributes['created_by'] = current_user.id
91
+ segment_klass = Labimotion::SegmentKlass.create!(attributes)
105
92
  end
93
+ segment_klass.create_klasses_revision(current_user)
106
94
  rescue StandardError => e
107
95
  Labimotion.log_exception(e, current_user)
108
96
  raise e
@@ -144,7 +144,8 @@ module Labimotion
144
144
  end
145
145
 
146
146
  def self.process(data)
147
- return data[:a].con_state if data[:a]&.attachable_type != 'Container'
147
+ return if data[:a]&.attachable_type != 'Container'
148
+
148
149
  response = nil
149
150
  begin
150
151
  ofile = Rails.root.join(data[:f], data[:a].filename)
@@ -165,14 +166,12 @@ module Labimotion
165
166
  end
166
167
  if response.ok?
167
168
  Labimotion::Converter.handle_response(data[:a], response)
168
- Labimotion::ConState::PROCESSED
169
169
  else
170
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
172
171
  end
172
+ response
173
173
  rescue StandardError => e
174
- Labimotion::Converter.logger.error ["process fail: #{id}", e.message, *e.backtrace].join($INPUT_RECORD_SEPARATOR)
175
- Labimotion::ConState::ERROR
174
+ raise e
176
175
  ensure
177
176
  FileUtils.rm_f(ofile)
178
177
  end
@@ -181,14 +180,14 @@ module Labimotion
181
180
  def self.jcamp_converter(id)
182
181
  resp = nil
183
182
  begin
184
-
185
183
  data = Labimotion::Converter.vor_conv(id)
186
184
  return if data.nil?
187
185
 
188
- Labimotion::Converter.process(data)
186
+ resp = Labimotion::Converter.process(data)
187
+ resp&.success? ? Labimotion::ConState::PROCESSED : Labimotion::ConState::ERROR
189
188
  rescue StandardError => e
190
- Labimotion::Converter.logger.error ["jcamp_converter fail: #{id}", e.message, *e.backtrace].join($INPUT_RECORD_SEPARATOR)
191
189
  Labimotion::ConState::ERROR
190
+ Labimotion::Converter.logger.error ["jcamp_converter fail: #{id}", e.message, *e.backtrace].join($INPUT_RECORD_SEPARATOR)
192
191
  end
193
192
  end
194
193
 
@@ -234,8 +233,6 @@ module Labimotion
234
233
  new_prop = dataset.properties
235
234
  dsr.each do |ds|
236
235
  layer = layers[ds[:layer]]
237
- next if layer.nil? || layer['fields'].nil?
238
-
239
236
  fields = layer['fields'].select{ |f| f['field'] == ds[:field] }
240
237
  fi = fields&.first
241
238
  idx = layer['fields'].find_index(fi)
@@ -101,7 +101,7 @@ module Labimotion
101
101
  cds = Container.find(id)
102
102
  cds.attachments.where(aasm_state: 'csv').each do |att|
103
103
  name = File.basename(att.filename, '.csv')
104
- sheet = @xfile.workbook.add_worksheet(name: name.slice(0, 25))
104
+ sheet = @xfile.workbook.add_worksheet(name: name)
105
105
 
106
106
  if Labimotion::IS_RAILS5 == true
107
107
  File.open(att.store.path) do |fi|
@@ -43,15 +43,11 @@ module Labimotion
43
43
  error!('Cannot connect to Chemotion Repository', 401)
44
44
  end
45
45
 
46
- def self.fetch_identifier(klass, identifier, origin)
47
- body = { klass: klass, identifier: identifier, origin: origin }
48
- response = HTTParty.post(
49
- uri('fetch'),
50
- body: body,
51
- timeout: 10
52
- )
46
+ def self.fetch_identifier(klass, identifier)
47
+ # body = { klass: klass, identifier: identifier }
48
+ response = HTTParty.get("#{uri('fetch')}?klass=#{klass}&identifier=#{identifier}", timeout: 10)
53
49
  # response.parsed_response if response.code == 200
54
- JSON.parse(response.body) if response.code == 201
50
+ JSON.parse(response.body) if response.code == 200
55
51
  rescue StandardError => e
56
52
  Labimotion.log_exception(e)
57
53
  error!('Cannot connect to Chemotion Repository', 401)
@@ -36,7 +36,6 @@ 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)
40
39
  end
41
40
  end
42
41
  end
@@ -23,7 +23,7 @@ module Labimotion
23
23
  uuid = SecureRandom.uuid
24
24
  props = args[:properties]
25
25
  props['pkg'] = Labimotion::Utils.pkg(props['pkg'])
26
- props['identifier'] = klass.identifier if klass.identifier.present?
26
+ props['identifier'] = klass.identifier
27
27
  props['uuid'] = uuid
28
28
  props['klass'] = 'Dataset'
29
29
 
@@ -41,13 +41,14 @@ module Labimotion
41
41
 
42
42
  def save_segments(**args) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
43
43
  return if args[:segments].nil?
44
+
44
45
  segments = []
45
- args[:segments]&.each do |seg|
46
+ args[:segments].each do |seg|
46
47
  klass = Labimotion::SegmentKlass.find_by(id: seg['segment_klass_id'])
47
48
  uuid = SecureRandom.uuid
48
49
  props = seg['properties']
49
50
  props['pkg'] = Labimotion::Utils.pkg(props['pkg'])
50
- props['identifier'] = klass.identifier if klass.identifier.present?
51
+ props['identifier'] = identifier
51
52
  props['uuid'] = uuid
52
53
  props['klass'] = 'Segment'
53
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'])
@@ -58,7 +59,7 @@ module Labimotion
58
59
  next if segment.present?
59
60
 
60
61
  props['klass_uuid'] = klass.uuid
61
- segment = Labimotion::Segment.create!(properties_release: klass.properties_release, segment_klass_id: seg['segment_klass_id'], element_type: self.class.name, element_id: self.id, properties: props, created_by: args[:current_user_id], uuid: uuid, klass_uuid: klass.uuid)
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)
62
63
  segments.push(segment)
63
64
  end
64
65
  segments
@@ -23,14 +23,5 @@ module Labimotion
23
23
  end
24
24
  properties
25
25
  end
26
-
27
- def migrate_workflow
28
- return if properties_template.nil? || properties_release.nil?
29
-
30
- return if properties_template['flow'].nil? && properties_release['flow'].nil?
31
-
32
- update_column(:properties_template, split_workflow(properties_template)) if properties_template['flow']
33
- update_column(:properties_release, split_workflow(properties_release)) if properties_release['flow']
34
- end
35
26
  end
36
27
  end
@@ -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)
@@ -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,26 +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
-
36
- element, attachments = Labimotion::Export.fetch_properties(element, attachments, &fetch_one)
37
- fetch_containers.call(element)
38
- segment, @attachments = Labimotion::Export.fetch_segments(element, attachments, &fetch_one)
39
- segments += segment if segment.present?
40
- end
41
-
42
- [segments, attachments]
43
-
44
- end
45
25
 
46
26
  def self.fetch_segments(element, attachments, &fetch_one)
47
27
  element_type = element.class.name
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Labimotion
4
- IS_RAILS5 = true
5
- VERSION = '0.3.1' if Labimotion::IS_RAILS5 == true
6
- VERSION = '1.0.7' if Labimotion::IS_RAILS5 == false
4
+ # VERSION = '0.1.4'
5
+ VERSION = '1.0.0'
6
+ IS_RAILS5 = false
7
7
  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.3.1
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-09-10 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
@@ -84,7 +84,6 @@ 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
@@ -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