labimotion 0.1.6 → 0.1.7

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: 2d2c94d9d6147cab5fd823c611f65c6b41f5140bd018424aae86ca1bd697e1b0
4
- data.tar.gz: e5ac11f1be750a698f7285776fc62a1850876b4fa5b53814460f9325d90a832a
3
+ metadata.gz: 1f0a3e834c8cd1519a060d72139c14407d8959f317ab33ac43f6a01988fd25d9
4
+ data.tar.gz: 565294e07a80e97bbd0c1d09bf9c35d3c464ac9eac3c6b11ad74e55e7fe56b45
5
5
  SHA512:
6
- metadata.gz: 1430bdaa9a7721c6d5c09b35abde14ee6d2946a7f394fb65a12b9456b026c6734e027c1c36c24195cd36ec4e5701c7f4bba778f4d2fa31f4e6984e491f05eecb
7
- data.tar.gz: 5518460a7151dce59e3c20e6e8ca0422a3d443b8aff7c95fecf63d915aa0a6c2e1555b221548bc58ef7194798c48cb4252c3f89454798d27366d9c4a844b1348
6
+ metadata.gz: cca7ebdf9dd1340b64ee59f38cc21266520d75f02e7b72b297b480b9da39172826e345e6dd4d8b09d216851e79a3e18b2c6f0faad3222badc6ac1259219d8010
7
+ data.tar.gz: 152ecf2e8009b39e1c0313536da76cde1134a5ac804e387e1be5898e24bea6510aa2d751cf8e394fa9434b659f460bc221506db21e1175f40055446e4ca828bd
@@ -40,7 +40,7 @@ module Labimotion
40
40
  post do
41
41
  create_repo_klass(params, current_user)
42
42
  present DatasetKlass.all, with: Labimotion::DatasetKlassEntity, root: 'klass'
43
- rescue => e
43
+ rescue StandardError => e
44
44
  Labimotion.log_exception(e, current_user)
45
45
  { error: e.message }
46
46
  end
@@ -291,7 +291,7 @@ module Labimotion
291
291
  detail_levels: ElementDetailLevelCalculator.new(user: current_user, element: element).detail_levels,
292
292
  )
293
293
  end
294
- rescue => e
294
+ rescue StandardError => e
295
295
  Labimotion.log_exception(e, current_user)
296
296
  raise e
297
297
  end
@@ -328,7 +328,7 @@ module Labimotion
328
328
  attachments: Entities::AttachmentEntity.represent(element.attachments),
329
329
  }
330
330
  end
331
- rescue => e
331
+ rescue StandardError => e
332
332
  Labimotion.log_exception(e, current_user)
333
333
  raise e
334
334
  end
@@ -61,7 +61,7 @@ module Labimotion
61
61
  end
62
62
  post do
63
63
  update_segment_klass(current_user, params)
64
- rescue => e
64
+ rescue StandardError => e
65
65
  Labimotion.log_exception(e, current_user)
66
66
  { error: e.message }
67
67
  end
@@ -99,7 +99,7 @@ module Labimotion
99
99
  ))
100
100
 
101
101
  present segment_klass, with: Labimotion::SegmentKlassEntity, root: 'klass'
102
- rescue => e
102
+ rescue StandardError => e
103
103
  Labimotion.log_exception(e, current_user)
104
104
  { error: e.message }
105
105
  end
@@ -109,7 +109,7 @@ module Labimotion
109
109
  desc 'fetch segment templates from repository'
110
110
  get do
111
111
  fetch_repo_generic_template_list('Segment')
112
- rescue => e
112
+ rescue StandardError => e
113
113
  Labimotion.log_exception(e, current_user)
114
114
  { error: e.message }
115
115
  end
@@ -119,7 +119,7 @@ module Labimotion
119
119
  desc 'fetch Generic Segment Klass from Chemotion Repository'
120
120
  get do
121
121
  fetch_repo('SegmentKlass')
122
- rescue => e
122
+ rescue StandardError => e
123
123
  Labimotion.log_exception(e, current_user)
