labimotion 1.4.0.1 → 1.5.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b71d187c31ec221dea2c2ac6d92bf29efbf4004e16b48cf7a2bd0a85cd1dfdd4
4
- data.tar.gz: 4360e6cfe542ae5e9db004c0039187cdd551981abd53f81370a0be5ee10839de
3
+ metadata.gz: fb234cedd28a03695520718330ec4b35e7ad7512dce48ccd82919a917f249c52
4
+ data.tar.gz: 06c95920f9e0c88705f6c1d3fac27dbc516d57f1025d4798876870cc48a51ddd
5
5
  SHA512:
6
- metadata.gz: 5fe065bae48fbf7a36b1b409a17c7ff1c805bd83ad6f04b43267c024ca25d334dd5ea1092346bea5d38226c0a4bbb773d88c7487bd6adf884ae307e31884335d
7
- data.tar.gz: 5ad569a9c25ef3fc9f454ce60634323ed3da644d1dc663fa949bc779630f25b1d8ba1c54ea21c4c5bd57efb6146e27ebca57e86bfa6fea8a60fad37ce09e93e2
6
+ metadata.gz: 3c38b52e126ebb661704fcb5bdedcfaa723612e06b7ac5b1a51be30976821dfe5c3ff1cfc0cfd4ab06293d4d7f9706ab442b58674380735bd602ef43fd453dfa
7
+ data.tar.gz: cb91684b0d3c8b0b4eb03b43adee712bb16d2a7d402d08fd319e7fbf162dbf7cc2c4438e64429e3fe9d9fc82bbbab703544d924086539628348af0960c58c268
@@ -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,13 @@
1
+ # app/api/labimotion/central_api.rb
2
+ module Labimotion
3
+ class LabimotionAPI < Grape::API
4
+ mount Labimotion::ConverterAPI
5
+ mount Labimotion::GenericKlassAPI
6
+ mount Labimotion::GenericElementAPI
7
+ mount Labimotion::GenericDatasetAPI
8
+ mount Labimotion::SegmentAPI
9
+ mount Labimotion::LabimotionHubAPI
10
+ mount Labimotion::StandardLayerAPI
11
+ mount Labimotion::VocabularyAPI
12
+ end
13
+ 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
@@ -0,0 +1,109 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'labimotion/version'
4
+
5
+ module Labimotion
6
+ # Generic Element API
7
+ class VocabularyAPI < Grape::API
8
+ include Grape::Kaminari
9
+ helpers Labimotion::ParamHelpers
10
+
11
+ resource :vocab do
12
+ namespace :save_vocabulary do
13
+ desc 'Save vocabularies'
14
+ params do
15
+ use :vocab_save
16
+ end
17
+ before do
18
+ # error!('Error! duplicate record', 409) if ???.present?
19
+ rescue ActiveRecord::RecordNotFound
20
+ error!('404 Not Found', 404)
21
+ end
22
+ post do
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
+ # file_content = File.read(file_path)
52
+ # json_data = JSON.parse(file_content)
53
+ # merged_data.concat(json_data)
54
+ # end
55
+
56
+ # list = Labimotion::Vocabulary.all.sort_by { |e| e.name }
57
+ # present list, with: Labimotion::StdLayer, root: 'klass'
58
+ vocabularies = Labimotion::VocabularyHandler.load_all_vocabularies
59
+ combined_data = Labimotion::VocabularyEntity.represent(vocabularies, serializable: true)
60
+ return { mc: 'ss00', data: combined_data }
61
+ rescue StandardError => e
62
+ Labimotion.log_exception(e, current_user)
63
+ { mc: 'se00', msg: e.message, data: [] }
64
+ end
65
+ end
66
+
67
+ namespace :field_klasses do
68
+ desc 'get all field klasses for admin function'
69
+ get do
70
+ # Dir.glob(Rails.public_path.join('generic', 'vocabularies', '*.json')).each do |file_path|
71
+ # file_content = File.read(file_path)
72
+ # json_data = JSON.parse(file_content)
73
+ # merged_data.concat(json_data)
74
+ # end
75
+ vocabularies = Labimotion::VocabularyHandler.load_app_vocabularies
76
+ merged_data = Labimotion::FieldKlassEntity.represent(vocabularies, serializable: true)
77
+ # byebug
78
+ # list = Labimotion::Vocabulary.all.sort_by { |e| e.name }
79
+ # present list, with: Labimotion::VocabularyEntity, root: 'klass'
80
+ # byebug
81
+ merged_data
82
+ rescue StandardError => e
83
+ Labimotion.log_exception(e, current_user)
84
+ []
85
+ end
86
+ end
87
+
88
+ namespace :delete_vocabulary do
89
+ desc 'delete vocabulary by id'
90
+ params do
91
+ requires :id, type: Integer, desc: 'Vocabulary id'
92
+ end
93
+ route_param :id do
94
+ before do
95
+ # error!('401 Unauthorized', 401) unless ElementPolicy.new(current_user, Vocabulary.find(params[:id])).destroy?
96
+ end
97
+ delete do
98
+ entity = Labimotion::Vocabulary.find(params[:id])
99
+ entity.destroy
100
+ return { mc: 'ss00', data: {} }
101
+ rescue StandardError => e
102
+ Labimotion.log_exception(e, current_user)
103
+ { mc: 'se00', msg: e.message, data: [] }
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end
109
+ 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
@@ -232,10 +232,12 @@ module Labimotion
232
232
  new_prop = dataset.properties
