labimotion 0.1.14 → 0.1.16
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_dataset_api.rb +4 -3
- data/lib/labimotion/apis/generic_element_api.rb +11 -3
- data/lib/labimotion/apis/segment_api.rb +4 -3
- data/lib/labimotion/helpers/dataset_helpers.rb +14 -6
- data/lib/labimotion/helpers/element_helpers.rb +21 -9
- data/lib/labimotion/helpers/generic_helpers.rb +9 -8
- data/lib/labimotion/helpers/segment_helpers.rb +20 -8
- data/lib/labimotion/libs/template_hub.rb +8 -4
- data/lib/labimotion/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 95752e2c3001d5de57f899a05dc5e348611cd3408a7fe1a1448ee426edf56437
|
|
4
|
+
data.tar.gz: b8715b44806c7586c71c05534e83147ec33a0648f771bd3867b0212440cdaa69
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 45faeec9d12b78dec9838b47ac863f4492ae1808f84e4777f38d9a3137e60b74c238827ceff45639a003535906e6ec9a339d669cbc935eba62bbcb0e1157533f
|
|
7
|
+
data.tar.gz: a19c0cd0422952d57e1151ffe87ddc032e1e18f2029ab860284a094f6ad5d645665771f7705dd7a39bfd139d524ab67a0635c936f1a46f981f55ef16b7188ed1
|
|
@@ -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 }
|
|
@@ -23,6 +23,7 @@ module Labimotion
|
|
|
23
23
|
present ek, with: Labimotion::ElementKlassEntity, root: 'klass'
|
|
24
24
|
rescue StandardError => e
|
|
25
25
|
Labimotion.log_exception(e, current_user)
|
|
26
|
+
{ klass: [] }
|
|
26
27
|
end
|
|
27
28
|
end
|
|
28
29
|
|
|
@@ -36,6 +37,7 @@ module Labimotion
|
|
|
36
37
|
present list, with: Labimotion::ElementKlassEntity, root: 'klass'
|
|
37
38
|
rescue StandardError => e
|
|
38
39
|
Labimotion.log_exception(e, current_user)
|
|
40
|
+
{ klass: [] }
|
|
39
41
|
end
|
|
40
42
|
end
|
|
41
43
|
|
|
@@ -176,6 +178,7 @@ module Labimotion
|
|
|
176
178
|
true
|
|
177
179
|
rescue StandardError => e
|
|
178
180
|
Labimotion.log_exception(e, current_user)
|
|
181
|
+
raise e
|
|
179
182
|
end
|
|
180
183
|
end
|
|
181
184
|
|
|
@@ -193,7 +196,10 @@ module Labimotion
|
|
|
193
196
|
namespace :fetch_repo do
|
|
194
197
|
desc 'fetch Generic Element Klass from Chemotion Repository'
|
|
195
198
|
get do
|
|
196
|
-
fetch_repo('ElementKlass')
|
|
199
|
+
fetch_repo('ElementKlass', current_user)
|
|
200
|
+
rescue StandardError => e
|
|
201
|
+
Labimotion.log_exception(e, current_user)
|
|
202
|
+
[]
|
|
197
203
|
end
|
|
198
204
|
end
|
|
199
205
|
|
|
@@ -203,8 +209,9 @@ module Labimotion
|
|
|
203
209
|
requires :identifier, type: String, desc: 'Identifier'
|
|
204
210
|
end
|
|
205
211
|
post do
|
|
206
|
-
create_repo_klass(params, current_user)
|
|
207
|
-
|
|
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 }
|
|
208
215
|
rescue StandardError => e
|
|
209
216
|
Labimotion.log_exception(e, current_user)
|
|
210
217
|
{ error: e.message }
|
|
@@ -226,6 +233,7 @@ module Labimotion
|
|
|
226
233
|
deactivate_klass(params)
|
|
227
234
|
rescue StandardError => e
|
|
228
235
|
Labimotion.log_exception(e, current_user)
|
|
236
|
+
raise e
|
|
229
237
|
end
|
|
230
238
|
end
|
|
231
239
|
|
|
@@ -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 }
|
|
@@ -13,8 +13,8 @@ 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
19
|
attributes['properties_release']['identifier'] = attributes['identifier']
|
|
20
20
|
attributes['properties_template'] = attributes['properties_release']
|
|
@@ -23,14 +23,22 @@ module Labimotion
|
|
|
23
23
|
attributes['updated_by'] = current_user.id
|
|
24
24
|
attributes['sync_by'] = current_user.id
|
|
25
25
|
attributes['sync_time'] = DateTime.now
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
|
29
36
|
else
|
|
30
37
|
attributes['created_by'] = current_user.id
|
|
31
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']}!" }
|
|
32
41
|
end
|
|
33
|
-
ds.create_klasses_revision(current_user)
|
|
34
42
|
rescue StandardError => e
|
|
35
43
|
Labimotion.log_exception(e, current_user)
|
|
36
44
|
# { error: e.message }
|
|
@@ -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}").
|
|
172
|
-
TransferFileFromTmpJob.set(queue: "transfer_file_from_tmp_#{current_user.id}").
|
|
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
|
|
@@ -289,9 +289,9 @@ module Labimotion
|
|
|
289
289
|
raise e
|
|
290
290
|
end
|
|
291
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')
|
|
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
295
|
attributes['properties_release']['identifier'] = attributes['identifier']
|
|
296
296
|
attributes['properties_template'] = attributes['properties_release']
|
|
297
297
|
attributes['place'] = ((Labimotion::DatasetKlass.all.length * 10) || 0) + 10
|
|
@@ -302,12 +302,24 @@ module Labimotion
|
|
|
302
302
|
|
|
303
303
|
element_klass = Labimotion::ElementKlass.find_by(identifier: attributes['identifier'])
|
|
304
304
|
if element_klass.present?
|
|
305
|
-
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
|
|
306
312
|
else
|
|
307
|
-
attributes['
|
|
308
|
-
|
|
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
|
|
309
322
|
end
|
|
310
|
-
element_klass.create_klasses_revision(current_user)
|
|
311
323
|
rescue StandardError => e
|
|
312
324
|
Labimotion.log_exception(e, current_user)
|
|
313
325
|
# { error: e.message }
|
|
@@ -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' }
|
|
@@ -63,8 +63,8 @@ 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])
|
|
66
|
+
def create_repo_klass(params, current_user, origin)
|
|
67
|
+
response = Labimotion::TemplateHub.fetch_identifier('SegmentKlass', params[:identifier], origin)
|
|
68
68
|
attributes = response.slice('label', 'desc', 'uuid', 'identifier', 'released_at', 'properties_release', 'version')
|
|
69
69
|
attributes['properties_release']['identifier'] = attributes['identifier']
|
|
70
70
|
attributes['properties_template'] = attributes['properties_release']
|
|
@@ -75,8 +75,8 @@ module Labimotion
|
|
|
75
75
|
attributes['sync_time'] = DateTime.now
|
|
76
76
|
|
|
77
77
|
element_klass = Labimotion::ElementKlass.find_by(identifier: response['element_klass']['identifier'])
|
|
78
|
-
element_klass = Labimotion::ElementKlass.find_by(name: response['element_klass']['name']) if element_klass.nil?
|
|
79
|
-
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?
|
|
80
80
|
|
|
81
81
|
# el_attributes = response['element_klass'].slice('name', 'label', 'desc', 'uuid', 'identifier', 'icon_name', 'klass_prefix', 'is_generic', 'released_at')
|
|
82
82
|
# el_attributes['properties_template'] = response['element_klass']['properties_release']
|
|
@@ -85,12 +85,24 @@ module Labimotion
|
|
|
85
85
|
attributes['element_klass_id'] = element_klass.id
|
|
86
86
|
segment_klass = Labimotion::SegmentKlass.find_by(identifier: attributes['identifier'])
|
|
87
87
|
if segment_klass.present?
|
|
88
|
-
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
|
|
89
95
|
else
|
|
90
|
-
attributes['
|
|
91
|
-
|
|
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
|
|
92
105
|
end
|
|
93
|
-
segment_klass.create_klasses_revision(current_user)
|
|
94
106
|
rescue StandardError => e
|
|
95
107
|
Labimotion.log_exception(e, current_user)
|
|
96
108
|
raise e
|
|
@@ -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)
|
data/lib/labimotion/version.rb
CHANGED