labimotion 0.1.12 → 0.1.15

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: 9a72bc36d304bce71f181b4a5b8b5bcb81532cd21c204efee6f75fa3fb85a29f
4
+ data.tar.gz: d9fe725cf70b07074df5a045dcb5025090a1160c3c04621f8d13fe4e14a5cfbc
5
5
  SHA512:
6
- metadata.gz: b85976e6caf972dc33ce38b2ae128f3270c3f5b594485503d01c1ee3f4100c3cf6ec3352d51c755895a5e12bd19624a604221f9c69a3a4a5d2c0c4fc5bfc0bfb
7
- data.tar.gz: f3a777ef610da20216929d7e3278229c848dd56fa8c5a458e88667a6b524313d625fbd09127c96d32f32d99f53673505591129aeb4f6f49e2d4c71f1980f14dd
6
+ metadata.gz: dfffccf852420e3d9aac5ec9bb36ce9f10f738a4d814633d0a07a31a3dba9eabd712955dec68b9e18644fc888adf47b6967075b9994e1eb59a6fc4176eb4ffb0
7
+ data.tar.gz: 23c5d2ce7d797a86f29c29c6fcee85dfb78e61dca82a9b0dc4535b9e9098cda085b33089bcd2c2cb72b702df13a8805e29ff93ae27dc1efea7a65e756a37db07
@@ -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,9 @@ 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: [] }
24
27
  end
25
28
  end
26
29
 
@@ -32,6 +35,9 @@ module Labimotion
32
35
  get do
33
36
  list = klass_list(params[:generic_only])
34
37
  present list, with: Labimotion::ElementKlassEntity, root: 'klass'
38
+ rescue StandardError => e
39
+ Labimotion.log_exception(e, current_user)
40
+ { klass: [] }
35
41
  end
36
42
  end
37
43
 
@@ -67,6 +73,9 @@ module Labimotion
67
73
  post do
68
74
  authenticate_admin!('elements')
69
75
  update_element_klass(current_user, params)
76
+ rescue StandardError => e
77
+ Labimotion.log_exception(e, current_user)
78
+ raise e
70
79
  end
71
80
  end
72
81
 
@@ -79,6 +88,9 @@ module Labimotion
79
88
  get do
80
89
  list = list_klass_revisions(params)
81
90
  present list, with: Labimotion::KlassRevisionEntity, root: 'revisions'
91
+ rescue StandardError => e
92
+ Labimotion.log_exception(e, current_user)
93
+ []
82
94
  end
83
95
  end
84
96
 
@@ -90,6 +102,9 @@ module Labimotion
90
102
  get do
91
103
  list = element_revisions(params)
92
104
  present list, with: Labimotion::ElementRevisionEntity, root: 'revisions'
105
+ rescue StandardError => e
106
+ Labimotion.log_exception(e, current_user)
107
+ []
93
108
  end
94
109
  end
95
110
 
@@ -104,6 +119,9 @@ module Labimotion
104
119
  authenticate_admin!(params[:klass].gsub(/(Klass)/, 's').downcase)
105
120
  delete_klass_revision(params)
106
121
  status 201
122
+ rescue StandardError => e
123
+ Labimotion.log_exception(e, current_user)
124
+ raise e
107
125
  end
108
126
  end
109
127
 
@@ -117,6 +135,9 @@ module Labimotion
117
135
  post do
118
136
  delete_revision(params)
119
137
  status 201
138
+ rescue StandardError => e
139
+ Labimotion.log_exception(e, current_user)
140
+ raise e
120
141
  end
121
142
  end
122
143
 
@@ -129,6 +150,9 @@ module Labimotion
129
150
  klass = Labimotion::Segment.find(params[:id])
130
151
  list = klass.segments_revisions unless klass.nil?
131
152
  present list&.sort_by(&:created_at).reverse, with: Labimotion::SegmentRevisionEntity, root: 'revisions'
153
+ rescue StandardError => e
154
+ Labimotion.log_exception(e, current_user)
155
+ []
132
156
  end
133
157
  end
134
158
 
@@ -152,6 +176,9 @@ module Labimotion
152
176
  post do
153
177
  upload_generics_files(current_user, params)
154
178
  true
179
+ rescue StandardError => e
180
+ Labimotion.log_exception(e, current_user)
181
+ raise e
155
182
  end
156
183
  end
157
184
 
@@ -160,6 +187,33 @@ module Labimotion
160
187
  get do
161
188
  list = Labimotion::ElementKlass.all.sort_by { |e| e.place }
162
189
  present list, with: Labimotion::ElementKlassEntity, root: 'klass'