124
124
  { error: e.message }
125
125
  end
@@ -133,7 +133,7 @@ module Labimotion
133
133
  post do
134
134
  create_repo_klass(params, current_user)
135
135
  present SegmentKlass.all, with: Labimotion::SegmentKlassEntity, root: 'klass'
136
- rescue => e
136
+ rescue StandardError => e
137
137
  Labimotion.log_exception(e, current_user)
138
138
  ## { error: e.message }
139
139
  raise e
@@ -29,7 +29,7 @@ module Labimotion
29
29
  attributes['created_by'] = current_user.id
30
30
  Labimotion::DatasetKlass.create!(attributes)
31
31
  end
32
- rescue => e
32
+ rescue StandardError => e
33
33
  Labimotion.log_exception(e, current_user)
34
34
  # { error: e.message }
35
35
  raise e
@@ -38,7 +38,7 @@ module Labimotion
38
38
  klasses = Labimotion::ElementKlass.where(is_active: true)&.pluck(:name) || []
39
39
  File.write(klass_names_file, klasses)
40
40
  klasses
41
- rescue => e
41
+ rescue StandardError => e
42
42
  Labimotion.log_exception(e, current_user)
43
43
  raise e
44
44
  end
@@ -58,7 +58,7 @@ module Labimotion
58
58
  klass.place = place
59
59
  klass.save!
60
60
  klass
61
- rescue => e
61
+ rescue StandardError => e
62
62
  Labimotion.log_exception(e, current_user)
63
63
  raise e
64
64
  end
@@ -97,7 +97,7 @@ module Labimotion
97
97
  element.save!
98
98
  element.save_segments(segments: params[:segments], current_user_id: current_user.id)
99
99
  element
100
- rescue => e
100
+ rescue StandardError => e
101
101
  Labimotion.log_exception(e, current_user)
102
102
  raise e
103
103
  end
@@ -128,7 +128,7 @@ module Labimotion
128
128
  end
129
129
  element.save_segments(segments: params[:segments], current_user_id: current_user.id)
130
130
  element
131
- rescue => e
131
+ rescue StandardError => e
132
132
  Labimotion.log_exception(e, current_user)
133
133
  raise e
134
134
  end
@@ -172,7 +172,7 @@ module Labimotion
172
172
  TransferFileFromTmpJob.set(queue: "transfer_file_from_tmp_#{current_user.id}").perform_now(attach_ary) unless attach_ary.empty?
173
173
  end
174
174
  true
175
- rescue => e
175
+ rescue StandardError => e
176
176
  Labimotion.log_exception(e, current_user)
177
177
  ## false
178
178
  raise e
@@ -182,7 +182,7 @@ module Labimotion
182
182
  klass = Labimotion::Element.find(params[:id])
183
183
  list = klass.elements_revisions unless klass.nil?
184
184
  list&.sort_by(&:created_at)&.reverse
185
- rescue => e
185
+ rescue StandardError => e
186
186
  Labimotion.log_exception(e, current_user)
187
187
  raise e
188
188
  end
@@ -222,7 +222,7 @@ module Labimotion
222
222
  scope = scope.updated_time_from(Time.at(from)) if from && !by_created_at
223
223
  scope = scope.updated_time_to(Time.at(to) + 1.day) if to && !by_created_at
224
224
  scope
225
- rescue => e
225
+ rescue StandardError => e
226
226
  Labimotion.log_exception(e, current_user)
227
227
  raise e
228
228
  end
@@ -260,7 +260,7 @@ module Labimotion
260
260
  scope = scope.updated_time_from(Time.at(from)) if from && !by_created_at
261
261
  scope = scope.updated_time_to(Time.at(to) + 1.day) if to && !by_created_at
262
262
  scope
263
- rescue => e
263
+ rescue StandardError => e
264
264
  Labimotion.log_exception(e, current_user)
265
265
  raise e
266
266
  end
@@ -15,7 +15,7 @@ module Labimotion
15
15
  klz = "Labimotion::#{name}".constantize.find_by(id: id)