233
233
  dsr.each do |ds|
234
234
  layer = layers[ds[:layer]]
235
- next if layer.nil? || layer[Labimotion::Prop::FIELDS].nil?
235
+ next if layer.blank? || layer[Labimotion::Prop::FIELDS].blank?
236
236
 
237
237
  fields = layer[Labimotion::Prop::FIELDS].select{ |f| f['field'] == ds[:field] }
238
238
  fi = fields&.first
239
+ next if fi.blank?
240
+
239
241
  idx = layer[Labimotion::Prop::FIELDS].find_index(fi)
240
242
  fi['value'] = ds[:value]
241
243
  fi['device'] = ds[:device] || ds[:value]
@@ -262,6 +264,7 @@ module Labimotion
262
264
  new_prop[Labimotion::Prop::LAYERS]['sample_details'][Labimotion::Prop::FIELDS][idx] = fi
263
265
  end
264
266
  end
267
+ new_prop = Labimotion::VocabularyHandler.update_vocabularies(new_prop, current_user, element)
265
268
  dataset.properties = new_prop
266
269
  dataset.save!
267
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.1'
5
+ VERSION = '1.5.0.rc1'
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.1
4
+ version: 1.5.0.rc1
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-08-22 00:00:00.000000000 Z
12
+ date: 2024-09-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -38,8 +38,12 @@ files:
38
38
  - lib/labimotion/apis/generic_dataset_api.rb
39
39
  - lib/labimotion/apis/generic_element_api.rb
40
40
  - lib/labimotion/apis/generic_klass_api.rb
41
+ - lib/labimotion/apis/labimotion_api.rb
41
42
  - lib/labimotion/apis/labimotion_hub_api.rb
42
43
  - lib/labimotion/apis/segment_api.rb
44
+ - lib/labimotion/apis/standard_api.rb
45
+ - lib/labimotion/apis/standard_layer_api.rb
46
+ - lib/labimotion/apis/vocabulary_api.rb
43
47
  - lib/labimotion/collection/export.rb
44
48
  - lib/labimotion/collection/import.rb
45
49
  - lib/labimotion/conf.rb
@@ -58,6 +62,7 @@ files:
58
62
  - lib/labimotion/entities/segment_entity.rb
59
63
  - lib/labimotion/entities/segment_klass_entity.rb
60
64
  - lib/labimotion/entities/segment_revision_entity.rb
65
+ - lib/labimotion/entities/vocabulary_entity.rb
61
66
  - lib/labimotion/helpers/converter_helpers.rb
62
67
  - lib/labimotion/helpers/dataset_helpers.rb
63
68
  - lib/labimotion/helpers/element_helpers.rb
@@ -67,6 +72,7 @@ files:
67
72
  - lib/labimotion/helpers/sample_association_helpers.rb
68
73
  - lib/labimotion/helpers/search_helpers.rb
69
74
  - lib/labimotion/helpers/segment_helpers.rb
75
+ - lib/labimotion/helpers/vocabulary_helpers.rb
70
76
  - lib/labimotion/libs/attachment_handler.rb
71
77
  - lib/labimotion/libs/converter.rb
72
78
  - lib/labimotion/libs/export_dataset.rb
@@ -75,6 +81,7 @@ files:
75
81
  - lib/labimotion/libs/properties_handler.rb
76
82
  - lib/labimotion/libs/sample_association.rb
77
83
  - lib/labimotion/libs/template_hub.rb
84
+ - lib/labimotion/libs/vocabulary_handler.rb
78
85
  - lib/labimotion/models/collections_element.rb
79
86
  - lib/labimotion/models/concerns/attachment_converter.rb
80
87
  - lib/labimotion/models/concerns/datasetable.rb
@@ -98,6 +105,9 @@ files:
98
105
  - lib/labimotion/models/segment_klass.rb
99
106
  - lib/labimotion/models/segment_klasses_revision.rb
100
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
101
111
  - lib/labimotion/utils/con_state.rb
102
112
  - lib/labimotion/utils/export_utils.rb
103
113
  - lib/labimotion/utils/field_type.rb
@@ -123,9 +133,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
123
133
  version: '0'
124
134
  required_rubygems_version: !ruby/object:Gem::Requirement
125
135
  requirements:
126
- - - ">="
136
+ - - ">"
127
137
  - !ruby/object:Gem::Version
128
- version: '0'
138
+ version: 1.3.1
129
139
  requirements: []
130
140
  rubygems_version: 3.1.6
131
141
  signing_key: