labimotion 0.3.3 → 1.0.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/api.rb +19 -0
- data/lib/labimotion/apis/generic_dataset_api.rb +3 -4
- data/lib/labimotion/apis/generic_element_api.rb +8 -56
- data/lib/labimotion/apis/labimotion_hub_api.rb +4 -13
- data/lib/labimotion/apis/segment_api.rb +3 -4
- data/lib/labimotion/entities/element_entity.rb +0 -1
- data/lib/labimotion/entities/generic_public_entity.rb +0 -2
- data/lib/labimotion/helpers/dataset_helpers.rb +6 -14
- data/lib/labimotion/helpers/element_helpers.rb +10 -30
- data/lib/labimotion/helpers/generic_helpers.rb +13 -13
- data/lib/labimotion/helpers/segment_helpers.rb +8 -20
- data/lib/labimotion/libs/converter.rb +27 -53
- data/lib/labimotion/libs/export_dataset.rb +3 -8
- data/lib/labimotion/libs/nmr_mapper.rb +15 -39
- data/lib/labimotion/libs/nmr_mapper_repo.rb +278 -0
- data/lib/labimotion/libs/template_hub.rb +4 -8
- data/lib/labimotion/models/concerns/attachment_converter.rb +9 -10
- data/lib/labimotion/models/concerns/datasetable.rb +1 -1
- data/lib/labimotion/models/concerns/segmentable.rb +4 -3
- data/lib/labimotion/models/concerns/workflow.rb +0 -9
- data/lib/labimotion/models/element.rb +8 -17
- data/lib/labimotion/models/element_klass.rb +8 -0
- data/lib/labimotion/models/segment_klass.rb +0 -2
- data/lib/labimotion/{collection → utils}/export.rb +1 -32
- data/lib/labimotion/{collection → utils}/import.rb +71 -53
- data/lib/labimotion/version.rb +3 -7
- data/lib/labimotion.rb +2 -5
- metadata +10 -10
- data/lib/labimotion/models/hub_log.rb +0 -8
- data/lib/labimotion/utils/import_utils.rb +0 -116
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 387a4b4a47a140008970b10f005472e8ba882c80ddaab99863ced5acdb0dfa29
|
4
|
+
data.tar.gz: 90f5839a92d045e45861a2354354bf5ef1542799a484cda94fa9c1263c206d5e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cca4c43074754aefbe3f2b3ca09b55af69d25ebf2a4b7f456990bc692ee7ab19905020aed4505d6360b720d94e497e91ab5910b8c50d4b5b914a01d23e840796
|
7
|
+
data.tar.gz: 5280180e034e2bd2a38000b62e8001ebee247cae2dd29e30f5b66eb3292d11e0e9f0566986c5eb918e6f6dcfc9d95024553204d834da44e7a1aee2b13500d454
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
## This is the first version of the dataset class
|
4
|
+
module Labimotion
|
5
|
+
## This is the first version of the dataset class
|
6
|
+
class Api
|
7
|
+
def initialize
|
8
|
+
# Initialization code
|
9
|
+
end
|
10
|
+
|
11
|
+
def gget_data
|
12
|
+
'Hello, worlddddddddddddddddddddd!'
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.hello
|
16
|
+
'Hellooooooooooooooooooooo!'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -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')
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -40,9 +40,8 @@ module Labimotion
|
|
40
40
|
requires :identifier, type: String, desc: 'Identifier'
|
41
41
|
end
|
42
42
|
post do
|
43
|
-
|
44
|
-
|
45
|
-
{ status: msg[:status], message: msg[:message], klass: klass }
|
43
|
+
create_repo_klass(params, current_user)
|
44
|
+
present DatasetKlass.all, with: Labimotion::DatasetKlassEntity, root: 'klass'
|
46
45
|
rescue StandardError => e
|
47
46
|
Labimotion.log_exception(e, current_user)
|
48
47
|
{ error: e.message }
|
@@ -21,9 +21,6 @@ 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: [] }
|
27
24
|
end
|
28
25
|
end
|
29
26
|
|
@@ -35,9 +32,6 @@ module Labimotion
|
|
35
32
|
get do
|
36
33
|
list = klass_list(params[:generic_only])
|
37
34
|
present list, with: Labimotion::ElementKlassEntity, root: 'klass'
|
38
|
-
rescue StandardError => e
|
39
|
-
Labimotion.log_exception(e, current_user)
|
40
|
-
{ klass: [] }
|
41
35
|
end
|
42
36
|
end
|
43
37
|
|
@@ -73,9 +67,6 @@ module Labimotion
|
|
73
67
|
post do
|
74
68
|
authenticate_admin!('elements')
|
75
69
|
update_element_klass(current_user, params)
|
76
|
-
rescue StandardError => e
|
77
|
-
Labimotion.log_exception(e, current_user)
|
78
|
-
raise e
|
79
70
|
end
|
80
71
|
end
|
81
72
|
|
@@ -88,9 +79,6 @@ module Labimotion
|
|
88
79
|
get do
|
89
80
|
list = list_klass_revisions(params)
|
90
81
|
present list, with: Labimotion::KlassRevisionEntity, root: 'revisions'
|
91
|
-
rescue StandardError => e
|
92
|
-
Labimotion.log_exception(e, current_user)
|
93
|
-
[]
|
94
82
|
end
|
95
83
|
end
|
96
84
|
|
@@ -102,9 +90,6 @@ module Labimotion
|
|
102
90
|
get do
|
103
91
|
list = element_revisions(params)
|
104
92
|
present list, with: Labimotion::ElementRevisionEntity, root: 'revisions'
|
105
|
-
rescue StandardError => e
|
106
|
-
Labimotion.log_exception(e, current_user)
|
107
|
-
[]
|
108
93
|
end
|
109
94
|
end
|
110
95
|
|
@@ -119,9 +104,6 @@ module Labimotion
|
|
119
104
|
authenticate_admin!(params[:klass].gsub(/(Klass)/, 's').downcase)
|
120
105
|
delete_klass_revision(params)
|
121
106
|
status 201
|
122
|
-
rescue StandardError => e
|
123
|
-
Labimotion.log_exception(e, current_user)
|
124
|
-
raise e
|
125
107
|
end
|
126
108
|
end
|
127
109
|
|
@@ -135,9 +117,6 @@ module Labimotion
|
|
135
117
|
post do
|
136
118
|
delete_revision(params)
|
137
119
|
status 201
|
138
|
-
rescue StandardError => e
|
139
|
-
Labimotion.log_exception(e, current_user)
|
140
|
-
raise e
|
141
120
|
end
|
142
121
|
end
|
143
122
|
|
@@ -150,9 +129,6 @@ module Labimotion
|
|
150
129
|
klass = Labimotion::Segment.find(params[:id])
|
151
130
|
list = klass.segments_revisions unless klass.nil?
|
152
131
|
present list&.sort_by(&:created_at).reverse, with: Labimotion::SegmentRevisionEntity, root: 'revisions'
|
153
|
-
rescue StandardError => e
|
154
|
-
Labimotion.log_exception(e, current_user)
|
155
|
-
[]
|
156
132
|
end
|
157
133
|
end
|
158
134
|
|
@@ -176,9 +152,6 @@ module Labimotion
|
|
176
152
|
post do
|
177
153
|
upload_generics_files(current_user, params)
|
178
154
|
true
|
179
|
-
rescue StandardError => e
|
180
|
-
Labimotion.log_exception(e, current_user)
|
181
|
-
raise e
|
182
155
|
end
|
183
156
|
end
|
184
157
|
|
@@ -187,19 +160,13 @@ module Labimotion
|
|
187
160
|
get do
|
188
161
|
list = Labimotion::ElementKlass.all.sort_by { |e| e.place }
|
189
162
|
present list, with: Labimotion::ElementKlassEntity, root: 'klass'
|
190
|
-
rescue StandardError => e
|
191
|
-
Labimotion.log_exception(e, current_user)
|
192
|
-
[]
|
193
163
|
end
|
194
164
|
end
|
195
165
|
|
196
166
|
namespace :fetch_repo do
|
197
167
|
desc 'fetch Generic Element Klass from Chemotion Repository'
|
198
168
|
get do
|
199
|
-
fetch_repo('ElementKlass'
|
200
|
-
rescue StandardError => e
|
201
|
-
Labimotion.log_exception(e, current_user)
|
202
|
-
[]
|
169
|
+
fetch_repo('ElementKlass')
|
203
170
|
end
|
204
171
|
end
|
205
172
|
|
@@ -209,9 +176,8 @@ module Labimotion
|
|
209
176
|
requires :identifier, type: String, desc: 'Identifier'
|
210
177
|
end
|
211
178
|
post do
|
212
|
-
|
213
|
-
|
214
|
-
{ status: msg[:status], message: msg[:message], klass: klass }
|
179
|
+
create_repo_klass(params, current_user)
|
180
|
+
present ElementKlass.all, with: Labimotion::ElementKlassEntity, root: 'klass'
|
215
181
|
rescue StandardError => e
|
216
182
|
Labimotion.log_exception(e, current_user)
|
217
183
|
{ error: e.message }
|
@@ -231,9 +197,6 @@ module Labimotion
|
|
231
197
|
end
|
232
198
|
post do
|
233
199
|
deactivate_klass(params)
|
234
|
-
rescue StandardError => e
|
235
|
-
Labimotion.log_exception(e, current_user)
|
236
|
-
raise e
|
237
200
|
end
|
238
201
|
end
|
239
202
|
|
@@ -246,9 +209,6 @@ module Labimotion
|
|
246
209
|
delete ':id' do
|
247
210
|
delete_klass(params)
|
248
211
|
status 201
|
249
|
-
rescue StandardError => e
|
250
|
-
Labimotion.log_exception(e, current_user)
|
251
|
-
raise e
|
252
212
|
end
|
253
213
|
end
|
254
214
|
|
@@ -266,9 +226,6 @@ module Labimotion
|
|
266
226
|
end
|
267
227
|
post do
|
268
228
|
update_template(params, current_user)
|
269
|
-
rescue StandardError => e
|
270
|
-
Labimotion.log_exception(e, current_user)
|
271
|
-
raise e
|
272
229
|
end
|
273
230
|
end
|
274
231
|
|
@@ -299,9 +256,6 @@ module Labimotion
|
|
299
256
|
end
|
300
257
|
end
|
301
258
|
{ generic_elements: generic_elements }
|
302
|
-
rescue StandardError => e
|
303
|
-
Labimotion.log_exception(e, current_user)
|
304
|
-
{ generic_elements: [] }
|
305
259
|
end
|
306
260
|
|
307
261
|
desc 'Return serialized element by id'
|
@@ -318,7 +272,7 @@ module Labimotion
|
|
318
272
|
if Labimotion::IS_RAILS5 == true
|
319
273
|
{
|
320
274
|
element: ElementPermissionProxy.new(current_user, element, user_ids).serialized,
|
321
|
-
attachments:
|
275
|
+
attachments: Entities::AttachmentEntity.represent(element.attachments)
|
322
276
|
}
|
323
277
|
else
|
324
278
|
{
|
@@ -326,11 +280,9 @@ module Labimotion
|
|
326
280
|
element,
|
327
281
|
detail_levels: ElementDetailLevelCalculator.new(user: current_user, element: element).detail_levels,
|
328
282
|
),
|
329
|
-
attachments:
|
283
|
+
attachments: Entities::AttachmentEntity.represent(element.attachments),
|
330
284
|
}
|
331
285
|
end
|
332
|
-
rescue StandardError => e
|
333
|
-
Labimotion.log_exception(e, current_user)
|
334
286
|
end
|
335
287
|
end
|
336
288
|
|
@@ -350,7 +302,7 @@ module Labimotion
|
|
350
302
|
if Labimotion::IS_RAILS5 == true
|
351
303
|
{
|
352
304
|
element: ElementPermissionProxy.new(current_user, element, user_ids).serialized,
|
353
|
-
attachments:
|
305
|
+
attachments: Entities::AttachmentEntity.represent(element.attachments)
|
354
306
|
}
|
355
307
|
else
|
356
308
|
present(
|
@@ -386,7 +338,7 @@ module Labimotion
|
|
386
338
|
if Labimotion::IS_RAILS5 == true
|
387
339
|
{
|
388
340
|
element: ElementPermissionProxy.new(current_user, element, user_ids).serialized,
|
389
|
-
attachments:
|
341
|
+
attachments: Entities::AttachmentEntity.represent(element.attachments)
|
390
342
|
}
|
391
343
|
else
|
392
344
|
{
|
@@ -394,7 +346,7 @@ module Labimotion
|
|
394
346
|
element,
|
395
347
|
detail_levels: ElementDetailLevelCalculator.new(user: current_user, element: element).detail_levels,
|
396
348
|
),
|
397
|
-
attachments:
|
349
|
+
attachments: Entities::AttachmentEntity.represent(element.attachments),
|
398
350
|
}
|
399
351
|
end
|
400
352
|
rescue StandardError => e
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'open-uri'
|
4
|
-
require 'labimotion/models/hub_log'
|
5
4
|
|
6
5
|
# Belong to Chemotion module
|
7
6
|
module Labimotion
|
@@ -20,25 +19,20 @@ module Labimotion
|
|
20
19
|
list = "Labimotion::#{params[:klass]}".constantize.where(is_active: true).where.not(released_at: nil)
|
21
20
|
list = list.where(is_generic: true) if params[:klass] == 'ElementKlass'
|
22
21
|
entities = Labimotion::GenericPublicEntity.represent(list, displayed: params[:with_props])
|
23
|
-
|
24
|
-
Labimotion.log_exception(e, current_user)
|
25
|
-
[]
|
22
|
+
# entities.length > 1 ? de_encode_json(entities) : []
|
26
23
|
end
|
27
24
|
end
|
28
25
|
namespace :fetch do
|
29
26
|
desc "get active generic templates"
|
30
27
|
params do
|
31
28
|
requires :klass, type: String, desc: 'Klass', values: %w[ElementKlass SegmentKlass DatasetKlass]
|
32
|
-
requires :
|
29
|
+
# requires :fqdn, type: Integer, desc: 'FQDN'
|
33
30
|
requires :identifier, type: String, desc: 'Identifier'
|
34
31
|
end
|
35
|
-
|
32
|
+
get do
|
36
33
|
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)
|
38
34
|
"Labimotion::#{params[:klass]}Entity".constantize.represent(entity)
|
39
|
-
|
40
|
-
Labimotion.log_exception(e, current_user)
|
41
|
-
raise e
|
35
|
+
# entities.length > 1 ? de_encode_json(entities) : []
|
42
36
|
end
|
43
37
|
end
|
44
38
|
|
@@ -51,9 +45,6 @@ module Labimotion
|
|
51
45
|
list = Labimotion::ElementKlass.where(is_active: true) if params[:generic_only].present? && params[:generic_only] == true
|
52
46
|
list = Labimotion::ElementKlass.where(is_active: true) unless params[:generic_only].present? && params[:generic_only] == true
|
53
47
|
list.pluck(:name)
|
54
|
-
rescue StandardError => e
|
55
|
-
Labimotion.log_exception(e, current_user)
|
56
|
-
[]
|
57
48
|
end
|
58
49
|
end
|
59
50
|
|
@@ -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')
|
122
122
|
rescue StandardError => e
|
123
123
|
Labimotion.log_exception(e, current_user)
|
124
124
|
{ error: e.message }
|
@@ -131,9 +131,8 @@ module Labimotion
|
|
131
131
|
requires :identifier, type: String, desc: 'Identifier'
|
132
132
|
end
|
133
133
|
post do
|
134
|
-
|
135
|
-
|
136
|
-
{ status: msg[:status], message: msg[:message], klass: klass }
|
134
|
+
create_repo_klass(params, current_user)
|
135
|
+
present SegmentKlass.all, with: Labimotion::SegmentKlassEntity, root: 'klass'
|
137
136
|
rescue StandardError => e
|
138
137
|
Labimotion.log_exception(e, current_user)
|
139
138
|
## { error: e.message }
|
@@ -5,7 +5,6 @@ require 'labimotion/entities/application_entity'
|
|
5
5
|
# Entity module
|
6
6
|
module Labimotion
|
7
7
|
class GenericPublicEntity < Labimotion::ApplicationEntity
|
8
|
-
expose! :uuid
|
9
8
|
expose! :name
|
10
9
|
expose! :desc
|
11
10
|
expose! :icon_name
|
@@ -13,7 +12,6 @@ module Labimotion
|
|
13
12
|
expose! :klass_name
|
14
13
|
expose! :label
|
15
14
|
expose! :identifier
|
16
|
-
expose! :version
|
17
15
|
expose! :released_at
|
18
16
|
expose! :properties_release, if: :displayed
|
19
17
|
expose :element_klass do |obj|
|
@@ -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)
|
17
|
+
response = Labimotion::TemplateHub.fetch_identifier('DatasetKlass', params[:identifier])
|
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,22 +23,14 @@ 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
|
-
|
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
|
26
|
+
if Labimotion::DatasetKlass.find_by(ols_term_id: attributes['ols_term_id']).present?
|
27
|
+
ds = Labimotion::DatasetKlass.find_by(ols_term_id: attributes['ols_term_id'])
|
28
|
+
ds.update!(attributes)
|
36
29
|
else
|
37
30
|
attributes['created_by'] = current_user.id
|
38
31
|
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']}!" }
|
41
32
|
end
|
33
|
+
ds.create_klasses_revision(current_user)
|
42
34
|
rescue StandardError => e
|
43
35
|
Labimotion.log_exception(e, current_user)
|
44
36
|
# { error: e.message }
|
@@ -159,7 +159,7 @@ module Labimotion
|
|
159
159
|
att_ary = create_attachments(
|
160
160
|
params[:attfiles],
|
161
161
|
params[:delfiles],
|
162
|
-
|
162
|
+
params[:att_type],
|
163
163
|
params[:att_id],
|
164
164
|
params[:attfilesIdentifier],
|
165
165
|
current_user.id
|
@@ -174,7 +174,8 @@ module Labimotion
|
|
174
174
|
true
|
175
175
|
rescue StandardError => e
|
176
176
|
Labimotion.log_exception(e, current_user)
|
177
|
-
false
|
177
|
+
## false
|
178
|
+
raise e
|
178
179
|
end
|
179
180
|
|
180
181
|
def element_revisions(params)
|
@@ -289,9 +290,9 @@ module Labimotion
|
|
289
290
|
raise e
|
290
291
|
end
|
291
292
|
|
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', '
|
293
|
+
def create_repo_klass(params, current_user)
|
294
|
+
response = Labimotion::TemplateHub.fetch_identifier('ElementKlass', params[:identifier])
|
295
|
+
attributes = response.slice('name', 'label', 'desc', 'icon_name', 'klass_prefix', 'is_generic', 'identifier', 'properties_release', 'version')
|
295
296
|
attributes['properties_release']['identifier'] = attributes['identifier']
|
296
297
|
attributes['properties_template'] = attributes['properties_release']
|
297
298
|
attributes['place'] = ((Labimotion::DatasetKlass.all.length * 10) || 0) + 10
|
@@ -302,38 +303,17 @@ module Labimotion
|
|
302
303
|
|
303
304
|
element_klass = Labimotion::ElementKlass.find_by(identifier: attributes['identifier'])
|
304
305
|
if element_klass.present?
|
305
|
-
|
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
|
+
element_klass.update!(attributes)
|
312
307
|
else
|
313
|
-
|
314
|
-
|
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
|
308
|
+
attributes['created_by'] = current_user.id
|
309
|
+
element_klass = Labimotion::ElementKlass.create!(attributes)
|
322
310
|
end
|
311
|
+
element_klass.create_klasses_revision(current_user)
|
323
312
|
rescue StandardError => e
|
324
313
|
Labimotion.log_exception(e, current_user)
|
325
314
|
# { error: e.message }
|
326
315
|
raise e
|
327
316
|
end
|
328
317
|
|
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
|
-
|
338
318
|
end
|
339
319
|
end
|
@@ -193,7 +193,7 @@ module Labimotion
|
|
193
193
|
(files || []).each_with_index do |file, index|
|
194
194
|
next unless (tempfile = file[:tempfile])
|
195
195
|
|
196
|
-
|
196
|
+
a = Attachment.new(
|
197
197
|
bucket: file[:container_id],
|
198
198
|
filename: file[:filename],
|
199
199
|
con_state: Labimotion::ConState::NONE,
|
@@ -205,7 +205,7 @@ module Labimotion
|
|
205
205
|
attachable_type: type,
|
206
206
|
attachable_id: id,
|
207
207
|
)
|
208
|
-
|
208
|
+
ActiveRecord::Base.transaction do
|
209
209
|
att.save!
|
210
210
|
attach_ary.push(att.id)
|
211
211
|
ensure
|
@@ -214,11 +214,12 @@ module Labimotion
|
|
214
214
|
end
|
215
215
|
end
|
216
216
|
unless (del_files || []).empty?
|
217
|
-
Attachment.where('id IN (?) AND attachable_type = (?)', del_files.map!(&:to_i),
|
217
|
+
Attachment.where('id IN (?) AND attachable_type = (?)', del_files.map!(&:to_i),
|
218
|
+
type).update_all(attachable_id: nil)
|
218
219
|
end
|
219
220
|
attach_ary
|
220
221
|
rescue StandardError => e
|
221
|
-
Labimotion.log_exception(e)
|
222
|
+
Labimotion.log_exception(e, current_user)
|
222
223
|
raise e
|
223
224
|
end
|
224
225
|
|
@@ -230,16 +231,15 @@ module Labimotion
|
|
230
231
|
Chemotion::Generic::Fetch::Template.list(API::TARGET, name)
|
231
232
|
end
|
232
233
|
|
233
|
-
def fetch_repo(name
|
234
|
-
|
234
|
+
def fetch_repo(name)
|
235
|
+
current_klasses = "Labimotion::#{name}".constantize.where.not(identifier: nil)&.pluck(:identifier) || []
|
235
236
|
response = Labimotion::TemplateHub.list(name)
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
(response && response['list']) || []
|
237
|
+
if response && response['list'].present? && response['list'].length.positive?
|
238
|
+
filter_list = response['list']&.reject do |ds|
|
239
|
+
current_klasses.include?(ds['identifier'])
|
240
|
+
end || []
|
241
|
+
end
|
242
|
+
filter_list || []
|
243
243
|
rescue StandardError => e
|
244
244
|
Labimotion.log_exception(e, current_user)
|
245
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)
|
67
|
+
response = Labimotion::TemplateHub.fetch_identifier('SegmentKlass', params[:identifier])
|
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']
|
79
|
-
return {
|
78
|
+
element_klass = Labimotion::ElementKlass.find_by(name: response['element_klass']['name']) if element_klass.nil?
|
79
|
+
return { error: 'ElementKlass not found' } 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,24 +85,12 @@ 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
|
-
|
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
|
+
segment_klass.update!(attributes)
|
95
89
|
else
|
96
|
-
|
97
|
-
|
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
|
90
|
+
attributes['created_by'] = current_user.id
|
91
|
+
segment_klass = Labimotion::SegmentKlass.create!(attributes)
|
105
92
|
end
|
93
|
+
segment_klass.create_klasses_revision(current_user)
|
106
94
|
rescue StandardError => e
|
107
95
|
Labimotion.log_exception(e, current_user)
|
108
96
|
raise e
|