labimotion 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/labimotion/apis/generic_dataset_api.rb +4 -3
- data/lib/labimotion/apis/generic_element_api.rb +58 -10
- data/lib/labimotion/apis/labimotion_hub_api.rb +13 -4
- data/lib/labimotion/apis/segment_api.rb +4 -3
- data/lib/labimotion/entities/generic_public_entity.rb +2 -0
- data/lib/labimotion/helpers/dataset_helpers.rb +16 -7
- data/lib/labimotion/helpers/element_helpers.rb +68 -23
- data/lib/labimotion/helpers/generic_helpers.rb +21 -20
- data/lib/labimotion/helpers/segment_helpers.rb +24 -11
- data/lib/labimotion/libs/converter.rb +18 -9
- data/lib/labimotion/libs/export_dataset.rb +14 -4
- data/lib/labimotion/libs/nmr_mapper.rb +14 -2
- data/lib/labimotion/libs/nmr_mapper_repo.rb +20 -5
- data/lib/labimotion/libs/template_hub.rb +8 -4
- data/lib/labimotion/models/concerns/attachment_converter.rb +1 -0
- data/lib/labimotion/models/concerns/datasetable.rb +1 -0
- data/lib/labimotion/models/concerns/generic_klass_revisions.rb +13 -4
- data/lib/labimotion/models/concerns/segmentable.rb +3 -3
- data/lib/labimotion/models/concerns/workflow.rb +9 -0
- data/lib/labimotion/models/element.rb +4 -2
- data/lib/labimotion/models/element_klass.rb +0 -8
- data/lib/labimotion/models/hub_log.rb +8 -0
- data/lib/labimotion/models/segment_klass.rb +1 -0
- data/lib/labimotion/utils/export.rb +20 -0
- data/lib/labimotion/utils/utils.rb +0 -1
- data/lib/labimotion/version.rb +3 -3
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98cb8ba855fc0078623deb096b7ecb7d3136e4238a3e659c25d8fb19b61327f4
|
4
|
+
data.tar.gz: e206d57e3d94ce90a36b4b34f6d974384a09cd1477a0822fff6435e16380005c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 788f8bac2c8f5d49c89985fe796ab956e77bd0ecdefb9587aa0037fda7a963e3118368a610a3c1e7bf8bc13d314e7d0798daf7d0819f8cb90af8e9b5b9a58aa9
|
7
|
+
data.tar.gz: 6fc941c2c4559effa8aec29ed36023427605a92ca015001f094f807065601d4d428829212b136935651af539aef37afcf6e06a51574fafc90bcbc3d8f786bca8
|
@@ -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')
|
33
|
+
fetch_repo('DatasetKlass', current_user)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -40,8 +40,9 @@ module Labimotion
|
|
40
40
|
requires :identifier, type: String, desc: 'Identifier'
|
41
41
|
end
|
42
42
|
post do
|
43
|
-
create_repo_klass(params, current_user)
|
44
|
-
|
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 }
|
45
46
|
rescue StandardError => e
|
46
47
|
Labimotion.log_exception(e, current_user)
|
47
48
|
{ error: e.message }
|
@@ -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,13 +187,19 @@ 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
|
+
[]
|
163
193
|
end
|
164
194
|
end
|
165
195
|
|
166
196
|
namespace :fetch_repo do
|
167
197
|
desc 'fetch Generic Element Klass from Chemotion Repository'
|
168
198
|
get do
|
169
|
-
fetch_repo('ElementKlass')
|
199
|
+
fetch_repo('ElementKlass', current_user)
|
200
|
+
rescue StandardError => e
|
201
|
+
Labimotion.log_exception(e, current_user)
|
202
|
+
[]
|
170
203
|
end
|
171
204
|
end
|
172
205
|
|
@@ -176,8 +209,9 @@ module Labimotion
|
|
176
209
|
requires :identifier, type: String, desc: 'Identifier'
|
177
210
|
end
|
178
211
|
post do
|
179
|
-
create_repo_klass(params, current_user)
|
180
|
-
|
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 }
|
181
215
|
rescue StandardError => e
|
182
216
|
Labimotion.log_exception(e, current_user)
|
183
217
|
{ error: e.message }
|
@@ -197,6 +231,9 @@ module Labimotion
|
|
197
231
|
end
|
198
232
|
post do
|
199
233
|
deactivate_klass(params)
|
234
|
+
rescue StandardError => e
|
235
|
+
Labimotion.log_exception(e, current_user)
|
236
|
+
raise e
|
200
237
|
end
|
201
238
|
end
|
202
239
|
|
@@ -209,6 +246,9 @@ module Labimotion
|
|
209
246
|
delete ':id' do
|
210
247
|
delete_klass(params)
|
211
248
|
status 201
|
249
|
+
rescue StandardError => e
|
250
|
+
Labimotion.log_exception(e, current_user)
|
251
|
+
raise e
|
212
252
|
end
|
213
253
|
end
|
214
254
|
|
@@ -225,7 +265,10 @@ module Labimotion
|
|
225
265
|
@klz = fetch_klass(params[:klass], params[:id])
|
226
266
|
end
|
227
267
|
post do
|
228
|
-
update_template(params)
|
268
|
+
update_template(params, current_user)
|
269
|
+
rescue StandardError => e
|
270
|
+
Labimotion.log_exception(e, current_user)
|
271
|
+
raise e
|
229
272
|
end
|
230
273
|
end
|
231
274
|
|
@@ -237,10 +280,10 @@ module Labimotion
|
|
237
280
|
optional :from_date, type: Integer, desc: 'created_date from in ms'
|
238
281
|
optional :to_date, type: Integer, desc: 'created_date to in ms'
|
239
282
|
optional :filter_created_at, type: Boolean, desc: 'filter by created at or updated at'
|
283
|
+
optional :sort_column, type: String, desc: 'sort by updated_at or selected layers property'
|
240
284
|
end
|
241
285
|
paginate per_page: 7, offset: 0, max_per_page: 100
|
242
286
|
get do
|
243
|
-
|
244
287
|
scope = list_serialized_elements(params, current_user)
|
245
288
|
|
246
289
|
reset_pagination_page(scope)
|
@@ -256,6 +299,9 @@ module Labimotion
|
|
256
299
|
end
|
257
300
|
end
|
258
301
|
{ generic_elements: generic_elements }
|
302
|
+
rescue StandardError => e
|
303
|
+
Labimotion.log_exception(e, current_user)
|
304
|
+
{ generic_elements: [] }
|
259
305
|
end
|
260
306
|
|
261
307
|
desc 'Return serialized element by id'
|
@@ -272,7 +318,7 @@ module Labimotion
|
|
272
318
|
if Labimotion::IS_RAILS5 == true
|
273
319
|
{
|
274
320
|
element: ElementPermissionProxy.new(current_user, element, user_ids).serialized,
|
275
|
-
attachments:
|
321
|
+
attachments: attach_thumbnail(element&.attachments)
|
276
322
|
}
|
277
323
|
else
|
278
324
|
{
|
@@ -280,9 +326,11 @@ module Labimotion
|
|
280
326
|
element,
|
281
327
|
detail_levels: ElementDetailLevelCalculator.new(user: current_user, element: element).detail_levels,
|
282
328
|
),
|
283
|
-
attachments:
|
329
|
+
attachments: attach_thumbnail(element&.attachments)
|
284
330
|
}
|
285
331
|
end
|
332
|
+
rescue StandardError => e
|
333
|
+
Labimotion.log_exception(e, current_user)
|
286
334
|
end
|
287
335
|
end
|
288
336
|
|
@@ -302,7 +350,7 @@ module Labimotion
|
|
302
350
|
if Labimotion::IS_RAILS5 == true
|
303
351
|
{
|
304
352
|
element: ElementPermissionProxy.new(current_user, element, user_ids).serialized,
|
305
|
-
attachments:
|
353
|
+
attachments: attach_thumbnail(element&.attachments)
|
306
354
|
}
|
307
355
|
else
|
308
356
|
present(
|
@@ -338,7 +386,7 @@ module Labimotion
|
|
338
386
|
if Labimotion::IS_RAILS5 == true
|
339
387
|
{
|
340
388
|
element: ElementPermissionProxy.new(current_user, element, user_ids).serialized,
|
341
|
-
attachments:
|
389
|
+
attachments: attach_thumbnail(element&.attachments)
|
342
390
|
}
|
343
391
|
else
|
344
392
|
{
|
@@ -346,7 +394,7 @@ module Labimotion
|
|
346
394
|
element,
|
347
395
|
detail_levels: ElementDetailLevelCalculator.new(user: current_user, element: element).detail_levels,
|
348
396
|
),
|
349
|
-
attachments:
|
397
|
+
attachments: attach_thumbnail(element&.attachments),
|
350
398
|
}
|
351
399
|
end
|
352
400
|
rescue StandardError => e
|
@@ -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
|
-
|
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
|
-
|
32
|
+
requires :origin, type: String, desc: 'origin'
|
30
33
|
requires :identifier, type: String, desc: 'Identifier'
|
31
34
|
end
|
32
|
-
|
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
|
-
|
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
|
|
@@ -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')
|
121
|
+
fetch_repo('SegmentKlass', current_user)
|
122
122
|
rescue StandardError => e
|
123
123
|
Labimotion.log_exception(e, current_user)
|
124
124
|
{ error: e.message }
|
@@ -131,8 +131,9 @@ module Labimotion
|
|
131
131
|
requires :identifier, type: String, desc: 'Identifier'
|
132
132
|
end
|
133
133
|
post do
|
134
|
-
create_repo_klass(params, current_user)
|
135
|
-
|
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 }
|
136
137
|
rescue StandardError => e
|
137
138
|
Labimotion.log_exception(e, current_user)
|
138
139
|
## { error: e.message }
|
@@ -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|
|
@@ -13,23 +13,32 @@ module Labimotion
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
def create_repo_klass(params, current_user)
|
17
|
-
response = Labimotion::TemplateHub.fetch_identifier('DatasetKlass', params[:identifier])
|
16
|
+
def create_repo_klass(params, current_user, origin)
|
17
|
+
response = Labimotion::TemplateHub.fetch_identifier('DatasetKlass', params[:identifier], origin)
|
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
|
-
attributes['
|
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
|
23
24
|
attributes['sync_by'] = current_user.id
|
24
25
|
attributes['sync_time'] = DateTime.now
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
28
36
|
else
|
29
37
|
attributes['created_by'] = current_user.id
|
30
38
|
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']}!" }
|
31
41
|
end
|
32
|
-
ds.create_klasses_revision(current_user.id)
|
33
42
|
rescue StandardError => e
|
34
43
|
Labimotion.log_exception(e, current_user)
|
35
44
|
# { error: e.message }
|
@@ -20,12 +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
|
-
if attributes[:properties_template].
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
attributes[:properties_template]['klass'] = 'ElementKlass'
|
28
|
-
end
|
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'
|
29
27
|
attributes[:is_active] = false
|
30
28
|
attributes[:uuid] = uuid
|
31
29
|
attributes[:released_at] = DateTime.now
|
@@ -34,7 +32,7 @@ module Labimotion
|
|
34
32
|
|
35
33
|
new_klass = Labimotion::ElementKlass.create!(attributes)
|
36
34
|
new_klass.reload
|
37
|
-
new_klass.create_klasses_revision(current_user
|
35
|
+
new_klass.create_klasses_revision(current_user)
|
38
36
|
klass_names_file = Rails.root.join('app/packs/klasses.json')
|
39
37
|
klasses = Labimotion::ElementKlass.where(is_active: true)&.pluck(:name) || []
|
40
38
|
File.write(klass_names_file, klasses)
|
@@ -71,6 +69,7 @@ module Labimotion
|
|
71
69
|
params[:properties]['klass_uuid'] = klass[:uuid]
|
72
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?
|
76
75
|
properties.delete('flowObject') unless properties['flowObject'].nil?
|
@@ -160,7 +159,7 @@ module Labimotion
|
|
160
159
|
att_ary = create_attachments(
|
161
160
|
params[:attfiles],
|
162
161
|
params[:delfiles],
|
163
|
-
params[:att_type],
|
162
|
+
"Labimotion::#{params[:att_type]}",
|
164
163
|
params[:att_id],
|
165
164
|
params[:attfilesIdentifier],
|
166
165
|
current_user.id
|
@@ -175,8 +174,7 @@ module Labimotion
|
|
175
174
|
true
|
176
175
|
rescue StandardError => e
|
177
176
|
Labimotion.log_exception(e, current_user)
|
178
|
-
|
179
|
-
raise e
|
177
|
+
false
|
180
178
|
end
|
181
179
|
|
182
180
|
def element_revisions(params)
|
@@ -247,7 +245,7 @@ module Labimotion
|
|
247
245
|
.where(
|
248
246
|
element_klasses: { name: params[:el_type] },
|
249
247
|
collections_elements: { collection_id: collection_id },
|
250
|
-
).includes(:tag, collections: :sync_collections_users)
|
248
|
+
).includes(:tag, collections: :sync_collections_users)
|
251
249
|
else
|
252
250
|
Labimotion::Element.none
|
253
251
|
end
|
@@ -256,20 +254,46 @@ module Labimotion
|
|
256
254
|
from = params[:from_date]
|
257
255
|
to = params[:to_date]
|
258
256
|
by_created_at = params[:filter_created_at] || false
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
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
|
263
286
|
scope
|
264
287
|
rescue StandardError => e
|
265
288
|
Labimotion.log_exception(e, current_user)
|
266
289
|
raise e
|
267
290
|
end
|
268
291
|
|
269
|
-
def create_repo_klass(params, current_user)
|
270
|
-
response = Labimotion::TemplateHub.fetch_identifier('ElementKlass', params[:identifier])
|
271
|
-
attributes = response.slice('name', 'label', 'desc', 'icon_name', 'klass_prefix', 'is_generic', 'identifier', 'properties_release', 'version')
|
272
|
-
attributes['
|
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')
|
295
|
+
attributes['properties_release']['identifier'] = attributes['identifier']
|
296
|
+
attributes['properties_template'] = attributes['properties_release']
|
273
297
|
attributes['place'] = ((Labimotion::DatasetKlass.all.length * 10) || 0) + 10
|
274
298
|
attributes['is_active'] = false
|
275
299
|
attributes['updated_by'] = current_user.id
|
@@ -278,17 +302,38 @@ module Labimotion
|
|
278
302
|
|
279
303
|
element_klass = Labimotion::ElementKlass.find_by(identifier: attributes['identifier'])
|
280
304
|
if element_klass.present?
|
281
|
-
element_klass
|
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
|
282
312
|
else
|
283
|
-
attributes['
|
284
|
-
|
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
|
285
322
|
end
|
286
|
-
element_klass.create_klasses_revision(current_user.id)
|
287
323
|
rescue StandardError => e
|
288
324
|
Labimotion.log_exception(e, current_user)
|
289
325
|
# { error: e.message }
|
290
326
|
raise e
|
291
327
|
end
|
292
328
|
|
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
|
+
|
293
338
|
end
|
294
339
|
end
|
@@ -41,22 +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
48
|
properties['uuid'] = uuid
|
49
|
-
|
50
49
|
klz.version = Labimotion::Utils.next_version(params[:release], klz.version)
|
51
50
|
properties['version'] = klz.version
|
52
|
-
properties['pkg'] = Labimotion::Utils.pkg(params['pkg'] || klz.properties_template['pkg'])
|
51
|
+
properties['pkg'] = Labimotion::Utils.pkg(params['pkg'] || (klz.properties_template && klz.properties_template['pkg']))
|
53
52
|
properties['klass'] = klz.class.name.split('::').last
|
53
|
+
properties['identifier'] = klz.identifier
|
54
54
|
properties.delete('eln') if properties['eln'].present?
|
55
55
|
klz.updated_by = current_user.id
|
56
56
|
klz.properties_template = properties
|
57
57
|
klz.save!
|
58
58
|
klz.reload
|
59
|
-
klz.create_klasses_revision(current_user
|
59
|
+
klz.create_klasses_revision(current_user) if params[:release] != 'draft'
|
60
60
|
klz
|
61
61
|
rescue StandardError => e
|
62
62
|
Labimotion.log_exception(e, current_user)
|
@@ -188,37 +188,37 @@ module Labimotion
|
|
188
188
|
raise e
|
189
189
|
end
|
190
190
|
|
191
|
-
def create_attachments(files, del_files, type, id, user_id)
|
191
|
+
def create_attachments(files, del_files, type, id, identifier, user_id)
|
192
192
|
attach_ary = []
|
193
|
-
(files || []).
|
193
|
+
(files || []).each_with_index do |file, index|
|
194
194
|
next unless (tempfile = file[:tempfile])
|
195
195
|
|
196
|
-
|
196
|
+
att = Attachment.new(
|
197
197
|
bucket: file[:container_id],
|
198
198
|
filename: file[:filename],
|
199
199
|
con_state: Labimotion::ConState::NONE,
|
200
200
|
file_path: file[:tempfile],
|
201
201
|
created_by: user_id,
|
202
202
|
created_for: user_id,
|
203
|
+
identifier: identifier[index],
|
203
204
|
content_type: file[:type],
|
204
205
|
attachable_type: type,
|
205
206
|
attachable_id: id,
|
206
207
|
)
|
207
208
|
begin
|
208
|
-
|
209
|
-
attach_ary.push(
|
209
|
+
att.save!
|
210
|
+
attach_ary.push(att.id)
|
210
211
|
ensure
|
211
212
|
tempfile.close
|
212
213
|
tempfile.unlink
|
213
214
|
end
|
214
215
|
end
|
215
216
|
unless (del_files || []).empty?
|
216
|
-
Attachment.where('id IN (?) AND attachable_type = (?)', del_files.map!(&:to_i),
|
217
|
-
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)
|
218
218
|
end
|
219
219
|
attach_ary
|
220
220
|
rescue StandardError => e
|
221
|
-
Labimotion.log_exception(e
|
221
|
+
Labimotion.log_exception(e)
|
222
222
|
raise e
|
223
223
|
end
|
224
224
|
|
@@ -230,15 +230,16 @@ module Labimotion
|
|
230
230
|
Chemotion::Generic::Fetch::Template.list(API::TARGET, name)
|
231
231
|
end
|
232
232
|
|
233
|
-
def fetch_repo(name)
|
234
|
-
current_klasses = "Labimotion::#{name}".constantize.where.not(identifier: nil)&.pluck(:identifier) || []
|
233
|
+
def fetch_repo(name, current_user)
|
234
|
+
# current_klasses = "Labimotion::#{name}".constantize.where.not(identifier: nil)&.pluck(:identifier) || []
|
235
235
|
response = Labimotion::TemplateHub.list(name)
|
236
|
-
if response && response['list'].present? && response['list'].length.positive?
|
237
|
-
filter_list = response['list']&.reject do |ds|
|
238
|
-
|
239
|
-
end || []
|
240
|
-
end
|
241
|
-
filter_list || []
|
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']) || []
|
242
243
|
rescue StandardError => e
|
243
244
|
Labimotion.log_exception(e, current_user)
|
244
245
|
{ error: 'Cannot connect to Chemotion Repository' }
|
@@ -38,7 +38,7 @@ module Labimotion
|
|
38
38
|
attributes[:properties_release] = attributes[:properties_template]
|
39
39
|
klass = Labimotion::SegmentKlass.create!(attributes)
|
40
40
|
klass.reload
|
41
|
-
klass.create_klasses_revision(current_user
|
41
|
+
klass.create_klasses_revision(current_user)
|
42
42
|
klass
|
43
43
|
rescue StandardError => e
|
44
44
|
Labimotion.log_exception(e, current_user)
|
@@ -63,10 +63,11 @@ module Labimotion
|
|
63
63
|
raise e
|
64
64
|
end
|
65
65
|
|
66
|
-
def create_repo_klass(params, current_user)
|
67
|
-
response = Labimotion::TemplateHub.fetch_identifier('SegmentKlass', params[:identifier])
|
68
|
-
attributes = response.slice('label', 'desc', 'uuid', 'identifier', 'released_at', 'properties_release', 'version')
|
69
|
-
attributes['
|
66
|
+
def create_repo_klass(params, current_user, origin)
|
67
|
+
response = Labimotion::TemplateHub.fetch_identifier('SegmentKlass', params[:identifier], origin)
|
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']
|
70
71
|
attributes['place'] = ((Labimotion::SegmentKlass.all.length * 10) || 0) + 10
|
71
72
|
attributes['is_active'] = false
|
72
73
|
attributes['updated_by'] = current_user.id
|
@@ -74,8 +75,8 @@ module Labimotion
|
|
74
75
|
attributes['sync_time'] = DateTime.now
|
75
76
|
|
76
77
|
element_klass = Labimotion::ElementKlass.find_by(identifier: response['element_klass']['identifier'])
|
77
|
-
element_klass = Labimotion::ElementKlass.find_by(name: response['element_klass']['name']) if element_klass.nil?
|
78
|
-
return { error: '
|
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?
|
79
80
|
|
80
81
|
# el_attributes = response['element_klass'].slice('name', 'label', 'desc', 'uuid', 'identifier', 'icon_name', 'klass_prefix', 'is_generic', 'released_at')
|
81
82
|
# el_attributes['properties_template'] = response['element_klass']['properties_release']
|
@@ -84,12 +85,24 @@ module Labimotion
|
|
84
85
|
attributes['element_klass_id'] = element_klass.id
|
85
86
|
segment_klass = Labimotion::SegmentKlass.find_by(identifier: attributes['identifier'])
|
86
87
|
if segment_klass.present?
|
87
|
-
segment_klass
|
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
95
|
else
|
89
|
-
attributes['
|
90
|
-
|
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
|
91
105
|
end
|
92
|
-
segment_klass.create_klasses_revision(current_user.id)
|
93
106
|
rescue StandardError => e
|
94
107
|
Labimotion.log_exception(e, current_user)
|
95
108
|
raise e
|
@@ -4,6 +4,7 @@ require 'net/http'
|
|
4
4
|
require 'uri'
|
5
5
|
require 'json'
|
6
6
|
require 'date'
|
7
|
+
require 'labimotion/version'
|
7
8
|
require 'labimotion/utils/utils'
|
8
9
|
|
9
10
|
# rubocop: disable Metrics/AbcSize
|
@@ -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
|
-
|
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
|
-
|
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
|
-
|
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
|
|
@@ -227,6 +234,8 @@ module Labimotion
|
|
227
234
|
new_prop = dataset.properties
|
228
235
|
dsr.each do |ds|
|
229
236
|
layer = layers[ds[:layer]]
|
237
|
+
next if layer.nil? || layer['fields'].nil?
|
238
|
+
|
230
239
|
fields = layer['fields'].select{ |f| f['field'] == ds[:field] }
|
231
240
|
fi = fields&.first
|
232
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
|
@@ -100,10 +101,19 @@ module Labimotion
|
|
100
101
|
cds = Container.find(id)
|
101
102
|
cds.attachments.where(aasm_state: 'csv').each do |att|
|
102
103
|
name = File.basename(att.filename, '.csv')
|
103
|
-
sheet = @xfile.workbook.add_worksheet(name: name)
|
104
|
-
|
105
|
-
|
106
|
-
|
104
|
+
sheet = @xfile.workbook.add_worksheet(name: name.slice(0, 25))
|
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,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'labimotion/version'
|
3
4
|
require 'labimotion/utils/utils'
|
4
5
|
|
5
6
|
module Labimotion
|
@@ -7,8 +8,8 @@ module Labimotion
|
|
7
8
|
class NmrMapper
|
8
9
|
def self.is_brucker_binary(id)
|
9
10
|
att = Attachment.find(id)
|
10
|
-
if
|
11
|
-
Zip::File.open(att.
|
11
|
+
if Labimotion::IS_RAILS5 == true
|
12
|
+
Zip::File.open(att.store.path) do |zip_file|
|
12
13
|
zip_file.each do |entry|
|
13
14
|
if entry.name.include?('/pdata/') && entry.name.include?('parm.txt')
|
14
15
|
metadata = entry.get_input_stream.read.force_encoding('UTF-8')
|
@@ -16,6 +17,17 @@ module Labimotion
|
|
16
17
|
end
|
17
18
|
end
|
18
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
|
19
31
|
end
|
20
32
|
nil
|
21
33
|
end
|
@@ -1,18 +1,33 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
require 'labimotion/version'
|
2
3
|
require 'labimotion/utils/utils'
|
3
4
|
|
4
5
|
module Labimotion
|
5
6
|
class NmrMapperRepo
|
6
7
|
def self.is_brucker_binary(id)
|
7
8
|
att = Attachment.find(id)
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
13
27
|
end
|
14
28
|
end
|
15
29
|
end
|
30
|
+
|
16
31
|
nil
|
17
32
|
end
|
18
33
|
|
@@ -43,11 +43,15 @@ module Labimotion
|
|
43
43
|
error!('Cannot connect to Chemotion Repository', 401)
|
44
44
|
end
|
45
45
|
|
46
|
-
def self.fetch_identifier(klass, identifier)
|
47
|
-
|
48
|
-
response = HTTParty.
|
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
|
+
)
|
49
53
|
# response.parsed_response if response.code == 200
|
50
|
-
JSON.parse(response.body) if response.code ==
|
54
|
+
JSON.parse(response.body) if response.code == 201
|
51
55
|
rescue StandardError => e
|
52
56
|
Labimotion.log_exception(e)
|
53
57
|
error!('Cannot connect to Chemotion Repository', 401)
|
@@ -1,13 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Labimotion
|
4
|
-
|
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(
|
11
|
+
def create_klasses_revision(current_user)
|
11
12
|
properties_release = properties_template
|
12
13
|
migrate_workflow if properties_release['flow'].present?
|
13
14
|
|
@@ -21,11 +22,19 @@ module Labimotion
|
|
21
22
|
end
|
22
23
|
properties_release['flowObject']['nodes'] = elements
|
23
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
|
+
}
|
24
33
|
|
25
|
-
self.update!(
|
34
|
+
self.update!(klass_attributes)
|
26
35
|
reload
|
27
36
|
attributes = {
|
28
|
-
released_by:
|
37
|
+
released_by: released_by,
|
29
38
|
uuid: uuid,
|
30
39
|
version: version,
|
31
40
|
properties_release: properties_release,
|
@@ -41,13 +41,13 @@ module Labimotion
|
|
41
41
|
|
42
42
|
def save_segments(**args) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
43
43
|
return if args[:segments].nil?
|
44
|
-
|
45
44
|
segments = []
|
46
|
-
args[:segments]
|
45
|
+
args[:segments]&.each do |seg|
|
47
46
|
klass = Labimotion::SegmentKlass.find_by(id: seg['segment_klass_id'])
|
48
47
|
uuid = SecureRandom.uuid
|
49
48
|
props = seg['properties']
|
50
49
|
props['pkg'] = Labimotion::Utils.pkg(props['pkg'])
|
50
|
+
props['identifier'] = klass.identifier if klass.identifier.present?
|
51
51
|
props['uuid'] = uuid
|
52
52
|
props['klass'] = 'Segment'
|
53
53
|
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 +58,7 @@ module Labimotion
|
|
58
58
|
next if segment.present?
|
59
59
|
|
60
60
|
props['klass_uuid'] = klass.uuid
|
61
|
-
segment = Labimotion::Segment.create!(properties_release: klass.properties_release, segment_klass_id: seg['segment_klass_id'], element_type:
|
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
62
|
segments.push(segment)
|
63
63
|
end
|
64
64
|
segments
|
@@ -23,5 +23,14 @@ 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
|
26
35
|
end
|
27
36
|
end
|
@@ -7,10 +7,12 @@ module Labimotion
|
|
7
7
|
class Element < ApplicationRecord
|
8
8
|
acts_as_paranoid
|
9
9
|
self.table_name = :elements
|
10
|
-
include PgSearch::
|
10
|
+
include PgSearch if Labimotion::IS_RAILS5 == true
|
11
|
+
include PgSearch::Model if Labimotion::IS_RAILS5 == false
|
11
12
|
include ElementUIStateScopes
|
12
13
|
include Collectable
|
13
14
|
## include AnalysisCodes
|
15
|
+
include ElementCodes
|
14
16
|
include Taggable
|
15
17
|
include Workflow
|
16
18
|
include Segmentable
|
@@ -57,7 +59,7 @@ module Labimotion
|
|
57
59
|
|
58
60
|
|
59
61
|
def attachments
|
60
|
-
Attachment.where(attachable_id: self.id, attachable_type:
|
62
|
+
Attachment.where(attachable_id: self.id, attachable_type: self.class.name)
|
61
63
|
end
|
62
64
|
|
63
65
|
def self.get_associated_samples(element_ids)
|
@@ -23,13 +23,5 @@ 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
|
34
26
|
end
|
35
27
|
end
|
@@ -6,6 +6,7 @@ module Labimotion
|
|
6
6
|
self.table_name = :segment_klasses
|
7
7
|
acts_as_paranoid
|
8
8
|
include GenericKlassRevisions
|
9
|
+
include Workflow
|
9
10
|
belongs_to :element_klass, class_name: 'Labimotion::ElementKlass'
|
10
11
|
has_many :segments, dependent: :destroy, class_name: 'Labimotion::Segment'
|
11
12
|
has_many :segment_klasses_revisions, dependent: :destroy, class_name: 'Labimotion::SegmentKlassesRevision'
|
@@ -22,6 +22,26 @@ 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
|
25
45
|
|
26
46
|
def self.fetch_segments(element, attachments, &fetch_one)
|
27
47
|
element_type = element.class.name
|
data/lib/labimotion/version.rb
CHANGED
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.
|
4
|
+
version: 0.3.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-
|
12
|
+
date: 2023-09-10 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:
|
20
|
+
version: 5.2.0
|
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:
|
27
|
+
version: 5.2.0
|
28
28
|
description:
|
29
29
|
email:
|
30
30
|
- chia-lin.lin@kit.edu
|
@@ -84,6 +84,7 @@ 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
|
87
88
|
- lib/labimotion/models/segment.rb
|
88
89
|
- lib/labimotion/models/segment_klass.rb
|
89
90
|
- lib/labimotion/models/segment_klasses_revision.rb
|