16
16
  error!("#{name.gsub(/(Klass)/, '')} is invalid. Please re-select.", 500) if klz.nil?
17
17
  klz
18
- rescue => e
18
+ rescue StandardError => e
19
19
  Labimotion.log_exception(e, current_user)
20
20
  raise e
21
21
  end
@@ -25,7 +25,7 @@ module Labimotion
25
25
  klz&.update!(is_active: params[:is_active])
26
26
  generate_klass_file unless klz.class.name != 'ElementKlass'
27
27
  klz
28
- rescue => e
28
+ rescue StandardError => e
29
29
  Labimotion.log_exception(e, current_user)
30
30
  raise e
31
31
  end
@@ -36,7 +36,7 @@ module Labimotion
36
36
  klz&.destroy!
37
37
  generate_klass_file unless klz.class.name != 'ElementKlass'
38
38
  status 201
39
- rescue => e
39
+ rescue StandardError => e
40
40
  Labimotion.log_exception(e, current_user)
41
41
  raise e
42
42
  end
@@ -59,7 +59,7 @@ module Labimotion
59
59
  klz.reload
60
60
  klz.create_klasses_revision(current_user.id) if params[:is_release] == true
61
61
  klz
62
- rescue => e
62
+ rescue StandardError => e
63
63
  Labimotion.log_exception(e, current_user)
64
64
  raise e
65
65
  end
@@ -70,7 +70,7 @@ module Labimotion
70
70
  error!('Revision is invalid.', 404) if revision.nil?
71
71
  error!('Can not delete the active revision.', 405) if revision.uuid == klass.uuid
72
72
  revision&.destroy!
73
- rescue => e
73
+ rescue StandardError => e
74
74
  Labimotion.log_exception(e, current_user)
75
75
  raise e
76
76
  end
@@ -81,7 +81,7 @@ module Labimotion
81
81
  error!('Revision is invalid.', 404) if revision.nil?
82
82
  error!('Can not delete the active revision.', 405) if revision.uuid == element.uuid
83
83
  revision&.destroy!
84
- rescue => e
84
+ rescue StandardError => e
85
85
  Labimotion.log_exception(e, current_user)
86
86
  raise e
87
87
  end
@@ -90,7 +90,7 @@ module Labimotion
90
90
  klass = "Labimotion::#{params[:klass]}".constantize.find_by(id: params[:id])
91
91
  list = klass.send("#{params[:klass].underscore}es_revisions") unless klass.nil?
92
92
  list.sort_by(&:released_at).reverse
93
- rescue => e
93
+ rescue StandardError => e
94
94
  Labimotion.log_exception(e, current_user)
95
95
  raise e
96
96
  end
@@ -105,7 +105,7 @@ module Labimotion
105
105
  klass_names_file = File.join(klass_dir, 'klasses.json')
106
106
  klasses = Labimotion::ElementKlass.where(is_active: true)&.pluck(:name) || []
107
107
  File.write(klass_names_file, klasses)
108
- rescue => e
108
+ rescue StandardError => e
109
109
  Labimotion.log_exception(e, current_user)
110
110
  raise e
111
111
  end
@@ -122,7 +122,7 @@ module Labimotion
122
122
  end
123
123
  end
124
124
  uploads
125
- rescue => e
125
+ rescue StandardError => e
126
126
  Labimotion.log_exception(e, current_user)
127
127
  raise e
128
128
  end
@@ -135,7 +135,7 @@ module Labimotion
135
135
  properties['layers'][pa[:layer]]['fields'][idx]['value']['files'][fidx]['aid'] = att.id
136
136
  properties['layers'][pa[:layer]]['fields'][idx]['value']['files'][fidx]['uid'] = att.identifier
137
137
  element.update_columns(properties: properties)
138
- rescue => e
138
+ rescue StandardError => e
139
139
  Labimotion.log_exception(e, current_user)
140
140
  raise e
141
141
  end
@@ -187,7 +187,7 @@ module Labimotion
187
187
  element.save!
188
188
  end
189
189
  attach_ary
