labimotion 1.4.0.2 → 1.5.0.rc2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5564b71b1b531e05ab523719dbd1a052c19828c86921f17381ca545554f2c514
4
- data.tar.gz: ee3b1e84d1aff2619a9ab65901c0f6c20af7288b3b6ef6f7ec49843dd78a543e
3
+ metadata.gz: 8c27e1abca5ba7bf25eb28196a873d27529c9f15a642c68359f548ab8908eb53
4
+ data.tar.gz: 2aec966843e9e8e1665afd6e6c874965bb7790d7a919802bb942c06548ce602a
5
5
  SHA512:
6
- metadata.gz: a8cfa29e6fbc0ed90c8bec7e581286f2921c461c0ba8fd9b957d98cd88287630f46fe86ab7f86404afd4379623e66296e23e858746b050b66ad76f3290799792
7
- data.tar.gz: af817bdab6d263afbb26b9efb7313ab505d3b56727e97b7c31149f139bfe6c45b26650ebcabc4614a4e367ff10f6719ffbedb6b9c5acae580c301a50c5379f15
6
+ metadata.gz: 4e7c44330b99cb08d05a3f2402566bd6cde2e384d917e9a9ebd19963f5261ea8e08422d932b11d551b81e23b9c202896ab169091fd680eb962b1d6deb4f9a902
7
+ data.tar.gz: c7fb2ab0e3eead1f32601ad3b4b952ad9d45e56540f9add8e7520eb6790bc464a6778d515e002d6050dfd5f7b0b85fdac7a22bf6a06b5c3c7111d9a64cc6e9be
@@ -12,6 +12,7 @@ module Labimotion
12
12
  helpers CollectionHelpers
13
13
  helpers UserLabelHelpers
14
14
  helpers Labimotion::SampleAssociationHelpers
15
+ helpers Labimotion::VocabularyHelpers
15
16
  helpers Labimotion::GenericHelpers
16
17
  helpers Labimotion::ElementHelpers
17
18
  helpers Labimotion::ParamHelpers
@@ -6,7 +6,7 @@ require 'labimotion/libs/export_element'
6
6
  module Labimotion
7
7
  # Generic Element API
8
8
  class GenericKlassAPI < Grape::API
9
-
9
+
10
10
  resource :generic_klass do
11
11
  namespace :download_klass do
12
12
  desc 'export klass'
@@ -28,7 +28,8 @@ module Labimotion
28
28
  Labimotion.log_exception(e, current_user)
29
29
  {}
30
30
  end
31
- end
31
+ end
32
+
32
33
  end
33
34
  end
34
35
  end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'labimotion/version'
4
+ require 'labimotion/libs/export_element'
5
+
6
+ module Labimotion
7
+ # Generic Element API
8
+ class StandardAPI < Grape::API
9
+ resource :standards do
10
+ namespace :create_std_layer do
11
+ desc 'create standard layer'
12
+ params do
13
+ use :create_std_layer_params
14
+ end
15
+ post do
16
+ # authenticate_admin!('elements')
17
+ # create_element_klass(current_user, params)
18
+ create_std_layer(current_user, params)
19
+ status 201
20
+ rescue ActiveRecord::RecordInvalid => e
21
+ { error: e.message }
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,100 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'labimotion/version'
4
+
5
+ module Labimotion
6
+ # Generic Element API
7
+ class StandardLayerAPI < Grape::API
8
+ include Grape::Kaminari
9
+ helpers Labimotion::ParamHelpers
10
+
11
+ resource :layers do
12
+ namespace :get_all_layers do
13
+ desc 'get all standard layers for designer'
14
+ get do
15
+ list = Labimotion::StdLayer.all.sort_by { |e| e.name }
16
+ # present list, with: Labimotion::StdLayer, root: 'klass'
17
+ # data = Labimotion::StdLayer.represent(col_tree, serializable: true)
18
+ return { mc: 'ss00', data: list }
19
+ rescue StandardError => e
20
+ Labimotion.log_exception(e, current_user)
21
+ { mc: 'se00', msg: e.message, data: [] }
22
+ end
23
+ end
24
+
25
+ namespace :get_standard_layer do
26
+ desc 'get standard layer by id'
27
+ # params do
28
+ # requires :id, type: Integer, desc: 'Layer id'
29
+ # end
30
+ route_param :id do
31
+ before do
32
+ # @element_policy = ElementPolicy.new(current_user, Labimotion::Element.find(params[:id]))
33
+ # error!('401 Unauthorized', 401) unless current_user.matrix_check_by_name('genericElement') && @element_policy.read?
34
+ # rescue ActiveRecord::RecordNotFound
35
+ # error!('404 Not Found', 404)
36
+ end
37
+ get do
38
+ entity = Labimotion::StdLayer.find(params[:id])
39
+ return { mc: 'ss00', data: entity }
40
+ rescue StandardError => e
41
+ Labimotion.log_exception(e, current_user)
42
+ { mc: 'se00', msg: e.message, data: {} }
43
+ end
44
+ end
45
+ end
46
+
47
+ namespace :save_standard_layer do
48
+ desc 'create Generic Element Klass'
49
+ params do
50
+ use :std_layer_save
51
+ end
52
+ before do
53
+ cur_layer = Labimotion::StdLayer.find_by(name: params[:key])
54
+ error!('Error! duplicate name', 409) if cur_layer.present?
55
+ # @element_policy = ElementPolicy.new(current_user, Labimotion::Element.find(params[:id]))
56
+ # error!('401 Unauthorized', 401) unless current_user.matrix_check_by_name('genericElement') && @element_policy.read?
57
+ # rescue ActiveRecord::RecordNotFound
58
+ # Labimotion.log_exception(e, current_user)
59
+ # error!('404 Not Found', 404)
60
+ end
61
+ post do
62
+ attributes = {
63
+ name: params[:key],
64
+ label: params[:label],
65
+ description: params[:description],
66
+ identifier: SecureRandom.uuid,
67
+ created_by: current_user.id,
68
+ properties: declared(params, include_missing: false)
69
+ }
70
+ layer = Labimotion::StdLayer.new(attributes)
71
+ layer.save!
72
+ { mc: 'ss00', data: layer }
73
+ rescue ActiveRecord::RecordInvalid => e
74
+ Labimotion.log_exception(e, current_user)
75
+ { mc: 'se00', msg: e.message, data: {} }
76
+ end
77
+ end
78
+
79
+ namespace :delete_standard_layer do
80
+ desc 'delete standard layer by id'
81
+ params do
82
+ requires :id, type: Integer, desc: 'Standard layer id'
83
+ end
84
+ route_param :id do
85
+ before do
86
+ # error!('401 Unauthorized', 401) unless ElementPolicy.new(current_user, StdLayer.find(params[:id])).destroy?
87
+ end
88
+ delete do
89
+ entity = Labimotion::StdLayer.find(params[:id])
90
+ entity.destroy
91
+ return { mc: 'ss00', data: {} }
92
+ rescue StandardError => e
93
+ Labimotion.log_exception(e, current_user)
94
+ { mc: 'se00', msg: e.message, data: [] }
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
@@ -9,32 +9,102 @@ module Labimotion
9
9
  helpers Labimotion::ParamHelpers
