labimotion 2.0.3 → 2.1.0.rc1
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 +20 -3
- data/lib/labimotion/apis/generic_element_api.rb +22 -2
- data/lib/labimotion/apis/generic_klass_api.rb +40 -1
- data/lib/labimotion/apis/labimotion_api.rb +1 -3
- data/lib/labimotion/apis/labimotion_hub_api.rb +10 -83
- data/lib/labimotion/apis/segment_api.rb +5 -3
- data/lib/labimotion/constants.rb +0 -7
- data/lib/labimotion/entities/application_entity.rb +7 -80
- data/lib/labimotion/entities/dataset_entity.rb +8 -3
- data/lib/labimotion/entities/dataset_klass_entity.rb +3 -2
- data/lib/labimotion/entities/element_entity.rb +1 -1
- data/lib/labimotion/entities/element_klass_entity.rb +2 -2
- data/lib/labimotion/entities/element_revision_entity.rb +1 -1
- data/lib/labimotion/entities/eln_element_entity.rb +2 -2
- data/lib/labimotion/entities/generic_klass_entity.rb +8 -9
- data/lib/labimotion/entities/generic_public_entity.rb +5 -3
- data/lib/labimotion/entities/klass_revision_entity.rb +9 -4
- data/lib/labimotion/entities/properties_entity.rb +1 -0
- data/lib/labimotion/entities/segment_entity.rb +5 -2
- data/lib/labimotion/entities/segment_revision_entity.rb +2 -2
- data/lib/labimotion/entities/vocabulary_entity.rb +2 -2
- data/lib/labimotion/helpers/dataset_helpers.rb +6 -4
- data/lib/labimotion/helpers/element_helpers.rb +6 -4
- data/lib/labimotion/helpers/segment_helpers.rb +2 -2
- data/lib/labimotion/libs/data/mapper/Chemwiki.json +2 -2
- data/lib/labimotion/libs/properties_handler.rb +10 -0
- data/lib/labimotion/libs/template_hub.rb +10 -28
- data/lib/labimotion/libs/vocabulary_handler.rb +8 -6
- data/lib/labimotion/models/concerns/datasetable.rb +3 -3
- data/lib/labimotion/models/concerns/generic_klass.rb +16 -0
- data/lib/labimotion/models/concerns/segmentable.rb +44 -7
- data/lib/labimotion/models/dataset_klass.rb +15 -2
- data/lib/labimotion/models/dataset_klasses_revision.rb +1 -4
- data/lib/labimotion/models/element.rb +7 -1
- data/lib/labimotion/models/element_klass.rb +10 -1
- data/lib/labimotion/models/element_klasses_revision.rb +2 -3
- data/lib/labimotion/models/segment_klass.rb +10 -4
- data/lib/labimotion/models/segment_klasses_revision.rb +1 -4
- data/lib/labimotion/version.rb +2 -2
- metadata +5 -7
- data/lib/labimotion/libs/data/layer/StdDataset.json +0 -212
- data/lib/labimotion/models/concerns/klass_revision.rb +0 -23
- data/lib/labimotion/models/template_submission.rb +0 -52
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: dc6bf6015a4c970c7f2bd3e3d6e1a2dfb334e6acc4c53f255c5ef7cb912b6b1e
|
|
4
|
+
data.tar.gz: c8d7fda79cb1e3967a884b7ebd53db0f08eb90777ec0f78e58cabada98038f82
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0dc6b6c5242a5480c52535ab0dba78593ed66258ba9d509c8d10674dcddd50a683a319331753b098112889faa6c5199df2dab26a17e16990944227ff914a85ff
|
|
7
|
+
data.tar.gz: e78481dec58ed4a2a3e50d968fd39561ce0a2e25aba773db3f1f97b79cdc58c2737c3ec354456ceb1eb3fcae8a953ad51228f631720f9dc31dbabd4b794856d5
|
|
@@ -11,19 +11,36 @@ module Labimotion
|
|
|
11
11
|
namespace :klasses do
|
|
12
12
|
desc 'get dataset klasses'
|
|
13
13
|
get do
|
|
14
|
-
list = klass_list(true)
|
|
14
|
+
list = klass_list(true, false)
|
|
15
15
|
present list.sort_by(&:place), with: Labimotion::DatasetKlassEntity, root: 'klass'
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
+
namespace :list_klass do
|
|
20
|
+
desc 'list Generic Dataset Klass'
|
|
21
|
+
params do
|
|
22
|
+
optional :is_active, type: Boolean, desc: 'Active or Inactive Dataset'
|
|
23
|
+
optional :displayed_in_list, type: Boolean, desc: 'Display in list format', default: true
|
|
24
|
+
end
|
|
25
|
+
get do
|
|
26
|
+
list = klass_list(params[:is_active], params[:displayed_in_list])
|
|
27
|
+
serialized_data = Labimotion::DatasetKlassEntity.represent(list, displayed_in_list: params[:displayed_in_list])
|
|
28
|
+
{ mc: 'ss00', data: serialized_data }
|
|
29
|
+
rescue StandardError => e
|
|
30
|
+
Labimotion.log_exception(e, current_user)
|
|
31
|
+
{ mc: 'se00', msg: e.message, data: [] }
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Deprecated: This namespace is no longer used, but kept for backward compatibility. It is replaced by `list_klass`.
|
|
19
36
|
namespace :list_dataset_klass do
|
|
20
37
|
desc 'list Generic Dataset Klass'
|
|
21
38
|
params do
|
|
22
39
|
optional :is_active, type: Boolean, desc: 'Active or Inactive Dataset'
|
|
23
40
|
end
|
|
24
41
|
get do
|
|
25
|
-
list = klass_list(params[:is_active])
|
|
26
|
-
present list, with: Labimotion::DatasetKlassEntity, root: 'klass'
|
|
42
|
+
list = klass_list(params[:is_active], false)
|
|
43
|
+
present list, with: Labimotion::DatasetKlassEntity, root: 'klass', displayed_in_list: false
|
|
27
44
|
end
|
|
28
45
|
end
|
|
29
46
|
|
|
@@ -221,6 +221,26 @@ module Labimotion
|
|
|
221
221
|
end
|
|
222
222
|
end
|
|
223
223
|
|
|
224
|
+
namespace :list_element_klass do
|
|
225
|
+
desc 'list Generic Element Klass'
|
|
226
|
+
params do
|
|
227
|
+
optional :is_generic, type: Boolean, desc: 'Is Generic or Non-Generic Element'
|
|
228
|
+
optional :is_active, type: Boolean, desc: 'Active or Inactive Dataset'
|
|
229
|
+
optional :displayed_in_list, type: Boolean, desc: 'Display in list format', default: true
|
|
230
|
+
end
|
|
231
|
+
get do
|
|
232
|
+
scope = params[:displayed_in_list] ? Labimotion::ElementKlass.for_list_display : Labimotion::ElementKlass.all
|
|
233
|
+
scope = scope.where(is_generic: params[:is_generic]) if params.key?(:is_generic)
|
|
234
|
+
|
|
235
|
+
list = scope.sort_by(&:place)
|
|
236
|
+
present list, with: Labimotion::ElementKlassEntity, root: 'klass', displayed_in_list: params[:displayed_in_list]
|
|
237
|
+
rescue StandardError => e
|
|
238
|
+
Labimotion.log_exception(e, current_user)
|
|
239
|
+
raise e
|
|
240
|
+
end
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
# Deprecated: This namespace is no longer used, but kept for backward compatibility.
|
|
224
244
|
namespace :klasses_all do
|
|
225
245
|
desc 'get all klasses for admin function'
|
|
226
246
|
get do
|
|
@@ -266,7 +286,7 @@ module Labimotion
|
|
|
266
286
|
end
|
|
267
287
|
after_validation do
|
|
268
288
|
authenticate_admin!(params[:klass].gsub(/(Klass)/, 's').downcase)
|
|
269
|
-
|
|
289
|
+
fetch_klass(params[:klass], params[:id])
|
|
270
290
|
end
|
|
271
291
|
post do
|
|
272
292
|
deactivate_klass(params)
|
|
@@ -301,7 +321,7 @@ module Labimotion
|
|
|
301
321
|
end
|
|
302
322
|
after_validation do
|
|
303
323
|
authenticate_admin!(params[:klass].gsub(/(Klass)/, 's').downcase)
|
|
304
|
-
|
|
324
|
+
fetch_klass(params[:klass], params[:id])
|
|
305
325
|
end
|
|
306
326
|
post do
|
|
307
327
|
update_template(params, current_user)
|
|
@@ -6,6 +6,7 @@ require 'labimotion/libs/export_element'
|
|
|
6
6
|
module Labimotion
|
|
7
7
|
# Generic Element API
|
|
8
8
|
class GenericKlassAPI < Grape::API
|
|
9
|
+
helpers Labimotion::GenericHelpers
|
|
9
10
|
|
|
10
11
|
resource :generic_klass do
|
|
11
12
|
namespace :download_klass do
|
|
@@ -30,6 +31,44 @@ module Labimotion
|
|
|
30
31
|
end
|
|
31
32
|
end
|
|
32
33
|
|
|
34
|
+
namespace :de_activate do
|
|
35
|
+
desc 'activate or deactivate Generic Klass'
|
|
36
|
+
params do
|
|
37
|
+
requires :klass, type: String, desc: 'Klass', values: %w[ElementKlass SegmentKlass DatasetKlass]
|
|
38
|
+
requires :id, type: Integer, desc: 'Klass ID'
|
|
39
|
+
requires :is_active, type: Boolean, desc: 'Active or Inactive Klass'
|
|
40
|
+
end
|
|
41
|
+
after_validation do
|
|
42
|
+
authenticate_admin!(params[:klass].gsub(/(Klass)/, 's').downcase)
|
|
43
|
+
fetch_klass(params[:klass], params[:id])
|
|
44
|
+
end
|
|
45
|
+
post do
|
|
46
|
+
updated_klass = deactivate_klass(params)
|
|
47
|
+
entity_class = "Labimotion::#{params[:klass]}Entity".constantize
|
|
48
|
+
serialized_data = entity_class.represent(updated_klass)
|
|
49
|
+
{ mc: 'ss00', data: serialized_data }
|
|
50
|
+
rescue StandardError => e
|
|
51
|
+
Labimotion.log_exception(e, current_user)
|
|
52
|
+
{ mc: 'se00', msg: e.message, data: {} }
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
namespace :fetch do
|
|
57
|
+
desc 'fetch Generic Klass by id'
|
|
58
|
+
params do
|
|
59
|
+
requires :id, type: Integer, desc: 'Klass ID'
|
|
60
|
+
requires :klass, type: String, desc: 'Klass', values: %w[ElementKlass SegmentKlass DatasetKlass]
|
|
61
|
+
end
|
|
62
|
+
get do
|
|
63
|
+
klass_obj = fetch_klass(params[:klass], params[:id])
|
|
64
|
+
entity_class = "Labimotion::#{params[:klass]}Entity".constantize
|
|
65
|
+
serialized_data = entity_class.represent(klass_obj)
|
|
66
|
+
{ mc: 'ss00', data: serialized_data }
|
|
67
|
+
rescue StandardError => e
|
|
68
|
+
Labimotion.log_exception(e, current_user)
|
|
69
|
+
{ mc: 'se00', msg: e.message, data: {} }
|
|
70
|
+
end
|
|
71
|
+
end
|
|
33
72
|
end
|
|
34
73
|
end
|
|
35
|
-
end
|
|
74
|
+
end
|
|
@@ -11,24 +11,24 @@ module Labimotion
|
|
|
11
11
|
|
|
12
12
|
namespace :labimotion_hub do
|
|
13
13
|
namespace :list do
|
|
14
|
-
desc
|
|
14
|
+
desc "get active generic templates"
|
|
15
15
|
params do
|
|
16
|
-
requires :klass, type: String, desc: 'Klass', values:
|
|
16
|
+
requires :klass, type: String, desc: 'Klass', values: %w[ElementKlass SegmentKlass DatasetKlass]
|
|
17
17
|
optional :with_props, type: Boolean, desc: 'With Properties', default: false
|
|
18
18
|
end
|
|
19
19
|
get do
|
|
20
20
|
list = "Labimotion::#{params[:klass]}".constantize.where(is_active: true).where.not(released_at: nil)
|
|
21
|
-
list = list.where(is_generic: true) if params[:klass] ==
|
|
22
|
-
Labimotion::GenericPublicEntity.represent(list, displayed: params[:with_props], root: 'list')
|
|
21
|
+
list = list.where(is_generic: true) if params[:klass] == 'ElementKlass'
|
|
22
|
+
entities = Labimotion::GenericPublicEntity.represent(list, displayed: params[:with_props], root: 'list')
|
|
23
23
|
rescue StandardError => e
|
|
24
24
|
Labimotion.log_exception(e, current_user)
|
|
25
25
|
[]
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
28
|
namespace :fetch do
|
|
29
|
-
desc
|
|
29
|
+
desc "get active generic templates"
|
|
30
30
|
params do
|
|
31
|
-
requires :klass, type: String, desc: 'Klass', values:
|
|
31
|
+
requires :klass, type: String, desc: 'Klass', values: %w[ElementKlass SegmentKlass DatasetKlass]
|
|
32
32
|
requires :origin, type: String, desc: 'origin'
|
|
33
33
|
requires :identifier, type: String, desc: 'Identifier'
|
|
34
34
|
end
|
|
@@ -43,16 +43,13 @@ module Labimotion
|
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
namespace :element_klasses_name do
|
|
46
|
-
desc
|
|
46
|
+
desc "get klasses"
|
|
47
47
|
params do
|
|
48
|
-
optional :generic_only, type: Boolean, desc:
|
|
48
|
+
optional :generic_only, type: Boolean, desc: "list generic element only"
|
|
49
49
|
end
|
|
50
50
|
get do
|
|
51
|
-
if params[:generic_only].present? && params[:generic_only] == true
|
|
52
|
-
|
|
53
|
-
else
|
|
54
|
-
list = Labimotion::ElementKlass.where(is_active: true)
|
|
55
|
-
end
|
|
51
|
+
list = Labimotion::ElementKlass.where(is_active: true) if params[:generic_only].present? && params[:generic_only] == true
|
|
52
|
+
list = Labimotion::ElementKlass.where(is_active: true) unless params[:generic_only].present? && params[:generic_only] == true
|
|
56
53
|
list.pluck(:name)
|
|
57
54
|
rescue StandardError => e
|
|
58
55
|
Labimotion.log_exception(e, current_user)
|
|
@@ -60,76 +57,6 @@ module Labimotion
|
|
|
60
57
|
end
|
|
61
58
|
end
|
|
62
59
|
|
|
63
|
-
namespace :submit do
|
|
64
|
-
desc 'submit a template'
|
|
65
|
-
params do
|
|
66
|
-
requires :klass, type: String, desc: 'klass of the template',
|
|
67
|
-
values: Labimotion::Constants::Klass::ALL
|
|
68
|
-
requires :id, type: Integer, desc: 'template revision id'
|
|
69
|
-
requires :contact_email, type: String, desc: 'email of the submitter', regexp: URI::MailTo::EMAIL_REGEXP
|
|
70
|
-
requires :application, type: String, desc: 'application for the template'
|
|
71
|
-
requires :message, type: String, desc: 'message of the submission'
|
|
72
|
-
end
|
|
73
|
-
post do
|
|
74
|
-
klass = params[:klass]
|
|
75
|
-
template = "Labimotion::#{klass}esRevision".constantize.find(params[:id])
|
|
76
|
-
klass_data = "Labimotion::#{klass}Entity".constantize.represent(template.klass, displayed_in_list: true)
|
|
77
|
-
metadata = {
|
|
78
|
-
klass: {
|
|
79
|
-
klass: klass,
|
|
80
|
-
data: klass_data
|
|
81
|
-
},
|
|
82
|
-
submission: {
|
|
83
|
-
last_name: current_user.last_name,
|
|
84
|
-
first_name: current_user.first_name,
|
|
85
|
-
email: current_user.email,
|
|
86
|
-
id: current_user.id,
|
|
87
|
-
contact_email: params[:contact_email],
|
|
88
|
-
application: params[:application],
|
|
89
|
-
message: params[:message]
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
# Submit the main template
|
|
94
|
-
result = Labimotion::TemplateHub.send_to_central_hub(klass, template.properties_release, metadata,
|
|
95
|
-
request.headers['Origin'])
|
|
96
|
-
|
|
97
|
-
# Increment submitted counter if submission was successful
|
|
98
|
-
template.increment_submitted! if result[:mc] == 'ss00'
|
|
99
|
-
|
|
100
|
-
# For SegmentKlass, also submit the associated ElementKlass
|
|
101
|
-
if klass == Labimotion::Constants::Klass::SEGMENT && result[:mc] == 'ss00'
|
|
102
|
-
element_klass = template.klass.element_klass
|
|
103
|
-
element_klass_data = Labimotion::ElementKlassEntity.represent(element_klass, displayed_in_list: true)
|
|
104
|
-
element_metadata = {
|
|
105
|
-
klass: {
|
|
106
|
-
klass: Labimotion::Constants::Klass::ELEMENT,
|
|
107
|
-
data: element_klass_data
|
|
108
|
-
},
|
|
109
|
-
submission: metadata[:submission].merge(
|
|
110
|
-
associated_submission_id: result[:data][:id]
|
|
111
|
-
)
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
element_result = Labimotion::TemplateHub.send_to_central_hub(Labimotion::Constants::Klass::ELEMENT,
|
|
115
|
-
element_klass.properties_release,
|
|
116
|
-
element_metadata, request.headers['Origin'])
|
|
117
|
-
|
|
118
|
-
# Increment the ElementKlass revision counter if submission was successful
|
|
119
|
-
if element_result[:mc] == 'ss00'
|
|
120
|
-
# Find the revision that matches the ElementKlass UUID
|
|
121
|
-
element_revision = Labimotion::ElementKlassesRevision.find_by(uuid: element_klass.uuid)
|
|
122
|
-
element_revision&.increment_submitted!
|
|
123
|
-
end
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
# Only return the main result; TODO: handle element_result as well
|
|
127
|
-
result
|
|
128
|
-
rescue StandardError => e
|
|
129
|
-
Labimotion.log_exception(e, current_user)
|
|
130
|
-
{ mc: 'se00', msg: e.message, data: [] }
|
|
131
|
-
end
|
|
132
|
-
end
|
|
133
60
|
end
|
|
134
61
|
end
|
|
135
62
|
end
|
|
@@ -12,19 +12,21 @@ module Labimotion
|
|
|
12
12
|
optional :element, type: String, desc: "Klass Element, e.g. Sample, Reaction, Mof,..."
|
|
13
13
|
end
|
|
14
14
|
get do
|
|
15
|
-
list = klass_list(params[:element], true)
|
|
15
|
+
list = klass_list(params[:element], true, false)
|
|
16
16
|
present list, with: Labimotion::SegmentKlassEntity, root: 'klass'
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
+
# TODO: params[:displayed_in_list] will be used in the future to control the display format, set 'false' for now.
|
|
20
21
|
namespace :list_segment_klass do
|
|
21
22
|
desc 'list Generic Segment Klass'
|
|
22
23
|
params do
|
|
23
24
|
optional :is_active, type: Boolean, desc: 'Active or Inactive Segment'
|
|
25
|
+
optional :displayed_in_list, type: Boolean, desc: 'Display in list format', default: false
|
|
24
26
|
end
|
|
25
27
|
get do
|
|
26
|
-
list = klass_list(nil, params[:is_active])
|
|
27
|
-
present list, with: Labimotion::SegmentKlassEntity, root: 'klass'
|
|
28
|
+
list = klass_list(nil, params[:is_active], false)
|
|
29
|
+
present list, with: Labimotion::SegmentKlassEntity, root: 'klass', displayed_in_list: false
|
|
28
30
|
end
|
|
29
31
|
end
|
|
30
32
|
|
data/lib/labimotion/constants.rb
CHANGED
|
@@ -21,12 +21,5 @@ module Labimotion
|
|
|
21
21
|
NMR_CONFIG = ::File.join(__dir__, 'libs', 'data', 'mapper', 'Source.json').freeze
|
|
22
22
|
WIKI_CONFIG = ::File.join(__dir__, 'libs', 'data', 'mapper', 'Chemwiki.json').freeze
|
|
23
23
|
end
|
|
24
|
-
|
|
25
|
-
module Klass
|
|
26
|
-
ELEMENT = 'ElementKlass'
|
|
27
|
-
SEGMENT = 'SegmentKlass'
|
|
28
|
-
DATASET = 'DatasetKlass'
|
|
29
|
-
ALL = [ELEMENT, SEGMENT, DATASET].freeze
|
|
30
|
-
end
|
|
31
24
|
end
|
|
32
25
|
end
|
|
@@ -1,88 +1,15 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
module Labimotion
|
|
4
4
|
## ApplicationEntity
|
|
5
|
-
class
|
|
6
|
-
|
|
5
|
+
# This class serves as the base entity for the Labimotion module,
|
|
6
|
+
# inheriting from the core ApplicationEntity and providing custom formatting.
|
|
7
|
+
class ApplicationEntity < ::Entities::ApplicationEntity
|
|
8
|
+
# Common condition for fields that should not be displayed in list views
|
|
9
|
+
DISPLAYED_IN_LIST_CONDITION = { unless: :displayed_in_list }.freeze
|
|
7
10
|
|
|
8
11
|
format_with(:eln_timestamp) do |datetime|
|
|
9
|
-
datetime.present? ? datetime
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def self.expose!(*args)
|
|
13
|
-
fields = args.first
|
|
14
|
-
options = args.last.is_a?(Hash) ? args.pop : {}
|
|
15
|
-
options = merge_options(options) # merges additional params set in #with_options
|
|
16
|
-
expose_fields_with_anonymization!(fields, options)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
# rubocop:disable Metrics/MethodLength
|
|
20
|
-
def self.expose_fields_with_anonymization!(fields, options)
|
|
21
|
-
anonymize_below = options[:anonymize_below] || 0
|
|
22
|
-
anonymize_with = options.key?(:anonymize_with) ? options[:anonymize_with] : '***'
|
|
23
|
-
|
|
24
|
-
Array(fields).each do |field|
|
|
25
|
-
expose(field, options) do |represented_object, _options|
|
|
26
|
-
if detail_levels[represented_object.class] < anonymize_below
|
|
27
|
-
anonymize_with
|
|
28
|
-
elsif respond_to?(field, true) # Entity has a method with the same name
|
|
29
|
-
send(field)
|
|
30
|
-
elsif represented_object.respond_to?(field)
|
|
31
|
-
represented_object.public_send(field)
|
|
32
|
-
else
|
|
33
|
-
represented_object[field] # works both for AR and Hash objects
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
private_class_method :expose_fields_with_anonymization!
|
|
39
|
-
# rubocop:enable Metrics/MethodLength
|
|
40
|
-
|
|
41
|
-
def self.expose_timestamps(timestamp_fields: %i[created_at updated_at], **additional_args)
|
|
42
|
-
timestamp_fields.each do |field|
|
|
43
|
-
expose field, format_with: :eln_timestamp, **additional_args
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
# overridden method from Grape::Entity to support our custom anonymization options
|
|
48
|
-
# https://github.com/ruby-grape/grape-entity/blob/v0.7.1/lib/grape_entity/entity.rb#L565
|
|
49
|
-
def self.valid_options(options)
|
|
50
|
-
options.each_key do |key|
|
|
51
|
-
next if OPTIONS.include?(key) || CUSTOM_ENTITY_OPTIONS.include?(key)
|
|
52
|
-
|
|
53
|
-
raise ArgumentError, "#{key.inspect} is not a valid option."
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
options[:using] = options.delete(:with) if options.key?(:with)
|
|
57
|
-
options
|
|
58
|
-
end
|
|
59
|
-
private_class_method :valid_options
|
|
60
|
-
|
|
61
|
-
private
|
|
62
|
-
|
|
63
|
-
def displayed_in_list?
|
|
64
|
-
options[:displayed_in_list] == true
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
def current_user
|
|
68
|
-
unless options[:current_user]
|
|
69
|
-
raise MissingCurrentUserError, "#{self.class} requires a current user to work properly"
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
options[:current_user]
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
def detail_levels
|
|
76
|
-
maximal_default_levels = Hash.new(10) # every requested detail level will be returned as 10
|
|
77
|
-
minimal_default_levels = Hash.new(0) # every requested detail level will be returned as 0
|
|
78
|
-
return maximal_default_levels if !options.key?(:detail_levels) || options[:detail_levels].empty?
|
|
79
|
-
|
|
80
|
-
# When explicitly configured detail levels are available, we want to return only those and all other
|
|
81
|
-
# requests (by using `detail_levels[SomeUnconfiguredModel]`) should return the minimum detail level
|
|
82
|
-
minimal_default_levels.merge(options[:detail_levels])
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
class MissingCurrentUserError < StandardError
|
|
12
|
+
datetime.present? ? datetime.strftime('%Y-%m-%d %H:%M:%S %Z') : nil
|
|
86
13
|
end
|
|
87
14
|
end
|
|
88
15
|
end
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
require 'labimotion/entities/application_entity'
|
|
4
|
+
require 'labimotion/entities/properties_entity'
|
|
4
5
|
module Labimotion
|
|
5
6
|
# Dataset entity
|
|
6
|
-
class DatasetEntity < PropertiesEntity
|
|
7
|
-
expose :id, :dataset_klass_id, :
|
|
7
|
+
class DatasetEntity < Labimotion::PropertiesEntity
|
|
8
|
+
expose :id, :dataset_klass_id, :element_id, :element_type
|
|
9
|
+
expose :klass_ols, :klass_label, :klass_uuid
|
|
10
|
+
expose :properties, **DISPLAYED_IN_LIST_CONDITION, anonymize_with: {}
|
|
11
|
+
expose :properties_release, **DISPLAYED_IN_LIST_CONDITION, anonymize_with: {}
|
|
12
|
+
|
|
8
13
|
def klass_ols
|
|
9
14
|
object&.dataset_klass&.ols_term_id
|
|
10
15
|
end
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
|
|
2
3
|
require 'labimotion/entities/generic_klass_entity'
|
|
3
4
|
module Labimotion
|
|
4
|
-
class DatasetKlassEntity < GenericKlassEntity
|
|
5
|
+
class DatasetKlassEntity < Labimotion::GenericKlassEntity
|
|
5
6
|
expose(
|
|
6
|
-
:ols_term_id
|
|
7
|
+
:ols_term_id
|
|
7
8
|
)
|
|
8
9
|
end
|
|
9
10
|
end
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
require 'labimotion/entities/properties_entity'
|
|
4
4
|
## TODO: Refactor labimotion to use the same entities as chemotion
|
|
5
5
|
module Labimotion
|
|
6
|
-
class ElementEntity < PropertiesEntity
|
|
6
|
+
class ElementEntity < Labimotion::PropertiesEntity
|
|
7
7
|
with_options(anonymize_below: 0) do
|
|
8
8
|
expose! :can_copy, unless: :displayed_in_list
|
|
9
9
|
expose! :can_publish, unless: :displayed_in_list
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
require 'labimotion/entities/generic_klass_entity'
|
|
4
4
|
|
|
5
5
|
module Labimotion
|
|
6
6
|
# ElementKlassEntity
|
|
7
|
-
class ElementKlassEntity < GenericKlassEntity
|
|
7
|
+
class ElementKlassEntity < Labimotion::GenericKlassEntity
|
|
8
8
|
expose :name, :icon_name, :klass_prefix, :is_generic
|
|
9
9
|
end
|
|
10
10
|
end
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
require 'labimotion/entities/application_entity'
|
|
4
4
|
module Labimotion
|
|
5
5
|
# ElementRevisionEntity
|
|
6
|
-
class ElementRevisionEntity < ApplicationEntity
|
|
6
|
+
class ElementRevisionEntity < Labimotion::ApplicationEntity
|
|
7
7
|
expose :id, :element_id, :uuid, :name, :klass_uuid, :properties, :created_at
|
|
8
8
|
def created_at
|
|
9
9
|
object.created_at.strftime('%d.%m.%Y, %H:%M')
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
require 'labimotion/entities/application_entity'
|
|
4
4
|
module Labimotion
|
|
5
5
|
## ElementEntity
|
|
6
|
-
class ElnElementEntity < ApplicationEntity
|
|
6
|
+
class ElnElementEntity < Labimotion::ApplicationEntity
|
|
7
7
|
with_options(anonymize_below: 0) do
|
|
8
8
|
expose! :created_by
|
|
9
9
|
expose! :id
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
require 'labimotion/entities/application_entity'
|
|
4
4
|
module Labimotion
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
expose :
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
expose_timestamps(timestamp_fields: [
|
|
12
|
-
expose_timestamps(timestamp_fields: [:sync_time])
|
|
5
|
+
class GenericKlassEntity < Labimotion::ApplicationEntity
|
|
6
|
+
expose :id, :uuid, :label, :desc, :is_active, :version, :place
|
|
7
|
+
expose :released_at, :identifier, :sync_time
|
|
8
|
+
|
|
9
|
+
expose :properties_template, **DISPLAYED_IN_LIST_CONDITION, anonymize_with: {}
|
|
10
|
+
expose :properties_release, **DISPLAYED_IN_LIST_CONDITION, anonymize_with: {}
|
|
11
|
+
expose_timestamps(timestamp_fields: %i[released_at created_at updated_at sync_time])
|
|
13
12
|
end
|
|
14
13
|
end
|
|
@@ -10,15 +10,17 @@ module Labimotion
|
|
|
10
10
|
expose! :desc
|
|
11
11
|
expose! :icon_name
|
|
12
12
|
expose! :klass_prefix
|
|
13
|
-
expose
|
|
13
|
+
expose :klass_name do |obj|
|
|
14
|
+
obj[:name] || ''
|
|
15
|
+
end
|
|
14
16
|
expose! :label
|
|
15
17
|
expose! :identifier
|
|
16
18
|
expose! :version
|
|
17
19
|
expose! :released_at
|
|
18
|
-
expose
|
|
20
|
+
expose :properties_release, **DISPLAYED_IN_LIST_CONDITION, anonymize_with: {}
|
|
19
21
|
expose :element_klass do |obj|
|
|
20
22
|
if obj[:element_klass_id]
|
|
21
|
-
{ :
|
|
23
|
+
{ label: obj.element_klass.label, icon_name: obj.element_klass.icon_name, id: obj.element_klass_id }
|
|
22
24
|
else
|
|
23
25
|
{}
|
|
24
26
|
end
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'labimotion/entities/application_entity'
|
|
3
4
|
module Labimotion
|
|
5
|
+
# KlassRevisionEntity
|
|
4
6
|
class KlassRevisionEntity < Labimotion::ApplicationEntity
|
|
5
|
-
expose :id, :uuid, :
|
|
6
|
-
expose :properties_release, **DISPLAYED_IN_LIST_CONDITION, anonymize_with: {}
|
|
7
|
+
expose :id, :uuid, :properties_release, :version, :released_at
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
object.
|
|
9
|
+
expose :klass_id do |object|
|
|
10
|
+
klass_id = object.element_klass_id if object.respond_to? :element_klass_id
|
|
11
|
+
klass_id = object.segment_klass_id if object.respond_to? :segment_klass_id
|
|
12
|
+
klass_id = object.dataset_klass_id if object.respond_to? :dataset_klass_id
|
|
13
|
+
klass_id
|
|
10
14
|
end
|
|
11
15
|
|
|
12
16
|
def released_at
|
|
@@ -14,3 +18,4 @@ module Labimotion
|
|
|
14
18
|
end
|
|
15
19
|
end
|
|
16
20
|
end
|
|
21
|
+
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require 'labimotion/entities/application_entity'
|
|
4
|
+
require 'labimotion/entities/properties_entity'
|
|
4
5
|
module Labimotion
|
|
5
6
|
## Segment entity
|
|
6
|
-
class SegmentEntity < PropertiesEntity
|
|
7
|
-
expose :id, :segment_klass_id, :element_type, :element_id, :
|
|
7
|
+
class SegmentEntity < Labimotion::PropertiesEntity
|
|
8
|
+
expose :id, :segment_klass_id, :element_type, :element_id, :uuid, :klass_uuid, :klass_label
|
|
9
|
+
expose :properties, **DISPLAYED_IN_LIST_CONDITION, anonymize_with: {}
|
|
10
|
+
expose :properties_release, **DISPLAYED_IN_LIST_CONDITION, anonymize_with: {}
|
|
8
11
|
|
|
9
12
|
def klass_label
|
|
10
13
|
object.segment_klass.label
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
require 'labimotion/entities/application_entity'
|
|
4
4
|
module Labimotion
|
|
5
|
-
class SegmentRevisionEntity < ApplicationEntity
|
|
5
|
+
class SegmentRevisionEntity < Labimotion::ApplicationEntity
|
|
6
6
|
expose :id, :segment_id, :uuid, :klass_uuid, :properties, :created_at
|
|
7
7
|
def created_at
|
|
8
8
|
object.created_at.strftime('%d.%m.%Y, %H:%M')
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
require 'labimotion/entities/application_entity'
|
|
4
4
|
module Labimotion
|
|
5
5
|
# Dataset entity
|
|
6
|
-
class VocabularyEntity < ApplicationEntity
|
|
6
|
+
class VocabularyEntity < Labimotion::ApplicationEntity
|
|
7
7
|
expose :id, :identifier, :name, :label, :field_type, :opid, :term_id,
|
|
8
8
|
:field_id, :properties, :source, :source_id, :layer_id
|
|
9
9
|
expose :voc do |obj|
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
|
|
2
3
|
require 'grape'
|
|
3
4
|
module Labimotion
|
|
4
|
-
|
|
5
|
+
## DatasetHelpers
|
|
5
6
|
module DatasetHelpers
|
|
6
7
|
extend Grape::API::Helpers
|
|
7
8
|
|
|
8
|
-
def klass_list(is_active)
|
|
9
|
+
def klass_list(is_active, displayed_in_list = false)
|
|
10
|
+
scope = displayed_in_list ? Labimotion::DatasetKlass.for_list_display : Labimotion::DatasetKlass.all
|
|
9
11
|
if is_active == true
|
|
10
|
-
|
|
12
|
+
scope.where(is_active: true).order('place') || []
|
|
11
13
|
else
|
|
12
|
-
|
|
14
|
+
scope.order('place') || []
|
|
13
15
|
end
|
|
14
16
|
end
|
|
15
17
|
|