190
+ rescue StandardError => e
191
+ Labimotion.log_exception(e, current_user)
192
+ []
193
+ end
194
+ end
195
+
196
+ namespace :fetch_repo do
197
+ desc 'fetch Generic Element Klass from Chemotion Repository'
198
+ get do
199
+ fetch_repo('ElementKlass')
200
+ rescue StandardError => e
201
+ Labimotion.log_exception(e, current_user)
202
+ []
203
+ end
204
+ end
205
+
206
+ namespace :create_repo_klass do
207
+ desc 'create Generic Element Klass'
208
+ params do
209
+ requires :identifier, type: String, desc: 'Identifier'
210
+ end
211
+ post do
212
+ create_repo_klass(params, current_user)
213
+ present ElementKlass.all, with: Labimotion::ElementKlassEntity, root: 'klass'
214
+ rescue StandardError => e
215
+ Labimotion.log_exception(e, current_user)
216
+ { error: e.message }
163
217
  end
164
218
  end
165
219
 
@@ -176,6 +230,9 @@ module Labimotion
176
230
  end
177
231
  post do
178
232
  deactivate_klass(params)
233
+ rescue StandardError => e
234
+ Labimotion.log_exception(e, current_user)
235
+ raise e
179
236
  end
180
237
  end
181
238
 
@@ -188,6 +245,9 @@ module Labimotion
188
245
  delete ':id' do
189
246
  delete_klass(params)
190
247
  status 201
248
+ rescue StandardError => e
249
+ Labimotion.log_exception(e, current_user)
250
+ raise e
191
251
  end
192
252
  end
193
253
 
@@ -197,14 +257,17 @@ module Labimotion
197
257
  requires :klass, type: String, desc: 'Klass', values: %w[ElementKlass SegmentKlass DatasetKlass]
198
258
  requires :id, type: Integer, desc: 'Klass ID'
199
259
  requires :properties_template, type: Hash
200
- optional :is_release, type: Boolean, default: false
260
+ optional :release, type: String, default: 'draft', desc: 'release status', values: %w[draft major minor patch]
201
261
  end
202
262
  after_validation do
203
263
  authenticate_admin!(params[:klass].gsub(/(Klass)/, 's').downcase)
204
264
  @klz = fetch_klass(params[:klass], params[:id])
205
265
  end
206
266
  post do
207
- update_template(params)
267
+ update_template(params, current_user)
268
+ rescue StandardError => e
269
+ Labimotion.log_exception(e, current_user)
270
+ raise e
208
271
  end
209
272
  end
210
273
 
@@ -216,10 +279,10 @@ module Labimotion
216
279
  optional :from_date, type: Integer, desc: 'created_date from in ms'
217
280
  optional :to_date, type: Integer, desc: 'created_date to in ms'
218
281
  optional :filter_created_at, type: Boolean, desc: 'filter by created at or updated at'
282
+ optional :sort_column, type: String, desc: 'sort by updated_at or selected layers property'
219
283
  end
220
284
  paginate per_page: 7, offset: 0, max_per_page: 100
221
285
  get do
222
-
223
286
  scope = list_serialized_elements(params, current_user)
224
287
 
225
288
  reset_pagination_page(scope)
@@ -235,6 +298,9 @@ module Labimotion
235
298
  end
236
299
  end
237
300
  { generic_elements: generic_elements }
301
+ rescue StandardError => e
302
+ Labimotion.log_exception(e, current_user)
303
+ { generic_elements: [] }
238
304
  end
239
305
 
240
306
  desc 'Return serialized element by id'
@@ -262,6 +328,8 @@ module Labimotion
262
328
  attachments: Entities::AttachmentEntity.represent(element.attachments),
263
329
  }
264
330
  end
331
+ rescue StandardError => e
332
+ Labimotion.log_exception(e, current_user)
265
333
  end
266
334
  end
267
335
 
@@ -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
@@ -168,8 +168,8 @@ module Labimotion
168
168
  (attach_ary << att_ary).flatten! unless att_ary&.empty?
169
169
 
170
170
  if Labimotion::IS_RAILS5 == true
171
- TransferThumbnailToPublicJob.set(queue: "transfer_thumbnail_to_public_#{current_user.id}").perform_later(attach_ary) unless attach_ary.empty?
172
- TransferFileFromTmpJob.set(queue: "transfer_file_from_tmp_#{current_user.id}").perform_later(attach_ary) unless attach_ary.empty?
171
+ TransferThumbnailToPublicJob.set(queue: "transfer_thumbnail_to_public_#{current_user.id}").perform_now(attach_ary) unless attach_ary.empty?
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
175
  rescue StandardError => e
@@ -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