10
10
 
11
11
  resource :vocab do
12
- namespace :save do
12
+ namespace :save_vocabulary do
13
13
  desc 'Save vocabularies'
14
14
  params do
15
- use :std_layer_save
15
+ use :vocab_save
16
16
  end
17
17
  before do
18
+ # error!('Error! duplicate record', 409) if ???.present?
18
19
  rescue ActiveRecord::RecordNotFound
19
20
  error!('404 Not Found', 404)
20
21
  end
21
22
  post do
22
- rescue ActiveRecord::RecordInvalid => e
23
- { error: e.message }
23
+ attributes = {
24
+ name: params[:name],
25
+ label: params[:label],
26
+ field_type: params[:field_type],
27
+ opid: 8,
28
+ term_id: params[:term_id],
29
+ source: params[:source],
30
+ source_id: params[:source_id],
31
+ layer_id: params[:layer_id],
32
+ field_id: params[:name],
33
+ identifier: params[:source_id],
34
+ created_by: current_user.id,
35
+ properties: declared(params, include_missing: false),
36
+ }
37
+ voc = Labimotion::Vocabulary.new(attributes)
38
+ voc.save!
39
+ { mc: 'ss00', data: voc }
40
+ rescue StandardError => e
41
+ Labimotion.log_exception(e, current_user)
42
+ { mc: 'se00', msg: e.message, data: {} }
43
+ end
44
+ end
45
+
46
+ namespace :get_all_vocabularies do
47
+ desc 'get all standard layers for designer'
48
+ get do
49
+ # merged_data = []
50
+ # Dir.glob(Rails.public_path.join('generic', 'vocabularies', '*.json')).each do |file_path|
51
+ merged_data = []
52
+ Dir.glob(Rails.public_path.join('generic', 'vocabularies', '*.json')).each do |file_path|
53
+ file_content = File.read(file_path)
54
+ json_data = JSON.parse(file_content)
55
+ merged_data.concat(json_data)
56
+ end
57
+
58
+ list = Labimotion::Vocabulary.all.sort_by { |e| e.name }
59
+ data = Labimotion::VocabularyEntity.represent(list, serializable: true)
60
+ combined_data = merged_data + data
61
+ return { mc: 'ss00', data: combined_data }
62
+ rescue StandardError => e
63
+ Labimotion.log_exception(e, current_user)
64
+ { mc: 'se00', msg: e.message, data: [] }
24
65
  end
25
66
  end
26
67
 
27
68
  namespace :field_klasses do
28
69
  desc 'get all field klasses for admin function'
29
70
  get do
30
- list = Labimotion::Vocabulary.all.sort_by { |e| e.name }
31
- present list, with: Labimotion::VocabularyEntity, root: 'klass'
71
+ # Dir.glob(Rails.public_path.join('generic', 'vocabularies', '*.json')).each do |file_path|
72
+ # file_content = File.read(file_path)
73
+ # json_data = JSON.parse(file_content)
74
+ # merged_data.concat(json_data)
75
+ # end
76
+ vocabularies = Labimotion::VocabularyHandler.load_app_vocabularies
77
+ merged_data = Labimotion::FieldKlassEntity.represent(vocabularies, serializable: true)
78
+ # byebug
79
+ # list = Labimotion::Vocabulary.all.sort_by { |e| e.name }
80
+ # present list, with: Labimotion::VocabularyEntity, root: 'klass'
81
+ # byebug
82
+ merged_data
32
83
  rescue StandardError => e
33
84
  Labimotion.log_exception(e, current_user)
34
85
  []
35
86
  end
36
87
  end
37
88
 
89
+ namespace :delete_vocabulary do
90
+ desc 'delete vocabulary by id'
91
+ params do
92
+ requires :id, type: Integer, desc: 'Vocabulary id'
93
+ end
94
+ route_param :id do
95
+ before do
96
+ # error!('401 Unauthorized', 401) unless ElementPolicy.new(current_user, Vocabulary.find(params[:id])).destroy?
97
+ end
98
+ delete do
99
+ entity = Labimotion::Vocabulary.find(params[:id])
100
+ entity.destroy
101
+ return { mc: 'ss00', data: {} }
102
+ rescue StandardError => e
103
+ Labimotion.log_exception(e, current_user)
104
+ { mc: 'se00', msg: e.message, data: [] }
105
+ end
106
+ end
107
+ end
38
108
  end