190
- rescue => e
190
+ rescue StandardError => e
191
191
  Labimotion.log_exception(e, current_user)
192
192
  error!('Error while uploading files.', 500)
193
193
  raise e
@@ -222,7 +222,7 @@ module Labimotion
222
222
  type).update_all(attachable_id: nil)
223
223
  end
224
224
  attach_ary
225
- rescue => e
225
+ rescue StandardError => e
226
226
  Labimotion.log_exception(e, current_user)
227
227
  raise e
228
228
  end
@@ -244,7 +244,7 @@ module Labimotion
244
244
  end || []
245
245
  end
246
246
  filter_list || []
247
- rescue => e
247
+ rescue StandardError => e
248
248
  Labimotion.log_exception(e, current_user)
249
249
  raise e
250
250
  end
@@ -30,7 +30,7 @@ module Labimotion
30
30
  subsample.save!
31
31
  subsample.reload
32
32
  subsample
33
- rescue => e
33
+ rescue StandardError => e
34
34
  Labimotion.log_exception(e, current_user)
35
35
  nil
36
36
  end
@@ -68,7 +68,7 @@ module Labimotion
68
68
  end
69
69
  end
70
70
  sds
71
- rescue => e
71
+ rescue StandardError => e
72
72
  Labimotion.log_exception(e, current_user)
73
73
  []
74
74
  end
@@ -119,7 +119,7 @@ module Labimotion
119
119
  Labimotion::ElementsSample.where(element_id: element.id).where.not(sample_id: sds)&.destroy_all
120
120
  Labimotion::ElementsElement.where(parent_id: element.id).where.not(element_id: els&.flatten)&.destroy_all
121
121
  properties
122
- rescue => e
122
+ rescue StandardError => e
123
123
  Labimotion.log_exception(e, current_user)
124
124
  end
125
125
  end
@@ -39,7 +39,7 @@ module Labimotion
39
39
  klass.reload
40
40
  klass.create_klasses_revision(current_user.id)
41
41
  klass
42
- rescue => e
42
+ rescue StandardError => e
43
43
  Labimotion.log_exception(e, current_user)
44
44
  raise e
45
45
  end
@@ -57,14 +57,13 @@ module Labimotion
57
57
  attributes[:place] = place
58
58
  segment&.update!(attributes)
59
59
  segment
60
- rescue => e
60
+ rescue StandardError => e
61
61
  Labimotion.log_exception(e, current_user)
62
62
  raise e
63
63
  end
64
64
 
65
65
  def create_repo_klass(params, current_user)
66
66
  response = Labimotion::TemplateHub.fetch_identifier('SegmentKlass', params[:identifier])
67
- byebug
68
67
  attributes = response.slice('label', 'desc', 'uuid', 'identifier', 'released_at') # .except(:id, :is_active, :place, :created_by, :created_at, :updated_at)
69
68
  attributes['properties_template'] = response['properties_release']
70
69
  attributes['place'] = ((Labimotion::SegmentKlass.all.length * 10) || 0) + 10
@@ -89,7 +88,7 @@ byebug
89
88
  attributes['created_by'] = current_user.id
90
89
  Labimotion::SegmentKlass.create!(attributes)
91
90
  end
92
- rescue => e
91
+ rescue StandardError => e
93
92
  Labimotion.log_exception(e, current_user)
94
93
  raise e
95
94
  end
@@ -120,6 +120,7 @@ module Labimotion
120
120
  att.save!
121
121
  end
122
122
  if att.valid? && Labimotion::IS_RAILS5 == true
123
+ att.save!
123
124
  primary_store = Rails.configuration.storage.primary_store
124
125
  att.update!(storage: primary_store)
125
126
  end
@@ -21,7 +21,7 @@ module Labimotion
21
21
  properties: properties,
22
22
  properties_release: properties_release
23
23
  }
24
- attributes["#{self.class.name.downcase.split('::').last}_id"] = id
24
+ attributes["#{Labimotion::Utils.element_name_dc(self.class.name)}_id"] = id
25
25
  attributes['name'] = name if self.class.name == 'Labimotion::Element'
