labimotion 1.3.0.rc3 → 1.3.0.rc5
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 +4 -4
- data/lib/labimotion/apis/generic_element_api.rb +57 -58
- data/lib/labimotion/apis/generic_klass_api.rb +34 -0
- data/lib/labimotion/apis/segment_api.rb +25 -10
- data/lib/labimotion/helpers/element_helpers.rb +22 -20
- data/lib/labimotion/helpers/param_helpers.rb +97 -0
- data/lib/labimotion/helpers/segment_helpers.rb +26 -18
- data/lib/labimotion/libs/converter.rb +8 -27
- data/lib/labimotion/libs/export_dataset.rb +3 -12
- data/lib/labimotion/libs/export_element.rb +89 -25
- data/lib/labimotion/libs/nmr_mapper.rb +2 -15
- data/lib/labimotion/models/concerns/generic_klass_revisions.rb +6 -0
- data/lib/labimotion/utils/field_type.rb +2 -0
- data/lib/labimotion/utils/units.rb +465 -0
- data/lib/labimotion/version.rb +1 -2
- data/lib/labimotion.rb +2 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1544df427f4bbeeac189991d5dba50f8759e4ccc869b864edcee7479ba455bac
|
4
|
+
data.tar.gz: 5113e6ceffe6908efb4767cdffc3721131903d07668722e22e6503197bafc181
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1111378004a5bea4f3ac3a1e2056eb3003db3f21dc8887813d97d4a73ffa8df0473b72bd2c3c6450c50ce9b1a30d736303b34c156bb50124ca58ee09e43b151
|
7
|
+
data.tar.gz: 8ced73f30bea84693d46de94398e621badda9419d77432da3f81eb6d0aef0fc64c06e41cb80d18859936eeb773fdb77a5a6bc623aff0d6a0effd6132fa603042
|
@@ -13,6 +13,7 @@ module Labimotion
|
|
13
13
|
helpers Labimotion::SampleAssociationHelpers
|
14
14
|
helpers Labimotion::GenericHelpers
|
15
15
|
helpers Labimotion::ElementHelpers
|
16
|
+
helpers Labimotion::ParamHelpers
|
16
17
|
|
17
18
|
resource :generic_elements do
|
18
19
|
namespace :klass do
|
@@ -46,12 +47,19 @@ module Labimotion
|
|
46
47
|
namespace :export do
|
47
48
|
desc 'export element'
|
48
49
|
params do
|
49
|
-
|
50
|
+
requires :id, type: Integer, desc: 'element id'
|
51
|
+
requires :klass, type: String, desc: 'Klass', values: %w[Element Segment Dataset]
|
50
52
|
optional :export_format, type: String, desc: 'export format'
|
51
53
|
end
|
52
54
|
get do
|
53
|
-
|
54
|
-
|
55
|
+
case params[:klass]
|
56
|
+
when 'Element'
|
57
|
+
element = Labimotion::Element.find(params[:id])
|
58
|
+
when 'Segment'
|
59
|
+
element = Labimotion::Segment.find(params[:id])
|
60
|
+
when 'Dataset'
|
61
|
+
element = Labimotion::Dataset.find(params[:id])
|
62
|
+
end
|
55
63
|
export = Labimotion::ExportElement.new current_user, element, params[:export_format]
|
56
64
|
env['api.format'] = :binary
|
57
65
|
content_type 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
|
@@ -70,12 +78,7 @@ module Labimotion
|
|
70
78
|
namespace :create_element_klass do
|
71
79
|
desc 'create Generic Element Klass'
|
72
80
|
params do
|
73
|
-
|
74
|
-
requires :label, type: String, desc: 'Element Klass Label'
|
75
|
-
requires :klass_prefix, type: String, desc: 'Element Klass Short Label Prefix'
|
76
|
-
optional :icon_name, type: String, desc: 'Element Klass Icon Name'
|
77
|
-
optional :desc, type: String, desc: 'Element Klass Desc'
|
78
|
-
optional :properties_template, type: Hash, desc: 'Element Klass properties template'
|
81
|
+
use :create_element_klass_params
|
79
82
|
end
|
80
83
|
post do
|
81
84
|
authenticate_admin!('elements')
|
@@ -89,12 +92,7 @@ module Labimotion
|
|
89
92
|
namespace :update_element_klass do
|
90
93
|
desc 'update Generic Element Klass'
|
91
94
|
params do
|
92
|
-
|
93
|
-
optional :label, type: String, desc: 'Element Klass Label'
|
94
|
-
optional :klass_prefix, type: String, desc: 'Element Klass Short Label Prefix'
|
95
|
-
optional :icon_name, type: String, desc: 'Element Klass Icon Name'
|
96
|
-
optional :desc, type: String, desc: 'Element Klass Desc'
|
97
|
-
optional :place, type: String, desc: 'Element Klass Place'
|
95
|
+
use :update_element_klass_params
|
98
96
|
end
|
99
97
|
post do
|
100
98
|
authenticate_admin!('elements')
|
@@ -298,6 +296,39 @@ module Labimotion
|
|
298
296
|
end
|
299
297
|
end
|
300
298
|
|
299
|
+
namespace :upload_klass do
|
300
|
+
desc 'upload Generic Klass'
|
301
|
+
params do
|
302
|
+
use :upload_element_klass_params
|
303
|
+
end
|
304
|
+
post do
|
305
|
+
declared_params = declared(params, include_missing: false)
|
306
|
+
attributes = declared_params.merge(
|
307
|
+
created_by: current_user.id,
|
308
|
+
released_by: current_user.id,
|
309
|
+
updated_by: current_user.id,
|
310
|
+
is_active: false
|
311
|
+
)
|
312
|
+
validate_klass(attributes)
|
313
|
+
rescue StandardError => e
|
314
|
+
Labimotion.log_exception(e, current_user)
|
315
|
+
raise e
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
namespace :split do
|
320
|
+
desc 'split elements'
|
321
|
+
params do
|
322
|
+
requires :ui_state, type: Hash, desc: 'Selected elements from the UI'
|
323
|
+
end
|
324
|
+
post do
|
325
|
+
split_elements(params[:ui_state], current_user)
|
326
|
+
rescue StandardError => e
|
327
|
+
Labimotion.log_exception(e, current_user)
|
328
|
+
{ error: e.message }
|
329
|
+
end
|
330
|
+
end
|
331
|
+
|
301
332
|
desc 'Return serialized elements of current user'
|
302
333
|
params do
|
303
334
|
optional :collection_id, type: Integer, desc: 'Collection id'
|
@@ -311,7 +342,6 @@ module Labimotion
|
|
311
342
|
paginate per_page: 7, offset: 0, max_per_page: 100
|
312
343
|
get do
|
313
344
|
scope = list_serialized_elements(params, current_user)
|
314
|
-
|
315
345
|
reset_pagination_page(scope)
|
316
346
|
generic_elements = paginate(scope).map do |element|
|
317
347
|
Labimotion::ElementEntity.represent(
|
@@ -340,21 +370,14 @@ module Labimotion
|
|
340
370
|
|
341
371
|
get do
|
342
372
|
element = Labimotion::Element.find(params[:id])
|
343
|
-
|
344
|
-
|
345
|
-
element
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
element,
|
352
|
-
detail_levels: ElementDetailLevelCalculator.new(user: current_user, element: element).detail_levels,
|
353
|
-
policy: @element_policy
|
354
|
-
),
|
355
|
-
attachments: attach_thumbnail(element&.attachments)
|
356
|
-
}
|
357
|
-
end
|
373
|
+
{
|
374
|
+
element: Labimotion::ElementEntity.represent(
|
375
|
+
element,
|
376
|
+
detail_levels: ElementDetailLevelCalculator.new(user: current_user, element: element).detail_levels,
|
377
|
+
policy: @element_policy
|
378
|
+
),
|
379
|
+
attachments: attach_thumbnail(element&.attachments)
|
380
|
+
}
|
358
381
|
rescue StandardError => e
|
359
382
|
Labimotion.log_exception(e, current_user)
|
360
383
|
end
|
@@ -362,13 +385,7 @@ module Labimotion
|
|
362
385
|
|
363
386
|
desc 'Create a element'
|
364
387
|
params do
|
365
|
-
|
366
|
-
requires :name, type: String
|
367
|
-
optional :properties, type: Hash
|
368
|
-
optional :properties_release, type: Hash
|
369
|
-
optional :collection_id, type: Integer
|
370
|
-
requires :container, type: Hash
|
371
|
-
optional :segments, type: Array, desc: 'Segments'
|
388
|
+
use :create_element_params
|
372
389
|
end
|
373
390
|
post do
|
374
391
|
begin
|
@@ -387,12 +404,7 @@ module Labimotion
|
|
387
404
|
|
388
405
|
desc 'Update element by id'
|
389
406
|
params do
|
390
|
-
|
391
|
-
optional :name, type: String
|
392
|
-
requires :properties, type: Hash
|
393
|
-
optional :properties_release, type: Hash
|
394
|
-
requires :container, type: Hash
|
395
|
-
optional :segments, type: Array, desc: 'Segments'
|
407
|
+
use :update_element_params
|
396
408
|
end
|
397
409
|
route_param :id do
|
398
410
|
before do
|
@@ -414,20 +426,7 @@ module Labimotion
|
|
414
426
|
raise e
|
415
427
|
end
|
416
428
|
end
|
417
|
-
end
|
418
|
-
|
419
|
-
namespace :split do
|
420
|
-
desc 'split elements'
|
421
|
-
params do
|
422
|
-
requires :ui_state, type: Hash, desc: 'Selected elements from the UI'
|
423
|
-
end
|
424
|
-
post do
|
425
|
-
split_elements(params[:ui_state], current_user)
|
426
|
-
rescue StandardError => e
|
427
|
-
Labimotion.log_exception(e, current_user)
|
428
|
-
{ error: e.message }
|
429
|
-
end
|
430
|
-
end
|
429
|
+
end
|
431
430
|
end
|
432
431
|
end
|
433
432
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'labimotion/version'
|
4
|
+
require 'labimotion/libs/export_element'
|
5
|
+
|
6
|
+
module Labimotion
|
7
|
+
# Generic Element API
|
8
|
+
class GenericKlassAPI < Grape::API
|
9
|
+
|
10
|
+
resource :generic_klass do
|
11
|
+
namespace :download_klass do
|
12
|
+
desc 'export klass'
|
13
|
+
params do
|
14
|
+
requires :id, type: Integer, desc: 'element id'
|
15
|
+
requires :klass, type: String, desc: 'Klass', values: %w[ElementKlass SegmentKlass DatasetKlass]
|
16
|
+
end
|
17
|
+
get do
|
18
|
+
entity = "Labimotion::#{params[:klass]}".constantize.find_by(id: params[:id])
|
19
|
+
entity.update_columns(identifier: SecureRandom.uuid) if entity&.identifier.nil?
|
20
|
+
env['api.format'] = :binary
|
21
|
+
content_type('application/json')
|
22
|
+
filename = URI.escape("LabIMotion_#{params[:klass]}_#{entity.label}-#{Time.new.strftime("%Y%m%d%H%M%S")}.json")
|
23
|
+
# header['Content-Disposition'] = "attachment; filename=abc.docx"
|
24
|
+
header('Content-Disposition', "attachment; filename=\"#{filename}\"")
|
25
|
+
"Labimotion::#{params[:klass]}Entity".constantize.represent(entity)
|
26
|
+
# klass.as_json
|
27
|
+
rescue StandardError => e
|
28
|
+
Labimotion.log_exception(e, current_user)
|
29
|
+
{}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -3,6 +3,7 @@ module Labimotion
|
|
3
3
|
include Grape::Kaminari
|
4
4
|
helpers Labimotion::GenericHelpers
|
5
5
|
helpers Labimotion::SegmentHelpers
|
6
|
+
helpers Labimotion::ParamHelpers
|
6
7
|
|
7
8
|
resource :segments do
|
8
9
|
namespace :klasses do
|
@@ -30,11 +31,7 @@ module Labimotion
|
|
30
31
|
namespace :create_segment_klass do
|
31
32
|
desc 'create Generic Segment Klass'
|
32
33
|
params do
|
33
|
-
|
34
|
-
requires :element_klass, type: Integer, desc: 'Element Klass Id'
|
35
|
-
optional :desc, type: String, desc: 'Segment Klass Desc'
|
36
|
-
optional :place, type: String, desc: 'Segment Klass Place', default: '100'
|
37
|
-
optional :properties_template, type: Hash, desc: 'Element Klass properties template'
|
34
|
+
use :create_segment_klass_params
|
38
35
|
end
|
39
36
|
after_validation do
|
40
37
|
authenticate_admin!('segments')
|
@@ -50,11 +47,7 @@ module Labimotion
|
|
50
47
|
namespace :update_segment_klass do
|
51
48
|
desc 'update Generic Segment Klass'
|
52
49
|
params do
|
53
|
-
|
54
|
-
optional :label, type: String, desc: 'Segment Klass Label'
|
55
|
-
optional :desc, type: String, desc: 'Segment Klass Desc'
|
56
|
-
optional :place, type: String, desc: 'Segment Klass Place', default: '100'
|
57
|
-
optional :identifier, type: String, desc: 'Segment Identifier'
|
50
|
+
use :update_segment_klass_params
|
58
51
|
end
|
59
52
|
after_validation do
|
60
53
|
authenticate_admin!('segments')
|
@@ -140,6 +133,28 @@ module Labimotion
|
|
140
133
|
raise e
|
141
134
|
end
|
142
135
|
end
|
136
|
+
|
137
|
+
namespace :upload_klass do
|
138
|
+
desc 'upload Generic Klass'
|
139
|
+
params do
|
140
|
+
use :upload_segment_klass_params
|
141
|
+
end
|
142
|
+
post do
|
143
|
+
declared_params = declared(params, include_missing: false)
|
144
|
+
attributes = declared_params.merge(
|
145
|
+
created_by: current_user.id,
|
146
|
+
released_by: current_user.id,
|
147
|
+
updated_by: current_user.id,
|
148
|
+
is_active: false
|
149
|
+
)
|
150
|
+
attr_klass = params['element_klass'] || {}
|
151
|
+
attributes.delete(:element_klass)
|
152
|
+
validate_klass(attributes, attr_klass)
|
153
|
+
rescue StandardError => e
|
154
|
+
Labimotion.log_exception(e, current_user)
|
155
|
+
raise e
|
156
|
+
end
|
157
|
+
end
|
143
158
|
end
|
144
159
|
end
|
145
160
|
end
|
@@ -176,11 +176,6 @@ module Labimotion
|
|
176
176
|
)
|
177
177
|
end
|
178
178
|
(attach_ary << att_ary).flatten! unless att_ary&.empty?
|
179
|
-
|
180
|
-
if Labimotion::IS_RAILS5 == true
|
181
|
-
TransferThumbnailToPublicJob.set(queue: "transfer_thumbnail_to_public_#{current_user.id}").perform_now(attach_ary) unless attach_ary.empty?
|
182
|
-
TransferFileFromTmpJob.set(queue: "transfer_file_from_tmp_#{current_user.id}").perform_now(attach_ary) unless attach_ary.empty?
|
183
|
-
end
|
184
179
|
true
|
185
180
|
rescue StandardError => e
|
186
181
|
Labimotion.log_exception(e, current_user)
|
@@ -299,37 +294,44 @@ module Labimotion
|
|
299
294
|
raise e
|
300
295
|
end
|
301
296
|
|
302
|
-
def
|
303
|
-
response = Labimotion::TemplateHub.fetch_identifier('ElementKlass', params[:identifier], origin)
|
304
|
-
attributes = response.slice('name', 'label', 'desc', 'icon_name', 'uuid', 'klass_prefix', 'is_generic', 'identifier', 'properties_release', 'version')
|
305
|
-
attributes['properties_release']['identifier'] = attributes['identifier']
|
306
|
-
attributes['properties_template'] = attributes['properties_release']
|
307
|
-
attributes['place'] = ((Labimotion::DatasetKlass.all.length * 10) || 0) + 10
|
308
|
-
attributes['is_active'] = false
|
309
|
-
attributes['updated_by'] = current_user.id
|
310
|
-
attributes['sync_by'] = current_user.id
|
311
|
-
attributes['sync_time'] = DateTime.now
|
312
|
-
|
297
|
+
def validate_klass(attributes)
|
313
298
|
element_klass = Labimotion::ElementKlass.find_by(identifier: attributes['identifier'])
|
314
299
|
if element_klass.present?
|
315
300
|
if element_klass['uuid'] == attributes['uuid'] && element_klass['version'] == attributes['version']
|
316
|
-
{ status: 'success', message: "This element: #{attributes['name']} has the latest version!" }
|
301
|
+
return { status: 'success', message: "This element: #{attributes['name']} has the latest version!" }
|
317
302
|
else
|
318
303
|
element_klass.update!(attributes)
|
319
304
|
element_klass.create_klasses_revision(current_user)
|
320
|
-
{ status: 'success', message: "This element: [#{attributes['name']}] has been upgraded to the version: #{attributes['version']}!" }
|
305
|
+
return { status: 'success', message: "This element: [#{attributes['name']}] has been upgraded to the version: #{attributes['version']}!" }
|
321
306
|
end
|
322
307
|
else
|
323
308
|
exist_klass = Labimotion::ElementKlass.find_by(name: attributes['name'])
|
324
309
|
if exist_klass.present?
|
325
|
-
{ status: 'error', message: "The name [#{attributes['name']}] is already in use." }
|
310
|
+
return { status: 'error', message: "The name [#{attributes['name']}] is already in use." }
|
326
311
|
else
|
327
312
|
attributes['created_by'] = current_user.id
|
328
313
|
element_klass = Labimotion::ElementKlass.create!(attributes)
|
329
314
|
element_klass.create_klasses_revision(current_user)
|
330
|
-
{ status: 'success', message: "The element: #{attributes['name']} has been created using version: #{attributes['version']}!" }
|
315
|
+
return { status: 'success', message: "The element: #{attributes['name']} has been created using version: #{attributes['version']}!" }
|
331
316
|
end
|
332
317
|
end
|
318
|
+
|
319
|
+
rescue StandardError => e
|
320
|
+
Labimotion.log_exception(e, current_user)
|
321
|
+
return { status: 'error', message: e.message }
|
322
|
+
end
|
323
|
+
|
324
|
+
def create_repo_klass(params, current_user, origin)
|
325
|
+
response = Labimotion::TemplateHub.fetch_identifier('ElementKlass', params[:identifier], origin)
|
326
|
+
attributes = response.slice('name', 'label', 'desc', 'icon_name', 'uuid', 'klass_prefix', 'is_generic', 'identifier', 'properties_release', 'version')
|
327
|
+
attributes['properties_release']['identifier'] = attributes['identifier']
|
328
|
+
attributes['properties_template'] = attributes['properties_release']
|
329
|
+
attributes['place'] = ((Labimotion::ElementKlass.all.length * 10) || 0) + 10
|
330
|
+
attributes['is_active'] = false
|
331
|
+
attributes['updated_by'] = current_user.id
|
332
|
+
attributes['sync_by'] = current_user.id
|
333
|
+
attributes['sync_time'] = DateTime.now
|
334
|
+
validate_klass(attributes)
|
333
335
|
rescue StandardError => e
|
334
336
|
Labimotion.log_exception(e, current_user)
|
335
337
|
# { error: e.message }
|
@@ -0,0 +1,97 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'grape'
|
3
|
+
require 'labimotion/utils/utils'
|
4
|
+
# Helper for associated sample
|
5
|
+
module Labimotion
|
6
|
+
## Generic Helpers
|
7
|
+
module ParamHelpers
|
8
|
+
extend Grape::API::Helpers
|
9
|
+
## Element Klass Params
|
10
|
+
params :upload_element_klass_params do
|
11
|
+
requires :name, type: String, desc: 'Klass Name'
|
12
|
+
optional :label, type: String, desc: 'Klass label'
|
13
|
+
optional :desc, type: String, desc: 'Klass desc'
|
14
|
+
optional :klass_prefix, type: String, desc: 'Klass klass_prefix'
|
15
|
+
optional :icon_name, type: String, desc: 'Klass icon_name'
|
16
|
+
requires :properties_template, type: Hash, desc: 'Klass template'
|
17
|
+
optional :properties_release, type: Hash, desc: 'Klass release'
|
18
|
+
optional :released_at, type: DateTime, desc: 'Klass released_at'
|
19
|
+
requires :uuid, type: String, desc: 'Klass uuid'
|
20
|
+
requires :place, type: Integer, desc: 'Klass place'
|
21
|
+
requires :identifier, type: String, desc: 'Klass identifier'
|
22
|
+
optional :sync_time, type: DateTime, desc: 'Klass sync_time'
|
23
|
+
optional :version, type: String, desc: 'Klass version'
|
24
|
+
end
|
25
|
+
|
26
|
+
params :create_element_klass_params do
|
27
|
+
requires :name, type: String, desc: 'Element Klass Name'
|
28
|
+
requires :label, type: String, desc: 'Element Klass Label'
|
29
|
+
requires :klass_prefix, type: String, desc: 'Element Klass Short Label Prefix'
|
30
|
+
optional :icon_name, type: String, desc: 'Element Klass Icon Name'
|
31
|
+
optional :desc, type: String, desc: 'Element Klass Desc'
|
32
|
+
optional :properties_template, type: Hash, desc: 'Element Klass properties template'
|
33
|
+
end
|
34
|
+
|
35
|
+
params :update_element_klass_params do
|
36
|
+
requires :id, type: Integer, desc: 'Element Klass ID'
|
37
|
+
optional :label, type: String, desc: 'Element Klass Label'
|
38
|
+
optional :klass_prefix, type: String, desc: 'Element Klass Short Label Prefix'
|
39
|
+
optional :icon_name, type: String, desc: 'Element Klass Icon Name'
|
40
|
+
optional :desc, type: String, desc: 'Element Klass Desc'
|
41
|
+
optional :place, type: String, desc: 'Element Klass Place'
|
42
|
+
end
|
43
|
+
|
44
|
+
## Element Params
|
45
|
+
params :create_element_params do
|
46
|
+
requires :element_klass, type: Hash
|
47
|
+
requires :name, type: String
|
48
|
+
optional :properties, type: Hash
|
49
|
+
optional :properties_release, type: Hash
|
50
|
+
optional :collection_id, type: Integer
|
51
|
+
requires :container, type: Hash
|
52
|
+
optional :segments, type: Array, desc: 'Segments'
|
53
|
+
end
|
54
|
+
|
55
|
+
params :update_element_params do
|
56
|
+
requires :id, type: Integer, desc: 'element id'
|
57
|
+
optional :name, type: String
|
58
|
+
requires :properties, type: Hash
|
59
|
+
optional :properties_release, type: Hash
|
60
|
+
requires :container, type: Hash
|
61
|
+
optional :segments, type: Array, desc: 'Segments'
|
62
|
+
end
|
63
|
+
|
64
|
+
## Segment Klass Params
|
65
|
+
params :upload_segment_klass_params do
|
66
|
+
requires :label, type: String, desc: 'Klass label'
|
67
|
+
optional :desc, type: String, desc: 'Klass desc'
|
68
|
+
requires :properties_template, type: Hash, desc: 'Klass template'
|
69
|
+
optional :properties_release, type: Hash, desc: 'Klass release'
|
70
|
+
optional :released_at, type: DateTime, desc: 'Klass released_at'
|
71
|
+
requires :uuid, type: String, desc: 'Klass uuid'
|
72
|
+
requires :place, type: Integer, desc: 'Klass place'
|
73
|
+
requires :identifier, type: String, desc: 'Klass identifier'
|
74
|
+
optional :sync_time, type: DateTime, desc: 'Klass sync_time'
|
75
|
+
optional :version, type: String, desc: 'Klass version'
|
76
|
+
requires :element_klass, type: Hash do
|
77
|
+
use :upload_element_klass_params
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
params :update_segment_klass_params do
|
82
|
+
requires :id, type: Integer, desc: 'Segment Klass ID'
|
83
|
+
optional :label, type: String, desc: 'Segment Klass Label'
|
84
|
+
optional :desc, type: String, desc: 'Segment Klass Desc'
|
85
|
+
optional :place, type: String, desc: 'Segment Klass Place', default: '100'
|
86
|
+
optional :identifier, type: String, desc: 'Segment Identifier'
|
87
|
+
end
|
88
|
+
|
89
|
+
params :create_segment_klass_params do
|
90
|
+
requires :label, type: String, desc: 'Segment Klass Label'
|
91
|
+
requires :element_klass, type: Integer, desc: 'Element Klass Id'
|
92
|
+
optional :desc, type: String, desc: 'Segment Klass Desc'
|
93
|
+
optional :place, type: String, desc: 'Segment Klass Place', default: '100'
|
94
|
+
optional :properties_template, type: Hash, desc: 'Element Klass properties template'
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -63,45 +63,53 @@ module Labimotion
|
|
63
63
|
raise e
|
64
64
|
end
|
65
65
|
|
66
|
-
def
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
attributes['properties_template'] = attributes['properties_release']
|
71
|
-
attributes['place'] = ((Labimotion::SegmentKlass.all.length * 10) || 0) + 10
|
72
|
-
attributes['is_active'] = false
|
73
|
-
attributes['updated_by'] = current_user.id
|
74
|
-
attributes['sync_by'] = current_user.id
|
75
|
-
attributes['sync_time'] = DateTime.now
|
76
|
-
element_klass = Labimotion::ElementKlass.find_by(identifier: response['element_klass']['identifier']) if response.dig('element_klass','identifier').present?
|
77
|
-
element_klass = Labimotion::ElementKlass.find_by(name: response['element_klass']['name'], is_generic: false) if element_klass.nil?
|
78
|
-
return { status: 'error', message: "The element [#{response['element_klass']['name']}] does not exist in this instance" } if element_klass.nil?
|
66
|
+
def validate_klass(attributes, attr_klass)
|
67
|
+
element_klass = Labimotion::ElementKlass.find_by(identifier: attr_klass['identifier']) if attr_klass.dig('identifier').present?
|
68
|
+
element_klass = Labimotion::ElementKlass.find_by(name: attr_klass['name'], is_generic: false) if element_klass.nil?
|
69
|
+
return { status: 'error', message: "The element [#{attr_klass['name']}] does not exist in this instance" } if element_klass.nil?
|
79
70
|
|
80
71
|
# el_attributes = response['element_klass'].slice('name', 'label', 'desc', 'uuid', 'identifier', 'icon_name', 'klass_prefix', 'is_generic', 'released_at')
|
81
72
|
# el_attributes['properties_template'] = response['element_klass']['properties_release']
|
82
73
|
# Labimotion::ElementKlass.create!(el_attributes)
|
83
|
-
|
84
74
|
attributes['element_klass_id'] = element_klass.id
|
85
75
|
segment_klass = Labimotion::SegmentKlass.find_by(identifier: attributes['identifier'])
|
86
76
|
if segment_klass.present?
|
87
77
|
if segment_klass['uuid'] == attributes['uuid'] && segment_klass['version'] == attributes['version']
|
88
|
-
{ status: 'success', message: "This segment: #{attributes['label']} has the latest version!" }
|
78
|
+
return { status: 'success', message: "This segment: #{attributes['label']} has the latest version!" }
|
89
79
|
else
|
90
80
|
segment_klass.update!(attributes)
|
91
81
|
segment_klass.create_klasses_revision(current_user)
|
92
|
-
{ status: 'success', message: "This segment: [#{attributes['label']}] has been upgraded to the version: #{attributes['version']}!" }
|
82
|
+
return { status: 'success', message: "This segment: [#{attributes['label']}] has been upgraded to the version: #{attributes['version']}!" }
|
93
83
|
end
|
94
84
|
else
|
95
85
|
exist_klass = Labimotion::SegmentKlass.find_by(label: attributes['label'], element_klass_id: element_klass.id)
|
96
86
|
if exist_klass.present?
|
97
|
-
{ status: 'error', message: "The segment [#{attributes['label']}] is already in use." }
|
87
|
+
return { status: 'error', message: "The segment [#{attributes['label']}] is already in use." }
|
98
88
|
else
|
99
89
|
attributes['created_by'] = current_user.id
|
100
90
|
segment_klass = Labimotion::SegmentKlass.create!(attributes)
|
101
91
|
segment_klass.create_klasses_revision(current_user)
|
102
|
-
{ status: 'success', message: "The segment: #{attributes['label']} has been created using version: #{attributes['version']}!" }
|
92
|
+
return { status: 'success', message: "The segment: #{attributes['label']} has been created using version: #{attributes['version']}!" }
|
103
93
|
end
|
104
94
|
end
|
95
|
+
rescue StandardError => e
|
96
|
+
Labimotion.log_exception(e, current_user)
|
97
|
+
return { status: 'error', message: e.message }
|
98
|
+
end
|
99
|
+
|
100
|
+
def create_repo_klass(params, current_user, origin)
|
101
|
+
response = Labimotion::TemplateHub.fetch_identifier('SegmentKlass', params[:identifier], origin)
|
102
|
+
attributes = response.slice('label', 'desc', 'uuid', 'identifier', 'released_at', 'properties_release', 'version')
|
103
|
+
attributes['properties_release']['identifier'] = attributes['identifier']
|
104
|
+
attributes['properties_template'] = attributes['properties_release']
|
105
|
+
attributes['place'] = ((Labimotion::SegmentKlass.all.length * 10) || 0) + 10
|
106
|
+
attributes['is_active'] = false
|
107
|
+
attributes['updated_by'] = current_user.id
|
108
|
+
attributes['sync_by'] = current_user.id
|
109
|
+
attributes['sync_time'] = DateTime.now
|
110
|
+
attr_klass = response.dig('element_klass', {}) # response['element_klass']
|
111
|
+
validate_klass(attributes, attr_klass)
|
112
|
+
|
105
113
|
rescue StandardError => e
|
106
114
|
Labimotion.log_exception(e, current_user)
|
107
115
|
raise e
|
@@ -27,18 +27,10 @@ module Labimotion
|
|
27
27
|
|
28
28
|
dsr = []
|
29
29
|
ols = nil
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
dsr.push(res[:d]) unless res&.dig(:d).nil?
|
35
|
-
end
|
36
|
-
else
|
37
|
-
Zip::File.open(att.attachment_attacher.file.url) do |zip_file|
|
38
|
-
res = Labimotion::Converter.collect_metadata(zip_file) if att.filename.split('.')&.last == 'zip'
|
39
|
-
ols = res[:o] unless res&.dig(:o).nil?
|
40
|
-
dsr.push(res[:d]) unless res&.dig(:d).nil?
|
41
|
-
end
|
30
|
+
Zip::File.open(att.attachment_attacher.file.url) do |zip_file|
|
31
|
+
res = Labimotion::Converter.collect_metadata(zip_file) if att.filename.split('.')&.last == 'zip'
|
32
|
+
ols = res[:o] unless res&.dig(:o).nil?
|
33
|
+
dsr.push(res[:d]) unless res&.dig(:d).nil?
|
42
34
|
end
|
43
35
|
dsr.flatten!
|
44
36
|
dataset = build_ds(att.attachable_id, ols)
|
@@ -145,16 +137,9 @@ module Labimotion
|
|
145
137
|
created_by: oat.created_by,
|
146
138
|
created_for: oat.created_for,
|
147
139
|
)
|
148
|
-
|
149
|
-
if att.valid?
|
150
|
-
|
151
|
-
att.save!
|
152
|
-
end
|
153
|
-
if att.valid? && Labimotion::IS_RAILS5 == true
|
154
|
-
att.save!
|
155
|
-
primary_store = Rails.configuration.storage.primary_store
|
156
|
-
att.update!(storage: primary_store)
|
157
|
-
end
|
140
|
+
|
141
|
+
att.save! if att.valid?
|
142
|
+
|
158
143
|
process_ds(att.id)
|
159
144
|
rescue StandardError => e
|
160
145
|
raise e
|
@@ -168,11 +153,7 @@ module Labimotion
|
|
168
153
|
response = nil
|
169
154
|
begin
|
170
155
|
ofile = Rails.root.join(data[:f], data[:a].filename)
|
171
|
-
|
172
|
-
FileUtils.cp(data[:a].store.path, ofile)
|
173
|
-
else
|
174
|
-
FileUtils.cp(data[:a].attachment_url, ofile)
|
175
|
-
end
|
156
|
+
FileUtils.cp(data[:a].attachment_url, ofile)
|
176
157
|
|
177
158
|
File.open(ofile, 'r') do |f|
|
178
159
|
body = { file: f }
|
@@ -145,18 +145,9 @@ module Labimotion
|
|
145
145
|
sheet_name = "Sheet#{idx+1}"
|
146
146
|
sheet = @xfile.workbook.add_worksheet(name: sheet_name)
|
147
147
|
name_mapping.push([sheet_name, att.filename])
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
fi.each_line do |line|
|
152
|
-
sheet.add_row(line.split(','))
|
153
|
-
end
|
154
|
-
end
|
155
|
-
else
|
156
|
-
File.open(att.attachment_url) do |fi|
|
157
|
-
fi.each_line do |line|
|
158
|
-
sheet.add_row(line.split(','))
|
159
|
-
end
|
148
|
+
File.open(att.attachment_url) do |fi|
|
149
|
+
fi.each_line do |line|
|
150
|
+
sheet.add_row(line.split(','))
|
160
151
|
end
|
161
152
|
end
|
162
153
|
end
|