39
109
  end
40
- end
110
+ end
@@ -3,7 +3,7 @@
3
3
  require 'labimotion/entities/application_entity'
4
4
  module Labimotion
5
5
  # Dataset entity
6
- class DatasetEntity < ApplicationEntity
6
+ class DatasetEntity < PropertiesEntity
7
7
  expose :id, :dataset_klass_id, :properties, :properties_release, :element_id, :element_type, :klass_ols, :klass_label, :klass_uuid
8
8
  def klass_ols
9
9
  object&.dataset_klass&.ols_term_id
@@ -8,6 +8,27 @@ module Labimotion
8
8
  def properties
9
9
  (object&.properties.is_a?(Hash) && object.properties[Labimotion::Prop::LAYERS]&.keys || []).each do |key|
10
10
  # layer = object.properties[key]
11
+
12
+ # field_vocabularies = object.properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS].select { |ss| ss['is_vocabulary'] == true}
13
+ # field_vocabularies.each do |field|
14
+ # idx = object.properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS].index(field)
15
+ # if field['identifier'] == '7c30cd4f-aef4-433a-946e-d0f81f8918f1'
16
+ # if properties['klass'] == 'Dataset'
17
+ # container = object&.element_type.constantize.find_by(id: object&.element_id)
18
+ # element = container.root.containable
19
+ # if field['source'] == 'Segment'
20
+ # byebug
21
+ # segments = element.segments.joins(:segment_klass).find_by('segment_klasses.identifier = ?', field['source_id'])
22
+ # seg_prop = segments.properties
23
+ # fields = seg_prop[Labimotion::Prop::LAYERS][field['layer_id']][Labimotion::Prop::FIELDS].select { |ss| ss['field'] == field['field_id'] }
24
+ # val = fields.first['value']
25
+ # object.properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx]['value'] = val
26
+ # end
27
+ # end
28
+ # # object.properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx]['value'] = Time.now.strftime('%d/%m/%Y %H:%M')
29
+ # end
30
+ # end
31
+
11
32
  field_sample_molecules = object.properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS].select { |ss| ss['type'] == Labimotion::FieldType::DRAG_SAMPLE || ss['type'] == Labimotion::FieldType::DRAG_MOLECULE }
12
33
  field_sample_molecules.each do |field|
13
34
  idx = object.properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS].index(field)
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ require 'labimotion/entities/application_entity'
4
+ module Labimotion
5
+ # Dataset entity
6
+ class VocabularyEntity < ApplicationEntity
7
+ expose :id, :identifier, :name, :label, :field_type, :opid, :term_id,
8
+ :field_id, :properties, :source, :source_id, :layer_id
9
+ # expose :source do |obj|
10
+ # (obj[:properties] && obj[:properties]['voc'] && obj[:properties]['voc']['source']) || ''
11
+ # end
12
+ # expose :source_id do |obj|
13
+ # (obj[:properties] && obj[:properties]['voc'] && obj[:properties]['voc']['source_id']) || ''
14
+ # end
15
+ # expose :layer_id do |obj|
16
+ # (obj[:properties] && obj[:properties]['voc'] && obj[:properties]['voc']['layer_id']) || ''
17
+ # end
18
+
19
+ expose :voc do |obj|
20
+ (obj[:properties] && obj[:properties]['voc']) || {}
21
+ end
22
+ expose :ontology do |obj|
23
+ (obj[:properties] && obj[:properties]['ontology']) || {}
24
+ end
25
+ end
26
+ end
@@ -93,7 +93,8 @@ module Labimotion
93
93
  all_coll = Collection.get_all_collection_for_user(current_user.id)
94
94
  element.collections << all_coll
95
95
  element.save!
96
- element.properties = update_sample_association(params[:properties], current_user, element)
96
+ _properties = update_sample_association(params[:properties], current_user, element)
97
+ element.properties = update_vocabularies(_properties, current_user, element)
97
98
  element.container = update_datamodel(params[:container], current_user)
98
99
  element.save!
99
100
  update_element_labels(element, params[:user_labels], current_user.id)
@@ -321,7 +322,6 @@ module Labimotion
321
322
  return { status: 'success', message: "The element: #{attributes['name']} has been created using version: #{attributes['version']}!" }
322
323
  end
323
324
  end
324
-
325
325
  rescue StandardError => e
326
326
  Labimotion.log_exception(e, current_user)
327
327
  return { status: 'error', message: e.message }
@@ -351,7 +351,9 @@ module Labimotion
351
351
  _att
352
352
  end
353
353
  attachments
354
+ rescue StandardError => e
355
+ Labimotion.log_exception(e)
356
+ attachments
354
357
  end
355
-
356
358
  end
357
359
  end
@@ -6,94 +6,149 @@ module Labimotion
6
6
  ## Generic Helpers
7
7
  module ParamHelpers
8
8
  extend Grape::API::Helpers