26
26
  "#{self.class.name}sRevision".constantize.create(attributes)
27
27
  end
@@ -47,7 +47,7 @@ module Labimotion
47
47
  props = seg['properties']
48
48
  props['eln'] = Chemotion::Application.config.version
49
49
  props['labimotion'] = Labimotion::VERSION
50
- segment = Labimotion::Segment.find_by(element_type: self.class.name.split('::').last, element_id: self.id, segment_klass_id: seg['segment_klass_id'])
50
+ 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
51
  if segment.present? && (segment.klass_uuid != props['klass_uuid'] || segment.properties != props)
52
52
  props['uuid'] = uuid
53
53
  props['eln'] = Chemotion::Application.config.version
@@ -64,8 +64,7 @@ module Labimotion
64
64
  props['eln'] = Chemotion::Application.config.version
65
65
  props['labimotion'] = Labimotion::VERSION
66
66
  props['klass'] = 'Segment'
67
-
68
- segment = Labimotion::Segment.create!(properties_release: klass.properties_release, segment_klass_id: seg['segment_klass_id'], element_type: self.class.name.split('::').last, element_id: self.id, properties: props, created_by: args[:current_user_id], uuid: uuid, klass_uuid: klass.uuid)
67
+ 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)
69
68
  segments.push(segment)
70
69
  end
71
70
  segments
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Labimotion
4
+ class Utils
5
+ def self.klass_by_collection(name)
6
+ names = name.split('::')
7
+ if names.size == 1
8
+ name[11..]
9
+ else
10
+ "#{names[0]}::#{names.last[11..]}"
11
+ end
12
+ rescue StandardError => e
13
+ Labimotion.log_exception(e, current_user)
14
+ name
15
+ end
16
+
17
+ def self.elname_by_collection(name)
18
+ names = name.split('::')
19
+ if names.size == 1
20
+ name[11..].underscore
21
+ else
22
+ names.last[11..].underscore
23
+ end
24
+ rescue StandardError => e
25
+ Labimotion.log_exception(e)
26
+ name.constantize
27
+ end
28
+
29
+ def self.col_by_element(name)
30
+ names = name.split('::')
31
+ if names.size == 1
32
+ "collections_#{name.underscore.pluralize}"
33
+ else
34
+ "collections_#{names.last.underscore.pluralize}"
35
+ end
36
+ rescue StandardError => e
37
+ Labimotion.log_exception(e)
38
+ name..underscore.pluralize
39
+ end
40
+
41
+ def self.element_name(name)
42
+ names = name.split('::')
43
+ if names.size == 1
44
+ name
45
+ else
46
+ names.last
47
+ end
48
+ rescue StandardError => e
49
+ Labimotion.log_exception(e)
50
+ name
51
+ end
52
+
53
+ def self.element_name_dc(name)
54
+ Labimotion::Utils.element_name(name)&.downcase
55
+ end
56
+ end
57
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Labimotion
4
- VERSION = '0.1.6'
4
+ VERSION = '0.1.7'
5
5
  IS_RAILS5 = true
6
6
  end
data/lib/labimotion.rb CHANGED
@@ -12,6 +12,7 @@ module Labimotion
12
12
  Labimotion.logger.error(exception.backtrace.join("\n"))
13
13
  end
14
14
 
15
+ autoload :Utils, 'labimotion/utils/utils'
15
16
 
16
17
  ######## APIs
17
18
  autoload :GenericElementAPI, 'labimotion/apis/generic_element_api'
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.6
4
+ version: 0.1.7
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-13 00:00:00.000000000 Z
12
+ date: 2023-08-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -92,6 +92,7 @@ files:
92
92
  - lib/labimotion/utils/import.rb
93
93
  - lib/labimotion/utils/search.rb
94
94
  - lib/labimotion/utils/serializer.rb
95
+ - lib/labimotion/utils/utils.rb
95
96
  - lib/labimotion/version.rb
96
97
  homepage: https://github.com/phuang26/labimotion
97
98
  licenses: