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.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/lib/labimotion/apis/generic_dataset_api.rb +20 -3
  3. data/lib/labimotion/apis/generic_element_api.rb +22 -2
  4. data/lib/labimotion/apis/generic_klass_api.rb +40 -1
  5. data/lib/labimotion/apis/labimotion_api.rb +1 -3
  6. data/lib/labimotion/apis/labimotion_hub_api.rb +10 -83
  7. data/lib/labimotion/apis/segment_api.rb +5 -3
  8. data/lib/labimotion/constants.rb +0 -7
  9. data/lib/labimotion/entities/application_entity.rb +7 -80
  10. data/lib/labimotion/entities/dataset_entity.rb +8 -3
  11. data/lib/labimotion/entities/dataset_klass_entity.rb +3 -2
  12. data/lib/labimotion/entities/element_entity.rb +1 -1
  13. data/lib/labimotion/entities/element_klass_entity.rb +2 -2
  14. data/lib/labimotion/entities/element_revision_entity.rb +1 -1
  15. data/lib/labimotion/entities/eln_element_entity.rb +2 -2
  16. data/lib/labimotion/entities/generic_klass_entity.rb +8 -9
  17. data/lib/labimotion/entities/generic_public_entity.rb +5 -3
  18. data/lib/labimotion/entities/klass_revision_entity.rb +9 -4
  19. data/lib/labimotion/entities/properties_entity.rb +1 -0
  20. data/lib/labimotion/entities/segment_entity.rb +5 -2
  21. data/lib/labimotion/entities/segment_revision_entity.rb +2 -2
  22. data/lib/labimotion/entities/vocabulary_entity.rb +2 -2
  23. data/lib/labimotion/helpers/dataset_helpers.rb +6 -4
  24. data/lib/labimotion/helpers/element_helpers.rb +6 -4
  25. data/lib/labimotion/helpers/segment_helpers.rb +2 -2
  26. data/lib/labimotion/libs/data/mapper/Chemwiki.json +2 -2
  27. data/lib/labimotion/libs/properties_handler.rb +10 -0
  28. data/lib/labimotion/libs/template_hub.rb +10 -28
  29. data/lib/labimotion/libs/vocabulary_handler.rb +8 -6
  30. data/lib/labimotion/models/concerns/datasetable.rb +3 -3
  31. data/lib/labimotion/models/concerns/generic_klass.rb +16 -0
  32. data/lib/labimotion/models/concerns/segmentable.rb +44 -7
  33. data/lib/labimotion/models/dataset_klass.rb +15 -2
  34. data/lib/labimotion/models/dataset_klasses_revision.rb +1 -4
  35. data/lib/labimotion/models/element.rb +7 -1
  36. data/lib/labimotion/models/element_klass.rb +10 -1
  37. data/lib/labimotion/models/element_klasses_revision.rb +2 -3
  38. data/lib/labimotion/models/segment_klass.rb +10 -4
  39. data/lib/labimotion/models/segment_klasses_revision.rb +1 -4
  40. data/lib/labimotion/version.rb +2 -2
  41. metadata +5 -7
  42. data/lib/labimotion/libs/data/layer/StdDataset.json +0 -212
  43. data/lib/labimotion/models/concerns/klass_revision.rb +0 -23
  44. data/lib/labimotion/models/template_submission.rb +0 -52
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 27be8adb524b2f909b6b63a93395c828b5c95af139fc7babc6e0d80a014f7fd1
4
- data.tar.gz: 7bfbbd295d0c9147e52eef054e96575a312edefdc4b999b8a5adda3e2b3afb8c
3
+ metadata.gz: dc6bf6015a4c970c7f2bd3e3d6e1a2dfb334e6acc4c53f255c5ef7cb912b6b1e
4
+ data.tar.gz: c8d7fda79cb1e3967a884b7ebd53db0f08eb90777ec0f78e58cabada98038f82
5
5
  SHA512:
6
- metadata.gz: 5ab9fcec0f65c23cfb02df0248b0ae2c83311ef92d56051d5eb577c60d43dd34071f4a51040565ce18516fc3560882fd041a9f7ea88ab815ffbb797828aa48f8
7
- data.tar.gz: b90813c81ba3d4ba60b3b60a6e62ac8af96b53caf20efc61a57098725366d256f7c54a252b6a802fac522a92e7eb524e960030fbb07f6fbb4943cbd0bcb508ad
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
- @klz = fetch_klass(params[:klass], params[:id])
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
- @klz = fetch_klass(params[:klass], params[:id])
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
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  # app/api/labimotion/central_api.rb
4
2
  module Labimotion
5
3
  class LabimotionAPI < Grape::API
@@ -12,4 +10,4 @@ module Labimotion
12
10
  mount Labimotion::StandardLayerAPI
13
11
  mount Labimotion::VocabularyAPI
14
12
  end
15
- end
13
+ end
@@ -11,24 +11,24 @@ module Labimotion
11
11
 
12
12
  namespace :labimotion_hub do
13
13
  namespace :list do
14
- desc 'get active generic templates'
14
+ desc "get active generic templates"
15
15
  params do
16
- requires :klass, type: String, desc: 'Klass', values: Labimotion::Constants::Klass::ALL
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] == Labimotion::Constants::Klass::ELEMENT
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 'get active generic templates'
29
+ desc "get active generic templates"
30
30
  params do
31
- requires :klass, type: String, desc: 'Klass', values: Labimotion::Constants::Klass::ALL
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 'get klasses'
46
+ desc "get klasses"
47
47
  params do
48
- optional :generic_only, type: Boolean, desc: 'list generic element only'
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
- list = Labimotion::ElementKlass.where(is_active: true, is_generic: true)
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
 
@@ -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 ApplicationEntity < Grape::Entity
6
- CUSTOM_ENTITY_OPTIONS = %i[anonymize_below anonymize_with].freeze
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&.strftime('%Y-%m-%d %H:%M:%S %Z') : nil
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, :properties, :properties_release, :element_id, :element_type, :klass_ols, :klass_label, :klass_uuid
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
- # GenericKlassEntity
6
- class GenericKlassEntity < ApplicationEntity
7
- expose :id, :uuid, :label, :desc, :properties_template, :properties_release, :is_active, :version,
8
- :place, :released_at, :identifier, :sync_time, :created_by, :updated_by, :created_at, :updated_at
9
- expose_timestamps(timestamp_fields: [:released_at])
10
- expose_timestamps(timestamp_fields: [:created_at])
11
- expose_timestamps(timestamp_fields: [:updated_at])
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! :klass_name
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! :properties_release, if: :displayed
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
- { :label => obj.element_klass.label, :icon_name => obj.element_klass.icon_name }
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, :version, :released_at, :klass_id, :submitted
6
- expose :properties_release, **DISPLAYED_IN_LIST_CONDITION, anonymize_with: {}
7
+ expose :id, :uuid, :properties_release, :version, :released_at
7
8
 
8
- def klass_id
9
- object.klass&.id
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,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'labimotion/entities/application_entity'
2
3
 
3
4
  module Labimotion
@@ -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, :properties, :properties_release, :uuid, :klass_uuid, :klass_label
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
- ## DatasetHelpers
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
- Labimotion::DatasetKlass.where(is_active: true).order('place') || []
12
+ scope.where(is_active: true).order('place') || []
11
13
  else
12
- Labimotion::DatasetKlass.all.order('place') || []
14
+ scope.order('place') || []
13
15
  end
14
16
  end
15
17