labimotion 0.1.11 → 0.1.14
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 +2 -0
- data/lib/labimotion/apis/generic_element_api.rb +64 -3
- data/lib/labimotion/apis/labimotion_hub_api.rb +13 -4
- data/lib/labimotion/entities/generic_klass_entity.rb +1 -1
- data/lib/labimotion/entities/generic_public_entity.rb +2 -0
- data/lib/labimotion/entities/klass_revision_entity.rb +1 -1
- data/lib/labimotion/helpers/dataset_helpers.rb +5 -3
- data/lib/labimotion/helpers/element_helpers.rb +71 -20
- data/lib/labimotion/helpers/generic_helpers.rb +21 -26
- data/lib/labimotion/helpers/segment_helpers.rb +17 -14
- data/lib/labimotion/libs/converter.rb +19 -11
- data/lib/labimotion/libs/export_dataset.rb +13 -3
- data/lib/labimotion/libs/nmr_mapper.rb +17 -4
- data/lib/labimotion/libs/nmr_mapper_repo.rb +22 -7
- data/lib/labimotion/libs/template_hub.rb +9 -3
- data/lib/labimotion/models/concerns/attachment_converter.rb +3 -2
- data/lib/labimotion/models/concerns/datasetable.rb +6 -10
- data/lib/labimotion/models/concerns/generic_klass_revisions.rb +18 -10
- data/lib/labimotion/models/concerns/segmentable.rb +6 -11
- data/lib/labimotion/models/concerns/workflow.rb +27 -0
- data/lib/labimotion/models/element.rb +14 -1
- data/lib/labimotion/models/element_klass.rb +12 -2
- data/lib/labimotion/models/element_klasses_revision.rb +10 -0
- data/lib/labimotion/models/hub_log.rb +8 -0
- data/lib/labimotion/utils/utils.rb +33 -0
- data/lib/labimotion/version.rb +2 -1
- data/lib/labimotion.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4462059ccf7843ed6aee9d493e2fcadf9cb6675fd2e71652eb8ce670cd3e3630
|
4
|
+
data.tar.gz: bf3f3b3c664117b679b19ba27171ed37f45371e267a44988e0a709c98b9b66e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec3bfa245f202a31bb6e1a46104296b7ed7eab6500eabc7832adcaf0ded162492d46403459a476f89468ae8a513af83e5f8d23e057efd0820829be745c150e55
|
7
|
+
data.tar.gz: 04f4c1e4856c2a9909a487dfa4e2764aac737ac76379e892d07fd66da5347be2c55ec94281b7241bae57736c2667fe03250c945930295285b447850b9039fd92
|
@@ -21,6 +21,8 @@ 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)
|
24
26
|
end
|
25
27
|
end
|
26
28
|
|
@@ -32,6 +34,8 @@ module Labimotion
|
|
32
34
|
get do
|
33
35
|
list = klass_list(params[:generic_only])
|
34
36
|
present list, with: Labimotion::ElementKlassEntity, root: 'klass'
|
37
|
+
rescue StandardError => e
|
38
|
+
Labimotion.log_exception(e, current_user)
|
35
39
|
end
|
36
40
|
end
|
37
41
|
|
@@ -67,6 +71,9 @@ module Labimotion
|
|
67
71
|
post do
|
68
72
|
authenticate_admin!('elements')
|
69
73
|
update_element_klass(current_user, params)
|
74
|
+
rescue StandardError => e
|
75
|
+
Labimotion.log_exception(e, current_user)
|
76
|
+
raise e
|
70
77
|
end
|
71
78
|
end
|
72
79
|
|
@@ -79,6 +86,9 @@ module Labimotion
|
|
79
86
|
get do
|
80
87
|
list = list_klass_revisions(params)
|
81
88
|
present list, with: Labimotion::KlassRevisionEntity, root: 'revisions'
|
89
|
+
rescue StandardError => e
|
90
|
+
Labimotion.log_exception(e, current_user)
|
91
|
+
[]
|
82
92
|
end
|
83
93
|
end
|
84
94
|
|
@@ -90,6 +100,9 @@ module Labimotion
|
|
90
100
|
get do
|
91
101
|
list = element_revisions(params)
|
92
102
|
present list, with: Labimotion::ElementRevisionEntity, root: 'revisions'
|
103
|
+
rescue StandardError => e
|
104
|
+
Labimotion.log_exception(e, current_user)
|
105
|
+
[]
|
93
106
|
end
|
94
107
|
end
|
95
108
|
|
@@ -104,6 +117,9 @@ module Labimotion
|
|
104
117
|
authenticate_admin!(params[:klass].gsub(/(Klass)/, 's').downcase)
|
105
118
|
delete_klass_revision(params)
|
106
119
|
status 201
|
120
|
+
rescue StandardError => e
|
121
|
+
Labimotion.log_exception(e, current_user)
|
122
|
+
raise e
|
107
123
|
end
|
108
124
|
end
|
109
125
|
|
@@ -117,6 +133,9 @@ module Labimotion
|
|
117
133
|
post do
|
118
134
|
delete_revision(params)
|
119
135
|
status 201
|
136
|
+
rescue StandardError => e
|
137
|
+
Labimotion.log_exception(e, current_user)
|
138
|
+
raise e
|
120
139
|
end
|
121
140
|
end
|
122
141
|
|
@@ -129,6 +148,9 @@ module Labimotion
|
|
129
148
|
klass = Labimotion::Segment.find(params[:id])
|
130
149
|
list = klass.segments_revisions unless klass.nil?
|
131
150
|
present list&.sort_by(&:created_at).reverse, with: Labimotion::SegmentRevisionEntity, root: 'revisions'
|
151
|
+
rescue StandardError => e
|
152
|
+
Labimotion.log_exception(e, current_user)
|
153
|
+
[]
|
132
154
|
end
|
133
155
|
end
|
134
156
|
|
@@ -152,6 +174,8 @@ module Labimotion
|
|
152
174
|
post do
|
153
175
|
upload_generics_files(current_user, params)
|
154
176
|
true
|
177
|
+
rescue StandardError => e
|
178
|
+
Labimotion.log_exception(e, current_user)
|
155
179
|
end
|
156
180
|
end
|
157
181
|
|
@@ -160,6 +184,30 @@ module Labimotion
|
|
160
184
|
get do
|
161
185
|
list = Labimotion::ElementKlass.all.sort_by { |e| e.place }
|
162
186
|
present list, with: Labimotion::ElementKlassEntity, root: 'klass'
|
187
|
+
rescue StandardError => e
|
188
|
+
Labimotion.log_exception(e, current_user)
|
189
|
+
[]
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
namespace :fetch_repo do
|
194
|
+
desc 'fetch Generic Element Klass from Chemotion Repository'
|
195
|
+
get do
|
196
|
+
fetch_repo('ElementKlass')
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
namespace :create_repo_klass do
|
201
|
+
desc 'create Generic Element Klass'
|
202
|
+
params do
|
203
|
+
requires :identifier, type: String, desc: 'Identifier'
|
204
|
+
end
|
205
|
+
post do
|
206
|
+
create_repo_klass(params, current_user)
|
207
|
+
present ElementKlass.all, with: Labimotion::ElementKlassEntity, root: 'klass'
|
208
|
+
rescue StandardError => e
|
209
|
+
Labimotion.log_exception(e, current_user)
|
210
|
+
{ error: e.message }
|
163
211
|
end
|
164
212
|
end
|
165
213
|
|
@@ -176,6 +224,8 @@ module Labimotion
|
|
176
224
|
end
|
177
225
|
post do
|
178
226
|
deactivate_klass(params)
|
227
|
+
rescue StandardError => e
|
228
|
+
Labimotion.log_exception(e, current_user)
|
179
229
|
end
|
180
230
|
end
|
181
231
|
|
@@ -188,6 +238,9 @@ module Labimotion
|
|
188
238
|
delete ':id' do
|
189
239
|
delete_klass(params)
|
190
240
|
status 201
|
241
|
+
rescue StandardError => e
|
242
|
+
Labimotion.log_exception(e, current_user)
|
243
|
+
raise e
|
191
244
|
end
|
192
245
|
end
|
193
246
|
|
@@ -197,14 +250,17 @@ module Labimotion
|
|
197
250
|
requires :klass, type: String, desc: 'Klass', values: %w[ElementKlass SegmentKlass DatasetKlass]
|
198
251
|
requires :id, type: Integer, desc: 'Klass ID'
|
199
252
|
requires :properties_template, type: Hash
|
200
|
-
optional :
|
253
|
+
optional :release, type: String, default: 'draft', desc: 'release status', values: %w[draft major minor patch]
|
201
254
|
end
|
202
255
|
after_validation do
|
203
256
|
authenticate_admin!(params[:klass].gsub(/(Klass)/, 's').downcase)
|
204
257
|
@klz = fetch_klass(params[:klass], params[:id])
|
205
258
|
end
|
206
259
|
post do
|
207
|
-
update_template(params)
|
260
|
+
update_template(params, current_user)
|
261
|
+
rescue StandardError => e
|
262
|
+
Labimotion.log_exception(e, current_user)
|
263
|
+
raise e
|
208
264
|
end
|
209
265
|
end
|
210
266
|
|
@@ -216,10 +272,10 @@ module Labimotion
|
|
216
272
|
optional :from_date, type: Integer, desc: 'created_date from in ms'
|
217
273
|
optional :to_date, type: Integer, desc: 'created_date to in ms'
|
218
274
|
optional :filter_created_at, type: Boolean, desc: 'filter by created at or updated at'
|
275
|
+
optional :sort_column, type: String, desc: 'sort by updated_at or selected layers property'
|
219
276
|
end
|
220
277
|
paginate per_page: 7, offset: 0, max_per_page: 100
|
221
278
|
get do
|
222
|
-
|
223
279
|
scope = list_serialized_elements(params, current_user)
|
224
280
|
|
225
281
|
reset_pagination_page(scope)
|
@@ -235,6 +291,9 @@ module Labimotion
|
|
235
291
|
end
|
236
292
|
end
|
237
293
|
{ generic_elements: generic_elements }
|
294
|
+
rescue StandardError => e
|
295
|
+
Labimotion.log_exception(e, current_user)
|
296
|
+
{ generic_elements: [] }
|
238
297
|
end
|
239
298
|
|
240
299
|
desc 'Return serialized element by id'
|
@@ -262,6 +321,8 @@ module Labimotion
|
|
262
321
|
attachments: Entities::AttachmentEntity.represent(element.attachments),
|
263
322
|
}
|
264
323
|
end
|
324
|
+
rescue StandardError => e
|
325
|
+
Labimotion.log_exception(e, current_user)
|
265
326
|
end
|
266
327
|
end
|
267
328
|
|
@@ -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
|
|
@@ -4,7 +4,7 @@ require 'labimotion/entities/application_entity'
|
|
4
4
|
module Labimotion
|
5
5
|
# GenericKlassEntity
|
6
6
|
class GenericKlassEntity < ApplicationEntity
|
7
|
-
expose :id, :uuid, :label, :desc, :properties_template, :properties_release, :is_active,
|
7
|
+
expose :id, :uuid, :label, :desc, :properties_template, :properties_release, :is_active, :version,
|
8
8
|
:place, :released_at, :identifier, :sync_time, :created_by, :updated_by, :created_at, :updated_at
|
9
9
|
expose_timestamps(timestamp_fields: [:released_at])
|
10
10
|
expose_timestamps(timestamp_fields: [:created_at])
|
@@ -5,6 +5,7 @@ require 'labimotion/entities/application_entity'
|
|
5
5
|
# Entity module
|
6
6
|
module Labimotion
|
7
7
|
class GenericPublicEntity < Labimotion::ApplicationEntity
|
8
|
+
expose! :uuid
|
8
9
|
expose! :name
|
9
10
|
expose! :desc
|
10
11
|
expose! :icon_name
|
@@ -12,6 +13,7 @@ module Labimotion
|
|
12
13
|
expose! :klass_name
|
13
14
|
expose! :label
|
14
15
|
expose! :identifier
|
16
|
+
expose! :version
|
15
17
|
expose! :released_at
|
16
18
|
expose! :properties_release, if: :displayed
|
17
19
|
expose :element_klass do |obj|
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module Labimotion
|
4
4
|
# KlassRevisionEntity
|
5
5
|
class KlassRevisionEntity < ApplicationEntity
|
6
|
-
expose :id, :uuid, :properties_release, :released_at
|
6
|
+
expose :id, :uuid, :properties_release, :version, :released_at
|
7
7
|
|
8
8
|
expose :klass_id do |object|
|
9
9
|
klass_id = object.element_klass_id if object.respond_to? :element_klass_id
|
@@ -15,8 +15,9 @@ module Labimotion
|
|
15
15
|
|
16
16
|
def create_repo_klass(params, current_user)
|
17
17
|
response = Labimotion::TemplateHub.fetch_identifier('DatasetKlass', params[:identifier])
|
18
|
-
attributes = response.slice('ols_term_id', 'label', 'desc', 'uuid', 'identifier') # .except(:id, :is_active, :place, :created_by, :created_at, :updated_at)
|
19
|
-
attributes['
|
18
|
+
attributes = response.slice('ols_term_id', 'label', 'desc', 'uuid', 'identifier', 'properties_release', 'version') # .except(:id, :is_active, :place, :created_by, :created_at, :updated_at)
|
19
|
+
attributes['properties_release']['identifier'] = attributes['identifier']
|
20
|
+
attributes['properties_template'] = attributes['properties_release']
|
20
21
|
attributes['place'] = ((Labimotion::DatasetKlass.all.length * 10) || 0) + 10
|
21
22
|
attributes['is_active'] = false
|
22
23
|
attributes['updated_by'] = current_user.id
|
@@ -27,8 +28,9 @@ module Labimotion
|
|
27
28
|
ds.update!(attributes)
|
28
29
|
else
|
29
30
|
attributes['created_by'] = current_user.id
|
30
|
-
Labimotion::DatasetKlass.create!(attributes)
|
31
|
+
ds = Labimotion::DatasetKlass.create!(attributes)
|
31
32
|
end
|
33
|
+
ds.create_klasses_revision(current_user)
|
32
34
|
rescue StandardError => e
|
33
35
|
Labimotion.log_exception(e, current_user)
|
34
36
|
# { error: e.message }
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'grape'
|
4
|
-
require 'labimotion/
|
4
|
+
require 'labimotion/utils/utils'
|
5
5
|
# require 'labimotion/models/element_klass'
|
6
6
|
module Labimotion
|
7
7
|
## ElementHelpers
|
@@ -20,11 +20,10 @@ module Labimotion
|
|
20
20
|
uuid = SecureRandom.uuid
|
21
21
|
template = { uuid: uuid, layers: {}, select_options: {} }
|
22
22
|
attributes = declared(params, include_missing: false)
|
23
|
-
attributes[:properties_template]
|
24
|
-
attributes[:properties_template] =
|
25
|
-
attributes[:properties_template]['
|
26
|
-
attributes[:properties_template]['
|
27
|
-
attributes[:properties_template]['klass'] = 'ElementKlass' if attributes[:properties_template].present?
|
23
|
+
attributes[:properties_template] = template if attributes[:properties_template].nil?
|
24
|
+
attributes[:properties_template]['uuid'] = uuid
|
25
|
+
attributes[:properties_template]['pkg'] = Labimotion::Utils.pkg(attributes[:properties_template]['pkg'])
|
26
|
+
attributes[:properties_template]['klass'] = 'ElementKlass'
|
28
27
|
attributes[:is_active] = false
|
29
28
|
attributes[:uuid] = uuid
|
30
29
|
attributes[:released_at] = DateTime.now
|
@@ -33,8 +32,8 @@ module Labimotion
|
|
33
32
|
|
34
33
|
new_klass = Labimotion::ElementKlass.create!(attributes)
|
35
34
|
new_klass.reload
|
36
|
-
new_klass.create_klasses_revision(current_user
|
37
|
-
klass_names_file = Rails.root.join('
|
35
|
+
new_klass.create_klasses_revision(current_user)
|
36
|
+
klass_names_file = Rails.root.join('app/packs/klasses.json')
|
38
37
|
klasses = Labimotion::ElementKlass.where(is_active: true)&.pluck(:name) || []
|
39
38
|
File.write(klass_names_file, klasses)
|
40
39
|
klasses
|
@@ -68,11 +67,12 @@ module Labimotion
|
|
68
67
|
uuid = SecureRandom.uuid
|
69
68
|
params[:properties]['uuid'] = uuid
|
70
69
|
params[:properties]['klass_uuid'] = klass[:uuid]
|
71
|
-
params[:properties]['
|
72
|
-
params[:properties]['labimotion'] = Labimotion::VERSION
|
70
|
+
params[:properties]['pkg'] = Labimotion::Utils.pkg(params[:properties]['pkg'])
|
73
71
|
params[:properties]['klass'] = 'Element'
|
72
|
+
params[:properties]['identifier'] = klass[:identifier]
|
74
73
|
properties = params[:properties]
|
75
74
|
properties.delete('flow') unless properties['flow'].nil?
|
75
|
+
properties.delete('flowObject') unless properties['flowObject'].nil?
|
76
76
|
properties.delete('select_options') unless properties['select_options'].nil?
|
77
77
|
attributes = {
|
78
78
|
name: params[:name],
|
@@ -109,14 +109,14 @@ module Labimotion
|
|
109
109
|
params.delete(:container)
|
110
110
|
params.delete(:properties)
|
111
111
|
attributes = declared(params.except(:segments), include_missing: false)
|
112
|
-
properties['
|
113
|
-
properties['labimotion'] = Labimotion::VERSION
|
112
|
+
properties['pkg'] = Labimotion::Utils.pkg(properties['pkg'])
|
114
113
|
if element.klass_uuid != properties['klass_uuid'] || element.properties != properties || element.name != params[:name]
|
115
114
|
properties['klass'] = 'Element'
|
116
115
|
uuid = SecureRandom.uuid
|
117
116
|
properties['uuid'] = uuid
|
118
117
|
|
119
118
|
properties.delete('flow') unless properties['flow'].nil?
|
119
|
+
properties.delete('flowObject') unless properties['flowObject'].nil?
|
120
120
|
properties.delete('select_options') unless properties['select_options'].nil?
|
121
121
|
|
122
122
|
attributes['properties'] = properties
|
@@ -168,8 +168,8 @@ module Labimotion
|
|
168
168
|
(attach_ary << att_ary).flatten! unless att_ary&.empty?
|
169
169
|
|
170
170
|
if Labimotion::IS_RAILS5 == true
|
171
|
-
TransferThumbnailToPublicJob.set(queue: "transfer_thumbnail_to_public_#{current_user.id}").
|
172
|
-
TransferFileFromTmpJob.set(queue: "transfer_file_from_tmp_#{current_user.id}").
|
171
|
+
TransferThumbnailToPublicJob.set(queue: "transfer_thumbnail_to_public_#{current_user.id}").perform_later(attach_ary) unless attach_ary.empty?
|
172
|
+
TransferFileFromTmpJob.set(queue: "transfer_file_from_tmp_#{current_user.id}").perform_later(attach_ary) unless attach_ary.empty?
|
173
173
|
end
|
174
174
|
true
|
175
175
|
rescue StandardError => e
|
@@ -180,7 +180,7 @@ module Labimotion
|
|
180
180
|
def element_revisions(params)
|
181
181
|
klass = Labimotion::Element.find(params[:id])
|
182
182
|
list = klass.elements_revisions unless klass.nil?
|
183
|
-
list&.sort_by(&:created_at)&.reverse
|
183
|
+
list&.sort_by(&:created_at)&.reverse&.first(10)
|
184
184
|
rescue StandardError => e
|
185
185
|
Labimotion.log_exception(e, current_user)
|
186
186
|
raise e
|
@@ -245,7 +245,7 @@ module Labimotion
|
|
245
245
|
.where(
|
246
246
|
element_klasses: { name: params[:el_type] },
|
247
247
|
collections_elements: { collection_id: collection_id },
|
248
|
-
).includes(:tag, collections: :sync_collections_users)
|
248
|
+
).includes(:tag, collections: :sync_collections_users)
|
249
249
|
else
|
250
250
|
Labimotion::Element.none
|
251
251
|
end
|
@@ -254,14 +254,65 @@ module Labimotion
|
|
254
254
|
from = params[:from_date]
|
255
255
|
to = params[:to_date]
|
256
256
|
by_created_at = params[:filter_created_at] || false
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
257
|
+
if params[:sort_column]&.include?('.')
|
258
|
+
layer, field = params[:sort_column].split('.')
|
259
|
+
|
260
|
+
element_klass = Labimotion::ElementKlass.find_by(name: params[:el_type])
|
261
|
+
allowed_fields = element_klass.properties_release.dig('layers', layer, 'fields')&.pluck('field') || []
|
262
|
+
|
263
|
+
if field.in?(allowed_fields)
|
264
|
+
query = ActiveRecord::Base.sanitize_sql(
|
265
|
+
[
|
266
|
+
"LEFT JOIN LATERAL(
|
267
|
+
SELECT field->'value' AS value
|
268
|
+
FROM jsonb_array_elements(properties->'layers'->:layer->'fields') a(field)
|
269
|
+
WHERE field->>'field' = :field
|
270
|
+
) a ON true",
|
271
|
+
{ layer: layer, field: field },
|
272
|
+
],
|
273
|
+
)
|
274
|
+
scope = scope.joins(query).order('value ASC NULLS FIRST')
|
275
|
+
else
|
276
|
+
scope = scope.order(updated_at: :desc)
|
277
|
+
end
|
278
|
+
else
|
279
|
+
scope = scope.order(updated_at: :desc)
|
280
|
+
end
|
281
|
+
|
282
|
+
scope = scope.elements_created_time_from(Time.at(from)) if from && by_created_at
|
283
|
+
scope = scope.elements_created_time_to(Time.at(to) + 1.day) if to && by_created_at
|
284
|
+
scope = scope.elements_updated_time_from(Time.at(from)) if from && !by_created_at
|
285
|
+
scope = scope.elements_updated_time_to(Time.at(to) + 1.day) if to && !by_created_at
|
261
286
|
scope
|
262
287
|
rescue StandardError => e
|
263
288
|
Labimotion.log_exception(e, current_user)
|
264
289
|
raise e
|
265
290
|
end
|
291
|
+
|
292
|
+
def create_repo_klass(params, current_user)
|
293
|
+
response = Labimotion::TemplateHub.fetch_identifier('ElementKlass', params[:identifier])
|
294
|
+
attributes = response.slice('name', 'label', 'desc', 'icon_name', 'klass_prefix', 'is_generic', 'identifier', 'properties_release', 'version')
|
295
|
+
attributes['properties_release']['identifier'] = attributes['identifier']
|
296
|
+
attributes['properties_template'] = attributes['properties_release']
|
297
|
+
attributes['place'] = ((Labimotion::DatasetKlass.all.length * 10) || 0) + 10
|
298
|
+
attributes['is_active'] = false
|
299
|
+
attributes['updated_by'] = current_user.id
|
300
|
+
attributes['sync_by'] = current_user.id
|
301
|
+
attributes['sync_time'] = DateTime.now
|
302
|
+
|
303
|
+
element_klass = Labimotion::ElementKlass.find_by(identifier: attributes['identifier'])
|
304
|
+
if element_klass.present?
|
305
|
+
element_klass.update!(attributes)
|
306
|
+
else
|
307
|
+
attributes['created_by'] = current_user.id
|
308
|
+
element_klass = Labimotion::ElementKlass.create!(attributes)
|
309
|
+
end
|
310
|
+
element_klass.create_klasses_revision(current_user)
|
311
|
+
rescue StandardError => e
|
312
|
+
Labimotion.log_exception(e, current_user)
|
313
|
+
# { error: e.message }
|
314
|
+
raise e
|
315
|
+
end
|
316
|
+
|
266
317
|
end
|
267
318
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require 'grape'
|
3
|
-
require 'labimotion/
|
3
|
+
require 'labimotion/utils/utils'
|
4
4
|
# Helper for associated sample
|
5
5
|
module Labimotion
|
6
6
|
## Generic Helpers
|
@@ -41,23 +41,22 @@ module Labimotion
|
|
41
41
|
raise e
|
42
42
|
end
|
43
43
|
|
44
|
-
def update_template(params)
|
44
|
+
def update_template(params, current_user)
|
45
45
|
klz = fetch_klass(params[:klass], params[:id])
|
46
46
|
uuid = SecureRandom.uuid
|
47
47
|
properties = params[:properties_template]
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
properties['
|
54
|
-
properties['
|
55
|
-
properties['klass'] = @klz.class.name
|
48
|
+
properties['uuid'] = uuid
|
49
|
+
klz.version = Labimotion::Utils.next_version(params[:release], klz.version)
|
50
|
+
properties['version'] = klz.version
|
51
|
+
properties['pkg'] = Labimotion::Utils.pkg(params['pkg'] || (klz.properties_template && klz.properties_template['pkg']))
|
52
|
+
properties['klass'] = klz.class.name.split('::').last
|
53
|
+
properties['identifier'] = klz.identifier
|
54
|
+
properties.delete('eln') if properties['eln'].present?
|
56
55
|
klz.updated_by = current_user.id
|
57
56
|
klz.properties_template = properties
|
58
57
|
klz.save!
|
59
58
|
klz.reload
|
60
|
-
klz.create_klasses_revision(current_user
|
59
|
+
klz.create_klasses_revision(current_user) if params[:release] != 'draft'
|
61
60
|
klz
|
62
61
|
rescue StandardError => e
|
63
62
|
Labimotion.log_exception(e, current_user)
|
@@ -89,7 +88,7 @@ module Labimotion
|
|
89
88
|
def list_klass_revisions(params)
|
90
89
|
klass = "Labimotion::#{params[:klass]}".constantize.find_by(id: params[:id])
|
91
90
|
list = klass.send("#{params[:klass].underscore}es_revisions") unless klass.nil?
|
92
|
-
list
|
91
|
+
list&.order(released_at: :desc)&.limit(10)
|
93
92
|
rescue StandardError => e
|
94
93
|
Labimotion.log_exception(e, current_user)
|
95
94
|
raise e
|
@@ -97,12 +96,8 @@ module Labimotion
|
|
97
96
|
|
98
97
|
|
99
98
|
###############
|
100
|
-
|
101
|
-
|
102
99
|
def generate_klass_file
|
103
|
-
|
104
|
-
!File.directory?(klass_dir) && FileUtils.mkdir_p(klass_dir)
|
105
|
-
klass_names_file = File.join(klass_dir, 'klasses.json')
|
100
|
+
klass_names_file = Rails.root.join('app/packs/klasses.json')
|
106
101
|
klasses = Labimotion::ElementKlass.where(is_active: true)&.pluck(:name) || []
|
107
102
|
File.write(klass_names_file, klasses)
|
108
103
|
rescue StandardError => e
|
@@ -193,37 +188,37 @@ module Labimotion
|
|
193
188
|
raise e
|
194
189
|
end
|
195
190
|
|
196
|
-
def create_attachments(files, del_files, type, id, user_id)
|
191
|
+
def create_attachments(files, del_files, type, id, identifier, user_id)
|
197
192
|
attach_ary = []
|
198
|
-
(files || []).
|
193
|
+
(files || []).each_with_index do |file, index|
|
199
194
|
next unless (tempfile = file[:tempfile])
|
200
195
|
|
201
|
-
|
196
|
+
att = Attachment.new(
|
202
197
|
bucket: file[:container_id],
|
203
198
|
filename: file[:filename],
|
204
199
|
con_state: Labimotion::ConState::NONE,
|
205
200
|
file_path: file[:tempfile],
|
206
201
|
created_by: user_id,
|
207
202
|
created_for: user_id,
|
203
|
+
identifier: identifier[index],
|
208
204
|
content_type: file[:type],
|
209
205
|
attachable_type: type,
|
210
206
|
attachable_id: id,
|
211
207
|
)
|
212
208
|
begin
|
213
|
-
|
214
|
-
attach_ary.push(
|
209
|
+
att.save!
|
210
|
+
attach_ary.push(att.id)
|
215
211
|
ensure
|
216
212
|
tempfile.close
|
217
213
|
tempfile.unlink
|
218
214
|
end
|
219
215
|
end
|
220
216
|
unless (del_files || []).empty?
|
221
|
-
Attachment.where('id IN (?) AND attachable_type = (?)', del_files.map!(&:to_i),
|
222
|
-
type).update_all(attachable_id: nil)
|
217
|
+
Attachment.where('id IN (?) AND attachable_type = (?)', del_files.map!(&:to_i), type).update_all(attachable_id: nil)
|
223
218
|
end
|
224
219
|
attach_ary
|
225
220
|
rescue StandardError => e
|
226
|
-
Labimotion.log_exception(e
|
221
|
+
Labimotion.log_exception(e)
|
227
222
|
raise e
|
228
223
|
end
|
229
224
|
|
@@ -246,7 +241,7 @@ module Labimotion
|
|
246
241
|
filter_list || []
|
247
242
|
rescue StandardError => e
|
248
243
|
Labimotion.log_exception(e, current_user)
|
249
|
-
|
244
|
+
{ error: 'Cannot connect to Chemotion Repository' }
|
250
245
|
end
|
251
246
|
end
|
252
247
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require 'grape'
|
3
3
|
require 'labimotion/models/segment_klass'
|
4
|
+
require 'labimotion/utils/utils'
|
5
|
+
|
4
6
|
module Labimotion
|
5
7
|
## ElementHelpers
|
6
8
|
module SegmentHelpers
|
@@ -26,8 +28,7 @@ module Labimotion
|
|
26
28
|
attributes = declared(params, include_missing: false)
|
27
29
|
attributes[:properties_template]['uuid'] = uuid if attributes[:properties_template].present?
|
28
30
|
template = (attributes[:properties_template].presence || template)
|
29
|
-
template['
|
30
|
-
template['labimotion'] = Labimotion::VERSION
|
31
|
+
template['pkg'] = Labimotion::Utils.pkg(template['pkg'])
|
31
32
|
template['klass'] = 'SegmentKlass'
|
32
33
|
attributes.merge!(properties_template: template, element_klass: @klass, created_by: current_user.id,
|
33
34
|
place: place)
|
@@ -37,7 +38,7 @@ module Labimotion
|
|
37
38
|
attributes[:properties_release] = attributes[:properties_template]
|
38
39
|
klass = Labimotion::SegmentKlass.create!(attributes)
|
39
40
|
klass.reload
|
40
|
-
klass.create_klasses_revision(current_user
|
41
|
+
klass.create_klasses_revision(current_user)
|
41
42
|
klass
|
42
43
|
rescue StandardError => e
|
43
44
|
Labimotion.log_exception(e, current_user)
|
@@ -64,8 +65,9 @@ module Labimotion
|
|
64
65
|
|
65
66
|
def create_repo_klass(params, current_user)
|
66
67
|
response = Labimotion::TemplateHub.fetch_identifier('SegmentKlass', params[:identifier])
|
67
|
-
attributes = response.slice('label', 'desc', 'uuid', 'identifier', 'released_at'
|
68
|
-
attributes['
|
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']
|
69
71
|
attributes['place'] = ((Labimotion::SegmentKlass.all.length * 10) || 0) + 10
|
70
72
|
attributes['is_active'] = false
|
71
73
|
attributes['updated_by'] = current_user.id
|
@@ -74,20 +76,21 @@ module Labimotion
|
|
74
76
|
|
75
77
|
element_klass = Labimotion::ElementKlass.find_by(identifier: response['element_klass']['identifier'])
|
76
78
|
element_klass = Labimotion::ElementKlass.find_by(name: response['element_klass']['name']) if element_klass.nil?
|
77
|
-
if element_klass.nil?
|
78
|
-
el_attributes = response['element_klass'].slice('name', 'label', 'desc', 'uuid', 'identifier', 'icon_name', 'klass_prefix', 'is_generic', 'released_at')
|
79
|
-
el_attributes['properties_template'] = response['element_klass']['properties_release']
|
80
|
-
Labimotion::ElementKlass.create!(el_attributes)
|
81
|
-
end
|
79
|
+
return { error: 'ElementKlass not found' } if element_klass.nil?
|
82
80
|
|
81
|
+
# el_attributes = response['element_klass'].slice('name', 'label', 'desc', 'uuid', 'identifier', 'icon_name', 'klass_prefix', 'is_generic', 'released_at')
|
82
|
+
# el_attributes['properties_template'] = response['element_klass']['properties_release']
|
83
|
+
# Labimotion::ElementKlass.create!(el_attributes)
|
83
84
|
|
84
|
-
|
85
|
-
|
86
|
-
|
85
|
+
attributes['element_klass_id'] = element_klass.id
|
86
|
+
segment_klass = Labimotion::SegmentKlass.find_by(identifier: attributes['identifier'])
|
87
|
+
if segment_klass.present?
|
88
|
+
segment_klass.update!(attributes)
|
87
89
|
else
|
88
90
|
attributes['created_by'] = current_user.id
|
89
|
-
Labimotion::SegmentKlass.create!(attributes)
|
91
|
+
segment_klass = Labimotion::SegmentKlass.create!(attributes)
|
90
92
|
end
|
93
|
+
segment_klass.create_klasses_revision(current_user)
|
91
94
|
rescue StandardError => e
|
92
95
|
Labimotion.log_exception(e, current_user)
|
93
96
|
raise e
|