9
- ## Element Klass Params
10
- params :upload_element_klass_params do
11
- requires :name, type: String, desc: 'Klass Name'
12
- optional :label, type: String, desc: 'Klass label'
13
- optional :desc, type: String, desc: 'Klass desc'
14
- optional :klass_prefix, type: String, desc: 'Klass klass_prefix'
15
- optional :icon_name, type: String, desc: 'Klass icon_name'
16
- requires :properties_template, type: Hash, desc: 'Klass template'
17
- optional :properties_release, type: Hash, desc: 'Klass release'
18
- optional :released_at, type: DateTime, desc: 'Klass released_at'
19
- requires :uuid, type: String, desc: 'Klass uuid'
20
- requires :place, type: Integer, desc: 'Klass place'
21
- requires :identifier, type: String, desc: 'Klass identifier'
22
- optional :sync_time, type: DateTime, desc: 'Klass sync_time'
23
- optional :version, type: String, desc: 'Klass version'
24
- end
9
+ ## Element Klass Params
10
+ params :upload_element_klass_params do
11
+ requires :name, type: String, desc: 'Klass Name'
12
+ optional :label, type: String, desc: 'Klass label'
13
+ optional :desc, type: String, desc: 'Klass desc'
14
+ optional :klass_prefix, type: String, desc: 'Klass klass_prefix'
15
+ optional :icon_name, type: String, desc: 'Klass icon_name'
16
+ requires :properties_template, type: Hash, desc: 'Klass template'
17
+ optional :properties_release, type: Hash, desc: 'Klass release'
18
+ optional :released_at, type: DateTime, desc: 'Klass released_at'
19
+ requires :uuid, type: String, desc: 'Klass uuid'
20
+ requires :place, type: Integer, desc: 'Klass place'
21
+ requires :identifier, type: String, desc: 'Klass identifier'
22
+ optional :sync_time, type: DateTime, desc: 'Klass sync_time'
23
+ optional :version, type: String, desc: 'Klass version'
24
+ end
25
25
 
26
- params :create_element_klass_params do
27
- requires :name, type: String, desc: 'Element Klass Name'
28
- requires :label, type: String, desc: 'Element Klass Label'
29
- requires :klass_prefix, type: String, desc: 'Element Klass Short Label Prefix'
30
- optional :icon_name, type: String, desc: 'Element Klass Icon Name'
31
- optional :desc, type: String, desc: 'Element Klass Desc'
32
- optional :properties_template, type: Hash, desc: 'Element Klass properties template'
33
- end
26
+ params :create_element_klass_params do
27
+ requires :name, type: String, desc: 'Element Klass Name'
28
+ requires :label, type: String, desc: 'Element Klass Label'
29
+ requires :klass_prefix, type: String, desc: 'Element Klass Short Label Prefix'
30
+ optional :icon_name, type: String, desc: 'Element Klass Icon Name'
31
+ optional :desc, type: String, desc: 'Element Klass Desc'
32
+ optional :properties_template, type: Hash, desc: 'Element Klass properties template'
33
+ end
34
34
 
35
- params :update_element_klass_params do
36
- requires :id, type: Integer, desc: 'Element Klass ID'
37
- optional :label, type: String, desc: 'Element Klass Label'
38
- optional :klass_prefix, type: String, desc: 'Element Klass Short Label Prefix'
39
- optional :icon_name, type: String, desc: 'Element Klass Icon Name'
40
- optional :desc, type: String, desc: 'Element Klass Desc'
41
- optional :place, type: String, desc: 'Element Klass Place'
42
- end
35
+ params :update_element_klass_params do
36
+ requires :id, type: Integer, desc: 'Element Klass ID'
37
+ optional :label, type: String, desc: 'Element Klass Label'
38
+ optional :klass_prefix, type: String, desc: 'Element Klass Short Label Prefix'
39
+ optional :icon_name, type: String, desc: 'Element Klass Icon Name'
40
+ optional :desc, type: String, desc: 'Element Klass Desc'
41
+ optional :place, type: String, desc: 'Element Klass Place'
42
+ end
43
43
 
44
- ## Element Params
45
- params :create_element_params do
46
- requires :element_klass, type: Hash
47
- requires :name, type: String
48
- optional :properties, type: Hash
49
- optional :properties_release, type: Hash
50
- optional :collection_id, type: Integer
51
- requires :container, type: Hash
52
- optional :user_labels, type: Array
53
- optional :segments, type: Array, desc: 'Segments'
54
- end
44
+ ## Element Params
45
+ params :create_element_params do
46
+ requires :element_klass, type: Hash
47
+ requires :name, type: String
48
+ optional :properties, type: Hash
49
+ optional :properties_release, type: Hash
50
+ optional :collection_id, type: Integer
51
+ requires :container, type: Hash
52
+ optional :user_labels, type: Array
53
+ optional :segments, type: Array, desc: 'Segments'
54
+ end
55
55
 
56
- params :update_element_params do
57
- requires :id, type: Integer, desc: 'element id'
58
- optional :name, type: String
59
- requires :properties, type: Hash
60
- optional :properties_release, type: Hash
61
- requires :container, type: Hash
62
- optional :user_labels, type: Array
63
- optional :segments, type: Array, desc: 'Segments'
64
- end
56
+ params :update_element_params do
57
+ requires :id, type: Integer, desc: 'element id'
58
+ optional :name, type: String
59
+ requires :properties, type: Hash
60
+ optional :properties_release, type: Hash
61
+ requires :container, type: Hash
62
+ optional :user_labels, type: Array
63
+ optional :segments, type: Array, desc: 'Segments'
64
+ end
65
65
 
66
- ## Segment Klass Params
67
- params :upload_segment_klass_params do
68
- requires :label, type: String, desc: 'Klass label'
69
- optional :desc, type: String, desc: 'Klass desc'
70
- requires :properties_template, type: Hash, desc: 'Klass template'
71
- optional :properties_release, type: Hash, desc: 'Klass release'
72
- optional :released_at, type: DateTime, desc: 'Klass released_at'
73
- requires :uuid, type: String, desc: 'Klass uuid'
74
- requires :place, type: Integer, desc: 'Klass place'
75
- requires :identifier, type: String, desc: 'Klass identifier'
76
- optional :sync_time, type: DateTime, desc: 'Klass sync_time'
77
- optional :version, type: String, desc: 'Klass version'
78
- requires :element_klass, type: Hash do
79
- use :upload_element_klass_params
80
- end
66
+ ## Segment Klass Params
67
+ params :upload_segment_klass_params do
68
+ requires :label, type: String, desc: 'Klass label'
69
+ optional :desc, type: String, desc: 'Klass desc'
70
+ requires :properties_template, type: Hash, desc: 'Klass template'
71
+ optional :properties_release, type: Hash, desc: 'Klass release'
72
+ optional :released_at, type: DateTime, desc: 'Klass released_at'
73
+ requires :uuid, type: String, desc: 'Klass uuid'
74
+ requires :place, type: Integer, desc: 'Klass place'
75
+ requires :identifier, type: String, desc: 'Klass identifier'
76
+ optional :sync_time, type: DateTime, desc: 'Klass sync_time'
77
+ optional :version, type: String, desc: 'Klass version'
78
+ requires :element_klass, type: Hash do
79
+ use :upload_element_klass_params
81
80
  end
81
+ end
82
82
 
83
- params :update_segment_klass_params do
84
- requires :id, type: Integer, desc: 'Segment Klass ID'
85
- optional :label, type: String, desc: 'Segment Klass Label'
86
- optional :desc, type: String, desc: 'Segment Klass Desc'
87
- optional :place, type: String, desc: 'Segment Klass Place', default: '100'
88
- optional :identifier, type: String, desc: 'Segment Identifier'
89
- end
83
+ params :update_segment_klass_params do
84
+ requires :id, type: Integer, desc: 'Segment Klass ID'
85
+ optional :label, type: String, desc: 'Segment Klass Label'
86
+ optional :desc, type: String, desc: 'Segment Klass Desc'
87
+ optional :place, type: String, desc: 'Segment Klass Place', default: '100'
88
+ optional :identifier, type: String, desc: 'Segment Identifier'
89
+ end
90
90
 
91
- params :create_segment_klass_params do
92
- requires :label, type: String, desc: 'Segment Klass Label'
93
- requires :element_klass, type: Integer, desc: 'Element Klass Id'
94
- optional :desc, type: String, desc: 'Segment Klass Desc'
95
- optional :place, type: String, desc: 'Segment Klass Place', default: '100'
96
- optional :properties_template, type: Hash, desc: 'Element Klass properties template'
97
- end
91
+ params :create_segment_klass_params do
92
+ requires :label, type: String, desc: 'Segment Klass Label'
93
+ requires :element_klass, type: Integer, desc: 'Element Klass Id'
94
+ optional :desc, type: String, desc: 'Segment Klass Desc'
95
+ optional :place, type: String, desc: 'Segment Klass Place', default: '100'
96
+ optional :properties_template, type: Hash, desc: 'Element Klass properties template'
97
+ end
98
+
99
+ params :create_std_layer_params do
100
+ requires :name, type: String, desc: 'Element Klass Name'
101
+ requires :label, type: String, desc: 'Element Klass Label'
102
+ requires :klass_prefix, type: String, desc: 'Element Klass Short Label Prefix'
103
+ optional :icon_name, type: String, desc: 'Element Klass Icon Name'
104
+ optional :desc, type: String, desc: 'Element Klass Desc'
105
+ optional :properties_template, type: Hash, desc: 'Element Klass properties template'
106
+ end
107
+
108
+ params :std_layer_save do
109
+ requires :key, type: String, desc: 'key'
110
+ requires :cols, type: Integer, desc: 'key'
111
+ requires :label, type: String, desc: 'Label'
112
+ optional :position, type: Integer, desc: 'position'
113
+ optional :wf_position, type: Integer, desc: 'wf position'
114
+ optional :fields, type: Array, desc: 'fields'
115
+ optional :select_options, type: Hash, desc: 'selections'
116
+ end
117
+
118
+ params :std_layer_criteria do
119
+ requires :name, type: String, desc: 'Layer name'
120
+ end
121
+
122
+ params :vocab_save do
123
+ optional :name, type: String, desc: 'field'
124
+ optional :label, type: String, desc: 'Label'
125
+ optional :term_id, type: String, desc: 'ontology term_id'
126
+ requires :ontology, type: Hash, desc: 'ontology'
127
+ optional :source, type: String, desc: 'source'
128
+ optional :source_id, type: String, desc: 'source_id'
129
+ optional :layer_id, type: String, desc: 'layer_id'
130
+ optional :sub_fields, type: Array, desc: 'sub_fields'
131
+ optional :text_sub_fields, type: Array, desc: 'text_sub_fields'
132
+ requires :field_type, type: String, desc: 'field type'
133
+ requires :voc, type: Hash, desc: 'vocabulary references'
134
+ optional :select_options, type: Hash, desc: 'selections'
135
+ optional :option_layers, type: String, desc: 'option'
136
+ end
137
+
138
+ # params :vocabulary_save do
139
+ # requires :type, type: String, desc: 'type'
140
+ # requires :field, type: String, desc: 'field'
141
+ # optional :default, type: String, desc: 'default'
142
+ # optional :description, type: String, desc: 'description'
143
+ # optional :label, type: String, desc: 'label'
144
+ # optional :position, type: Integer, desc: 'position'
145
+ # optional :ontology, type: Hash, desc: 'ontology'
146
+ # optional :required, type: Boolean, desc: 'is required?'
147
+ # optional :sub_fields, type: Array, desc: 'sub_fields'
148
+ # optional :text_sub_fields, type: Array, desc: 'text_sub_fields'
149
+ # optional :source_type, type: String, desc: 'source type'
150
+ # optional :source_id, type: String, desc: 'source id'
151
+ # optional :layer_id, type: String, desc: 'layer id'
152
+ # end
98
153
  end
99
- end
154
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Labimotion
4
+ # Helper for associated sample
5
+ module VocabularyHelpers
6
+ extend Grape::API::Helpers
7
+
8
+ def update_vocabularies(properties, current_user, element)
9
+ Labimotion::VocabularyHandler.update_vocabularies(properties, current_user, element)
10
+ rescue StandardError => e
11
+ Labimotion.log_exception(e, current_user)
12
+ properties
13
+ end
14
+
15
+ end
16
+ end
@@ -264,6 +264,7 @@ module Labimotion
264
264
  new_prop[Labimotion::Prop::LAYERS]['sample_details'][Labimotion::Prop::FIELDS][idx] = fi
265
265
  end
266
266
  end
267
+ new_prop = Labimotion::VocabularyHandler.update_vocabularies(new_prop, current_user, element)
267
268
  dataset.properties = new_prop
268
269
  dataset.save!
269
270
  end
@@ -256,6 +256,7 @@ module Labimotion
256
256
  new_prop[Labimotion::Prop::LAYERS]['set'][Labimotion::Prop::FIELDS][idx] = fi
257
257
  end
258
258
  end
259
+ new_prop = Labimotion::VocabularyHandler.update_vocabularies(new_prop, current_user, element)
259
260
  dataset.properties = new_prop
260
261
  dataset.save!
261
262
  end
@@ -0,0 +1,91 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Labimotion
4
+ class VocabularyHandler
5
+
6
+ def self.update_vocabularies(properties, current_user, element)
7
+ properties[Labimotion::Prop::LAYERS].keys.each do |key|
8
+ layer = properties[Labimotion::Prop::LAYERS][key]
9
+ field_vocabularies = layer[Labimotion::Prop::FIELDS].select { |ss| ss['is_vocabulary'] == true && ss['opid'] == 9}
10
+ field_vocabularies.each do |field|
11
+ idx = properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS].index(field)
12
+ val = ''
13
+ orig_val = properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx]['value']
14
+ case field['source']
15
+ when 'System'
16
+ val = Time.now.strftime('%d/%m/%Y %H:%M') if field['identifier'] == 'dateTime.update'
17
+ val = Time.now.strftime('%d/%m/%Y %H:%M') if field['identifier'] == 'dateTime.create' && orig_val.blank?
18
+ when 'User'
19
+ val = current_user.name if field['identifier'] == 'user.name' && current_user.present?
20
+ when 'Element'
21
+ val = element.id.to_s if field['identifier'] == 'element.id'
22
+ val = element.short_label if element.has_attribute?(:short_label) && field['identifier'] == 'element.short_label'
23
+ when 'Segment'
24
+ segments = element.segments.joins(:segment_klass).find_by('segment_klasses.identifier = ?', field['source_id'])
25
+ next if segments.nil?
26
+
27
+ seg_prop = segments.properties
28
+ fields = seg_prop[Labimotion::Prop::LAYERS][field['layer_id']][Labimotion::Prop::FIELDS].select { |ss| ss['field'] == field['field_id'] }
29
+ val = fields.first['value']
30
+ when 'Dataset'
31
+ byebug
32
+ end
33
+ # case field['identifier']
34
+ # when 'dateTime.now'
35
+ # val = Time.now.strftime('%d/%m/%Y %H:%M')
36
+ # when 'user.name'
37
+ # val = current_user.name
38
+ # when 'element.id'
39
+ # val = element.id.to_s
40
+ # when 'element.short_label'
41
+ # val = element.short_label
42
+ # end
43
+ # ontology = {
44
+ # id: "ncit:class:http://purl.obolibrary.org/obo/#{field['term_id']}",
45
+ # iri: "http://purl.obolibrary.org/obo/#{field['term_id']}",
46
+ # type: "class",
47
+ # label: field['name'],
48
+ # obo_id: field['term_id'],
49
+ # short_form: field['term_id'],
50
+ # description: field['label'],
51
+ # }
52
+ # properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx]['ontology'] = ontology if ontology.present?
53
+ properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx]['value'] = val if val.present?
54
+ ## properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx]['placeholder'] = val if val.present?
55
+ end
56
+ end
57
+ properties
58
+ rescue StandardError => e
59
+ Labimotion.log_exception(e, current_user)
60
+ properties
61
+ end
62
+
63
+ def self.load_all_vocabularies
64
+ file_data = load_from_files
65
+ db_data = load_from_database
66
+ file_data + db_data
67
+ end
68
+
69
+ def self.load_app_vocabularies
70
+ load_from_files
71
+ end
72
+
73
+ def self.load_from_files
74
+ merged_data = []
75
+ dir_path = Rails.root.join('lib', 'labimotion', 'libs', 'data', 'vocab')
76
+ Dir.glob(dir_path.join('*.json')).each do |file_path|
77
+ file_content = File.read(file_path)
78
+ json_data = JSON.parse(file_content)
79
+ merged_data.concat(json_data)
80
+ end
81
+ merged_data
82
+ end
83
+
84
+ def self.load_from_database
85
+ Labimotion::Vocabulary.all.sort_by(&:name)
86
+ # Labimotion::VocabularyEntity.represent(Labimotion::Vocabulary.all.sort_by(&:name), serializable: true)
87
+ end
88
+
89
+ private_class_method :load_from_files, :load_from_database
90
+ end
91
+ end
@@ -25,14 +25,15 @@ module Labimotion
25
25
  def exec_converter
26
26
  return if self.has_attribute?(:con_state) == false || self.con_state.nil? || self.con_state == Labimotion::ConState::NONE
27
27
 
28
- return if attachable_id.nil? && self.con_state != Labimotion::ConState::WAIT
28
+ return if attachable_id.nil? && con_state != Labimotion::ConState::WAIT
29
29
 
30
+ current_user = User.find_by(id: created_by)
30
31
  case con_state
31
32
  when Labimotion::ConState::NMR
32
- self.con_state = Labimotion::NmrMapper.process_ds(id)
33
+ self.con_state = Labimotion::NmrMapper.process_ds(id, current_user)
33
34
  update_column(:con_state, con_state)
34
35
  when Labimotion::ConState::WAIT
35
- self.con_state = Labimotion::Converter.jcamp_converter(id)
36
+ self.con_state = Labimotion::Converter.jcamp_converter(id, current_user)
36
37
  update_column(:con_state, con_state)
37
38
  when Labimotion::ConState::CONVERTED
38
39
  Labimotion::Converter.metadata(id)
@@ -42,6 +42,7 @@ module Labimotion
42
42
  props['identifier'] = klass.identifier if klass.identifier.present?
43
43
  props['uuid'] = uuid
44
44
  props['klass'] = 'Dataset'
45
+ props = Labimotion::VocabularyHandler.update_vocabularies(props, args[:current_user], args[:element])
45
46
 
46
47
  ds = Labimotion::Dataset.find_by(element_type: self.class.name, element_id: id)
47
48
  if ds.present? && (ds.klass_uuid != props['klass_uuid'] || ds.properties != props)
@@ -59,6 +59,8 @@ module Labimotion
59
59
  props['uuid'] = uuid
60
60
  props['klass'] = 'Segment'
61
61
  props = Labimotion::SampleAssociation.update_sample_association(props, args[:current_user_id])
62
+ current_user = User.find_by(id: args[:current_user_id])
63
+ props = Labimotion::VocabularyHandler.update_vocabularies(props, current_user, self)
62
64
  segment = Labimotion::Segment.where(element_type: self.class.name, element_id: self.id, segment_klass_id: seg['segment_klass_id']).order(id: :desc).first
63
65
  if segment.present? && (segment.klass_uuid != props['klass_uuid'] || segment.properties != props)
64
66
  segment.update!(properties_release: klass.properties_release, properties: props, uuid: uuid, klass_uuid: props['klass_uuid'])
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Labimotion
4
+ class StdLayer < ApplicationRecord
5
+ acts_as_paranoid
6
+ self.table_name = :l_s_lyrs
7
+ has_many :l_s_lyrs_tracks, primary_key: 'identifier', foreign_key: 'identifier', class_name: 'Labimotion::StdLayersRevision'
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Labimotion
4
+ class StdLayersRevision < ApplicationRecord
5
+ acts_as_paranoid
6
+ self.table_name = :l_s_lyrs_tracks
7
+ belongs_to :l_s_lyrs, primary_key: 'identifier', foreign_key: 'identifier', class_name: 'Labimotion::StdLayer'
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ require 'labimotion/models/concerns/generic_klass_revisions'
3
+ require 'labimotion/models/concerns/workflow'
4
+
5
+ module Labimotion
6
+ class Vocabulary < ApplicationRecord
7
+ self.table_name = :vocabularies
8
+ acts_as_paranoid
9
+
10
+
11
+ end
12
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  ## Labimotion Version
4
4
  module Labimotion
5
- VERSION = '1.4.0.2'
5
+ VERSION = '1.5.0.rc2'
6
6
  end
data/lib/labimotion.rb CHANGED
@@ -16,12 +16,15 @@ module Labimotion
16
16
  autoload :Utils, 'labimotion/utils/utils'
17
17
 
18
18
  ######## APIs
19
+ autoload :LabimotionAPI, 'labimotion/apis/labimotion_api'
19
20
  autoload :GenericKlassAPI, 'labimotion/apis/generic_klass_api'
20
21
  autoload :GenericElementAPI, 'labimotion/apis/generic_element_api'
21
22
  autoload :GenericDatasetAPI, 'labimotion/apis/generic_dataset_api'
22
23
  autoload :SegmentAPI, 'labimotion/apis/segment_api'
23
24
  autoload :LabimotionHubAPI, 'labimotion/apis/labimotion_hub_api'
24
25
  autoload :ConverterAPI, 'labimotion/apis/converter_api'
26
+ autoload :StandardLayerAPI, 'labimotion/apis/standard_layer_api'
27
+ autoload :VocabularyAPI, 'labimotion/apis/vocabulary_api'
25
28
 
26
29
  ######## Entities
27
30
  autoload :PropertiesEntity, 'labimotion/entities/properties_entity'
@@ -43,6 +46,7 @@ module Labimotion
43
46
  autoload :ElementRevisionEntity, 'labimotion/entities/element_revision_entity'
44
47
  autoload :SegmentRevisionEntity, 'labimotion/entities/segment_revision_entity'
45
48
  ## autoload :DatasetRevisionEntity, 'labimotion/entities/dataset_revision_entity'
49
+ autoload :VocabularyEntity, 'labimotion/entities/vocabulary_entity'
46
50
 
47
51
  ######## Helpers
48
52
  autoload :GenericHelpers, 'labimotion/helpers/generic_helpers'
@@ -54,6 +58,7 @@ module Labimotion
54
58
  autoload :ConverterHelpers, 'labimotion/helpers/converter_helpers'
55
59
  autoload :SampleAssociationHelpers, 'labimotion/helpers/sample_association_helpers'
56
60
  autoload :RepositoryHelpers, 'labimotion/helpers/repository_helpers'
61
+ autoload :VocabularyHelpers, 'labimotion/helpers/vocabulary_helpers'
57
62
 
58
63
  ######## Libs
59
64
  autoload :Converter, 'labimotion/libs/converter'
@@ -64,6 +69,7 @@ module Labimotion
64
69
  autoload :SampleAssociation, 'labimotion/libs/sample_association'
65
70
  autoload :PropertiesHandler, 'labimotion/libs/properties_handler'
66
71
  autoload :AttachmentHandler, 'labimotion/libs/attachment_handler'
72
+ autoload :VocabularyHandler, 'labimotion/libs/vocabulary_handler'
67
73
 
68
74
  ######## Utils
69
75
  autoload :Prop, 'labimotion/utils/prop'
@@ -84,6 +90,7 @@ module Labimotion
84
90
  autoload :ElementKlass, 'labimotion/models/element_klass'
85
91
  autoload :SegmentKlass, 'labimotion/models/segment_klass'
86
92
  autoload :DatasetKlass, 'labimotion/models/dataset_klass'
93
+ autoload :Vocabulary, 'labimotion/models/vocabulary'
87
94
 
88
95
  autoload :ElementsRevision, 'labimotion/models/elements_revision'
89
96
  autoload :SegmentsRevision, 'labimotion/models/segments_revision'
@@ -97,6 +104,9 @@ module Labimotion
97
104
  autoload :ElementsElement, 'labimotion/models/elements_element'
98
105
  autoload :CollectionsElement, 'labimotion/models/collections_element'
99
106
 
107
+ autoload :StdLayer, 'labimotion/models/std_layer'
108
+ autoload :StdLayersRevision, 'labimotion/models/std_layers_revision'
109
+
100
110
  ######## Models/Concerns
101
111
  autoload :GenericKlassRevisions, 'labimotion/models/concerns/generic_klass_revisions'
102
112
  autoload :GenericRevisions, 'labimotion/models/concerns/generic_revisions'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: labimotion
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0.2
4
+ version: 1.5.0.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chia-Lin Lin
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2024-09-06 00:00:00.000000000 Z
12
+ date: 2024-10-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -41,6 +41,8 @@ files:
41
41
  - lib/labimotion/apis/labimotion_api.rb
42
42
  - lib/labimotion/apis/labimotion_hub_api.rb
43
43
  - lib/labimotion/apis/segment_api.rb
44
+ - lib/labimotion/apis/standard_api.rb
45
+ - lib/labimotion/apis/standard_layer_api.rb
44
46
  - lib/labimotion/apis/vocabulary_api.rb
45
47
  - lib/labimotion/collection/export.rb
46
48
  - lib/labimotion/collection/import.rb
@@ -60,6 +62,7 @@ files:
60
62
  - lib/labimotion/entities/segment_entity.rb
61
63
  - lib/labimotion/entities/segment_klass_entity.rb
62
64
  - lib/labimotion/entities/segment_revision_entity.rb
65
+ - lib/labimotion/entities/vocabulary_entity.rb
63
66
  - lib/labimotion/helpers/converter_helpers.rb
64
67
  - lib/labimotion/helpers/dataset_helpers.rb
65
68
  - lib/labimotion/helpers/element_helpers.rb
@@ -69,6 +72,7 @@ files:
69
72
  - lib/labimotion/helpers/sample_association_helpers.rb
70
73
  - lib/labimotion/helpers/search_helpers.rb
71
74
  - lib/labimotion/helpers/segment_helpers.rb
75
+ - lib/labimotion/helpers/vocabulary_helpers.rb
72
76
  - lib/labimotion/libs/attachment_handler.rb
73
77
  - lib/labimotion/libs/converter.rb
74
78
  - lib/labimotion/libs/export_dataset.rb
@@ -77,6 +81,7 @@ files:
77
81
  - lib/labimotion/libs/properties_handler.rb
78
82
  - lib/labimotion/libs/sample_association.rb
79
83
  - lib/labimotion/libs/template_hub.rb
84
+ - lib/labimotion/libs/vocabulary_handler.rb
80
85
  - lib/labimotion/models/collections_element.rb
81
86
  - lib/labimotion/models/concerns/attachment_converter.rb
82
87
  - lib/labimotion/models/concerns/datasetable.rb
@@ -100,6 +105,9 @@ files:
100
105
  - lib/labimotion/models/segment_klass.rb
101
106
  - lib/labimotion/models/segment_klasses_revision.rb
102
107
  - lib/labimotion/models/segments_revision.rb
108
+ - lib/labimotion/models/std_layer.rb
109
+ - lib/labimotion/models/std_layers_revision.rb
110
+ - lib/labimotion/models/vocabulary.rb
103
111
  - lib/labimotion/utils/con_state.rb
104
112
  - lib/labimotion/utils/export_utils.rb
105
113
  - lib/labimotion/utils/field_type.rb
@@ -125,9 +133,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
125
133
  version: '0'
126
134
  required_rubygems_version: !ruby/object:Gem::Requirement
127
135
  requirements:
128
- - - ">="
136
+ - - ">"
129
137
  - !ruby/object:Gem::Version
130
- version: '0'
138
+ version: 1.3.1
131
139
  requirements: []
132
140
  rubygems_version: 3.1.6
133
141
  signing_key: