labimotion 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/labimotion/apis/labimotion_api.rb +3 -1
- data/lib/labimotion/apis/labimotion_hub_api.rb +83 -10
- data/lib/labimotion/apis/standard_api.rb +2 -1
- data/lib/labimotion/apis/standard_layer_api.rb +17 -4
- data/lib/labimotion/apis/vocabulary_api.rb +20 -6
- data/lib/labimotion/constants.rb +7 -0
- data/lib/labimotion/entities/dataset_entity.rb +1 -0
- data/lib/labimotion/entities/element_entity.rb +0 -1
- data/lib/labimotion/entities/klass_revision_entity.rb +5 -9
- data/lib/labimotion/entities/properties_entity.rb +41 -102
- data/lib/labimotion/entities/segment_entity.rb +2 -0
- data/lib/labimotion/entities/vocabulary_entity.rb +12 -3
- data/lib/labimotion/helpers/element_helpers.rb +1 -2
- data/lib/labimotion/helpers/generic_helpers.rb +1 -6
- data/lib/labimotion/helpers/param_helpers.rb +16 -0
- data/lib/labimotion/libs/converter.rb +1 -0
- data/lib/labimotion/libs/data/layer/StdDataset.json +212 -0
- data/lib/labimotion/libs/data/vocab/System.json +1 -1
- data/lib/labimotion/libs/export_dataset.rb +98 -343
- data/lib/labimotion/libs/nmr_mapper.rb +247 -204
- data/lib/labimotion/libs/template_hub.rb +28 -10
- data/lib/labimotion/models/concerns/generic_klass_revisions.rb +0 -1
- data/lib/labimotion/models/concerns/generic_revisions.rb +0 -3
- data/lib/labimotion/models/concerns/klass_revision.rb +23 -0
- data/lib/labimotion/models/dataset_klasses_revision.rb +4 -1
- data/lib/labimotion/models/element.rb +0 -3
- data/lib/labimotion/models/element_klasses_revision.rb +3 -2
- data/lib/labimotion/models/segment_klasses_revision.rb +4 -1
- data/lib/labimotion/models/template_submission.rb +52 -0
- data/lib/labimotion/utils/utils.rb +0 -21
- data/lib/labimotion/version.rb +1 -1
- data/lib/labimotion.rb +3 -3
- metadata +5 -6
- data/lib/labimotion/libs/data/mapper/Chemwiki.json +0 -236
- data/lib/labimotion/libs/data/mapper/Source.json +0 -78
- data/lib/labimotion/libs/dataset_builder.rb +0 -70
- data/lib/labimotion/utils/mapper_utils.rb +0 -169
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fb9257b355d7ffd4825004ffd9ba25b4bc91cd4779b1bc84878e44d4d980d637
|
|
4
|
+
data.tar.gz: eb9ab9cf1eca01cf9e3eff8ac1fad6de9ea21c39cc71f37f2f6c9726a5984a5d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 713086e4492a67109dabe07f475fd7561374319bcff1ef97e71998c5c760b5e3f4ccecd7517aa5014441f2e0b74fb7267825c1b5365d4ba398694b25e225c05a
|
|
7
|
+
data.tar.gz: ae6e23e4702ee8d56e9bcd39b0b5a34706b4a5c257a2c35a4d1223da76ea175cdd89ef901a4d9ab547a6c40a9e629c376baa345cefaa67609ab3ec10d25ad13e
|
|
@@ -11,24 +11,24 @@ module Labimotion
|
|
|
11
11
|
|
|
12
12
|
namespace :labimotion_hub do
|
|
13
13
|
namespace :list do
|
|
14
|
-
desc
|
|
14
|
+
desc 'get active generic templates'
|
|
15
15
|
params do
|
|
16
|
-
requires :klass, type: String, desc: 'Klass', values:
|
|
16
|
+
requires :klass, type: String, desc: 'Klass', values: Labimotion::Constants::Klass::ALL
|
|
17
17
|
optional :with_props, type: Boolean, desc: 'With Properties', default: false
|
|
18
18
|
end
|
|
19
19
|
get do
|
|
20
20
|
list = "Labimotion::#{params[:klass]}".constantize.where(is_active: true).where.not(released_at: nil)
|
|
21
|
-
list = list.where(is_generic: true) if params[:klass] ==
|
|
22
|
-
|
|
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')
|
|
23
23
|
rescue StandardError => e
|
|
24
24
|
Labimotion.log_exception(e, current_user)
|
|
25
25
|
[]
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
28
|
namespace :fetch do
|
|
29
|
-
desc
|
|
29
|
+
desc 'get active generic templates'
|
|
30
30
|
params do
|
|
31
|
-
requires :klass, type: String, desc: 'Klass', values:
|
|
31
|
+
requires :klass, type: String, desc: 'Klass', values: Labimotion::Constants::Klass::ALL
|
|
32
32
|
requires :origin, type: String, desc: 'origin'
|
|
33
33
|
requires :identifier, type: String, desc: 'Identifier'
|
|
34
34
|
end
|
|
@@ -43,13 +43,16 @@ module Labimotion
|
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
namespace :element_klasses_name do
|
|
46
|
-
desc
|
|
46
|
+
desc 'get klasses'
|
|
47
47
|
params do
|
|
48
|
-
optional :generic_only, type: Boolean, desc:
|
|
48
|
+
optional :generic_only, type: Boolean, desc: 'list generic element only'
|
|
49
49
|
end
|
|
50
50
|
get do
|
|
51
|
-
|
|
52
|
-
|
|
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
|
|
53
56
|
list.pluck(:name)
|
|
54
57
|
rescue StandardError => e
|
|
55
58
|
Labimotion.log_exception(e, current_user)
|
|
@@ -57,6 +60,76 @@ module Labimotion
|
|
|
57
60
|
end
|
|
58
61
|
end
|
|
59
62
|
|
|
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
|
|
60
133
|
end
|
|
61
134
|
end
|
|
62
135
|
end
|
|
@@ -13,7 +13,8 @@ module Labimotion
|
|
|
13
13
|
use :create_std_layer_params
|
|
14
14
|
end
|
|
15
15
|
post do
|
|
16
|
-
authenticate_admin!('
|
|
16
|
+
# authenticate_admin!('elements')
|
|
17
|
+
# create_element_klass(current_user, params)
|
|
17
18
|
create_std_layer(current_user, params)
|
|
18
19
|
status 201
|
|
19
20
|
rescue ActiveRecord::RecordInvalid => e
|
|
@@ -7,13 +7,14 @@ module Labimotion
|
|
|
7
7
|
class StandardLayerAPI < Grape::API
|
|
8
8
|
include Grape::Kaminari
|
|
9
9
|
helpers Labimotion::ParamHelpers
|
|
10
|
-
helpers Labimotion::GenericHelpers
|
|
11
10
|
|
|
12
11
|
resource :layers do
|
|
13
12
|
namespace :get_all_layers do
|
|
14
13
|
desc 'get all standard layers for designer'
|
|
15
14
|
get do
|
|
16
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)
|
|
17
18
|
return { mc: 'ss00', data: list }
|
|
18
19
|
rescue StandardError => e
|
|
19
20
|
Labimotion.log_exception(e, current_user)
|
|
@@ -23,9 +24,17 @@ module Labimotion
|
|
|
23
24
|
|
|
24
25
|
namespace :get_standard_layer do
|
|
25
26
|
desc 'get standard layer by id'
|
|
27
|
+
# params do
|
|
28
|
+
# requires :id, type: Integer, desc: 'Layer id'
|
|
29
|
+
# end
|
|
26
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
|
|
27
37
|
get do
|
|
28
|
-
authenticate_admin!('standard_layers')
|
|
29
38
|
entity = Labimotion::StdLayer.find(params[:id])
|
|
30
39
|
return { mc: 'ss00', data: entity }
|
|
31
40
|
rescue StandardError => e
|
|
@@ -41,9 +50,13 @@ module Labimotion
|
|
|
41
50
|
use :std_layer_save
|
|
42
51
|
end
|
|
43
52
|
before do
|
|
44
|
-
authenticate_admin!('standard_layers')
|
|
45
53
|
cur_layer = Labimotion::StdLayer.find_by(name: params[:key])
|
|
46
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)
|
|
47
60
|
end
|
|
48
61
|
post do
|
|
49
62
|
attributes = {
|
|
@@ -70,7 +83,7 @@ module Labimotion
|
|
|
70
83
|
end
|
|
71
84
|
route_param :id do
|
|
72
85
|
before do
|
|
73
|
-
|
|
86
|
+
# error!('401 Unauthorized', 401) unless ElementPolicy.new(current_user, StdLayer.find(params[:id])).destroy?
|
|
74
87
|
end
|
|
75
88
|
delete do
|
|
76
89
|
entity = Labimotion::StdLayer.find(params[:id])
|
|
@@ -7,7 +7,6 @@ module Labimotion
|
|
|
7
7
|
class VocabularyAPI < Grape::API
|
|
8
8
|
include Grape::Kaminari
|
|
9
9
|
helpers Labimotion::ParamHelpers
|
|
10
|
-
helpers Labimotion::GenericHelpers
|
|
11
10
|
|
|
12
11
|
resource :vocab do
|
|
13
12
|
namespace :save_vocabulary do
|
|
@@ -16,7 +15,7 @@ module Labimotion
|
|
|
16
15
|
use :vocab_save
|
|
17
16
|
end
|
|
18
17
|
before do
|
|
19
|
-
|
|
18
|
+
# error!('Error! duplicate record', 409) if ???.present?
|
|
20
19
|
rescue ActiveRecord::RecordNotFound
|
|
21
20
|
error!('404 Not Found', 404)
|
|
22
21
|
end
|
|
@@ -31,7 +30,7 @@ module Labimotion
|
|
|
31
30
|
source_id: params[:source_id],
|
|
32
31
|
layer_id: params[:layer_id],
|
|
33
32
|
field_id: params[:name],
|
|
34
|
-
identifier:
|
|
33
|
+
identifier: params[:source_id],
|
|
35
34
|
created_by: current_user.id,
|
|
36
35
|
properties: declared(params, include_missing: false),
|
|
37
36
|
}
|
|
@@ -47,8 +46,17 @@ module Labimotion
|
|
|
47
46
|
namespace :get_all_vocabularies do
|
|
48
47
|
desc 'get all standard layers for designer'
|
|
49
48
|
get do
|
|
50
|
-
|
|
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'
|
|
51
58
|
combined_data = Labimotion::VocabularyHandler.load_all_vocabularies
|
|
59
|
+
# combined_data = Labimotion::VocabularyEntity.represent(vocabularies, serializable: true)
|
|
52
60
|
return { mc: 'ss00', data: combined_data }
|
|
53
61
|
rescue StandardError => e
|
|
54
62
|
Labimotion.log_exception(e, current_user)
|
|
@@ -59,9 +67,15 @@ module Labimotion
|
|
|
59
67
|
namespace :field_klasses do
|
|
60
68
|
desc 'get all field klasses for admin function'
|
|
61
69
|
get do
|
|
62
|
-
|
|
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
|
|
63
75
|
vocabularies = Labimotion::VocabularyHandler.load_app_vocabularies
|
|
64
76
|
merged_data = Labimotion::FieldKlassEntity.represent(vocabularies, serializable: true)
|
|
77
|
+
# list = Labimotion::Vocabulary.all.sort_by { |e| e.name }
|
|
78
|
+
# present list, with: Labimotion::VocabularyEntity, root: 'klass'
|
|
65
79
|
merged_data
|
|
66
80
|
rescue StandardError => e
|
|
67
81
|
Labimotion.log_exception(e, current_user)
|
|
@@ -76,7 +90,7 @@ module Labimotion
|
|
|
76
90
|
end
|
|
77
91
|
route_param :id do
|
|
78
92
|
before do
|
|
79
|
-
|
|
93
|
+
# error!('401 Unauthorized', 401) unless ElementPolicy.new(current_user, Vocabulary.find(params[:id])).destroy?
|
|
80
94
|
end
|
|
81
95
|
delete do
|
|
82
96
|
entity = Labimotion::Vocabulary.find(params[:id])
|
data/lib/labimotion/constants.rb
CHANGED
|
@@ -21,5 +21,12 @@ 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
|
|
24
31
|
end
|
|
25
32
|
end
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Labimotion
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
expose :
|
|
4
|
+
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
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
klass_id = object.segment_klass_id if object.respond_to? :segment_klass_id
|
|
11
|
-
klass_id = object.dataset_klass_id if object.respond_to? :dataset_klass_id
|
|
12
|
-
klass_id
|
|
8
|
+
def klass_id
|
|
9
|
+
object.klass&.id
|
|
13
10
|
end
|
|
14
11
|
|
|
15
12
|
def released_at
|
|
@@ -17,4 +14,3 @@ module Labimotion
|
|
|
17
14
|
end
|
|
18
15
|
end
|
|
19
16
|
end
|
|
20
|
-
|
|
@@ -12,7 +12,7 @@ module Labimotion
|
|
|
12
12
|
private
|
|
13
13
|
|
|
14
14
|
def process_layers
|
|
15
|
-
(object&.properties.is_a?(Hash) &&
|
|
15
|
+
(object&.properties.is_a?(Hash) && object.properties[Labimotion::Prop::LAYERS]&.keys || []).each do |key|
|
|
16
16
|
yield(key, object.properties[Labimotion::Prop::LAYERS][key])
|
|
17
17
|
end
|
|
18
18
|
end
|
|
@@ -25,8 +25,7 @@ module Labimotion
|
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
def process_sample_and_molecule_fields(key, layer)
|
|
28
|
-
select_fields(layer,
|
|
29
|
-
[Labimotion::FieldType::DRAG_SAMPLE, Labimotion::FieldType::DRAG_MOLECULE]).each do |field, idx|
|
|
28
|
+
select_fields(layer, [Labimotion::FieldType::DRAG_SAMPLE, Labimotion::FieldType::DRAG_MOLECULE]).each do |field, idx|
|
|
30
29
|
update_sample_or_molecule_field(key, field, idx)
|
|
31
30
|
end
|
|
32
31
|
end
|
|
@@ -61,20 +60,13 @@ module Labimotion
|
|
|
61
60
|
return unless sid.present?
|
|
62
61
|
|
|
63
62
|
el = field['type'] == Labimotion::FieldType::DRAG_SAMPLE ? Sample.find_by(id: sid) : Molecule.find_by(id: sid)
|
|
64
|
-
return unless el.present? && object.properties.dig(Labimotion::Prop::LAYERS, key, Labimotion::Prop::FIELDS, idx,
|
|
65
|
-
'value').present?
|
|
63
|
+
return unless el.present? && object.properties.dig(Labimotion::Prop::LAYERS, key, Labimotion::Prop::FIELDS, idx, 'value').present?
|
|
66
64
|
|
|
67
|
-
label = field['type'] == Labimotion::FieldType::DRAG_SAMPLE ? el&.short_label : el.iupac_name
|
|
68
65
|
update_field_value(key, idx, {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
else
|
|
74
|
-
File.join('/images',
|
|
75
|
-
'molecules', el&.molecule_svg_file || 'nosvg')
|
|
76
|
-
end
|
|
77
|
-
})
|
|
66
|
+
'el_label' => el.short_label,
|
|
67
|
+
'el_tip' => el.short_label,
|
|
68
|
+
'el_svg' => field['type'] == Labimotion::FieldType::DRAG_SAMPLE ? el.get_svg_path : File.join('/images', 'molecules', el&.molecule_svg_file || 'nosvg')
|
|
69
|
+
})
|
|
78
70
|
end
|
|
79
71
|
|
|
80
72
|
def update_reaction_field(key, field, idx)
|
|
@@ -87,34 +79,23 @@ module Labimotion
|
|
|
87
79
|
return
|
|
88
80
|
end
|
|
89
81
|
|
|
90
|
-
return unless object.properties.dig(Labimotion::Prop::LAYERS, key, Labimotion::Prop::FIELDS, idx,
|
|
91
|
-
'value').present?
|
|
82
|
+
return unless object.properties.dig(Labimotion::Prop::LAYERS, key, Labimotion::Prop::FIELDS, idx, 'value').present?
|
|
92
83
|
|
|
93
84
|
update_field_value(key, idx, {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
85
|
+
'el_label' => el.short_label,
|
|
86
|
+
'el_tip' => el.short_label,
|
|
87
|
+
'el_svg' => el.reaction_svg_file
|
|
88
|
+
})
|
|
98
89
|
end
|
|
99
90
|
|
|
100
91
|
def update_table_field(key, field, idx)
|
|
101
92
|
return unless field['sub_values'].present? && field[Labimotion::Prop::SUBFIELDS].present?
|
|
102
93
|
|
|
103
|
-
field_table_molecules = field[Labimotion::Prop::SUBFIELDS].select
|
|
104
|
-
|
|
105
|
-
end
|
|
106
|
-
if field_table_molecules.present?
|
|
107
|
-
object.properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx] =
|
|
108
|
-
set_table(field, field_table_molecules, Labimotion::Prop::MOLECULE)
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
field_table_samples = field[Labimotion::Prop::SUBFIELDS].select do |ss|
|
|
112
|
-
ss['type'] == Labimotion::FieldType::DRAG_SAMPLE
|
|
113
|
-
end
|
|
114
|
-
return unless field_table_samples.present?
|
|
94
|
+
field_table_molecules = field[Labimotion::Prop::SUBFIELDS].select { |ss| ss['type'] == Labimotion::FieldType::DRAG_MOLECULE }
|
|
95
|
+
object.properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx] = set_table(field, field_table_molecules, Labimotion::Prop::MOLECULE) if field_table_molecules.present?
|
|
115
96
|
|
|
116
|
-
|
|
117
|
-
|
|
97
|
+
field_table_samples = field[Labimotion::Prop::SUBFIELDS].select { |ss| ss['type'] == Labimotion::FieldType::DRAG_SAMPLE }
|
|
98
|
+
object.properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx] = set_table(field, field_table_samples, Labimotion::Prop::SAMPLE) if field_table_samples.present?
|
|
118
99
|
end
|
|
119
100
|
|
|
120
101
|
def update_voc_field(key, field, idx)
|
|
@@ -141,9 +122,9 @@ module Labimotion
|
|
|
141
122
|
end
|
|
142
123
|
|
|
143
124
|
def update_element_voc_field(key, field, idx, root_element)
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
125
|
+
if field['identifier'] == 'element.name'
|
|
126
|
+
update_field_value(key, idx, root_element&.name)
|
|
127
|
+
end
|
|
147
128
|
end
|
|
148
129
|
|
|
149
130
|
def update_segment_voc_field(key, field, idx, root_element)
|
|
@@ -151,28 +132,21 @@ module Labimotion
|
|
|
151
132
|
return if segs.empty? || field['layer_id'].blank? || field['field_id'].blank?
|
|
152
133
|
|
|
153
134
|
seg = segs&.first
|
|
154
|
-
seg_fields = seg.properties.dig(Labimotion::Prop::LAYERS, field['layer_id'],
|
|
155
|
-
Labimotion::Prop::FIELDS).select do |ff|
|
|
156
|
-
ff['field'] == field['field_id']
|
|
157
|
-
end
|
|
135
|
+
seg_fields = seg.properties.dig(Labimotion::Prop::LAYERS, field['layer_id'], Labimotion::Prop::FIELDS).select { |ff| ff['field'] == field['field_id'] }
|
|
158
136
|
seg_field = seg_fields&.first
|
|
159
137
|
update_field_value(key, idx, seg_field['value'])
|
|
160
138
|
end
|
|
161
139
|
|
|
162
140
|
def update_dataset_voc_field(key, field, idx, root_element)
|
|
163
|
-
dk = DatasetKlass.find_by(identifier: field[
|
|
164
|
-
dk[
|
|
165
|
-
anas = root_element.analyses.select
|
|
166
|
-
ana.extended_metadata['kind'].split('|')&.first&.strip == dk['ols_term_id']
|
|
167
|
-
end
|
|
141
|
+
dk = DatasetKlass.find_by(identifier: field["source_id"])
|
|
142
|
+
dk["ols_term_id"]
|
|
143
|
+
anas = root_element.analyses.select { |ana| ana.extended_metadata["kind"].split("|")&.first&.strip == dk["ols_term_id"] }
|
|
168
144
|
anas.each do |ana|
|
|
169
145
|
ana.children.each do |cds|
|
|
170
146
|
next unless cds.dataset.present?
|
|
171
147
|
|
|
172
148
|
ds_prop = cds.dataset.properties
|
|
173
|
-
ds_fields = ds_prop.dig(Labimotion::Prop::LAYERS, field['layer_id'], Labimotion::Prop::FIELDS).select
|
|
174
|
-
ff['field'] == field['field_id']
|
|
175
|
-
end
|
|
149
|
+
ds_fields = ds_prop.dig(Labimotion::Prop::LAYERS, field['layer_id'], Labimotion::Prop::FIELDS).select { |ff| ff['field'] == field['field_id'] }
|
|
176
150
|
ds_field = ds_fields&.first
|
|
177
151
|
if object.properties[Labimotion::Prop::LAYERS][key].present? && ds_field['value'].present?
|
|
178
152
|
update_field_value(key, idx, ds_field['value'])
|
|
@@ -181,38 +155,15 @@ module Labimotion
|
|
|
181
155
|
end
|
|
182
156
|
end
|
|
183
157
|
|
|
184
|
-
def update_field_value(key, idx, value
|
|
185
|
-
|
|
186
|
-
original_value = field_path['value']
|
|
187
|
-
|
|
188
|
-
field_path['value'] = merge_values(original_value, value, act)
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
def merge_by_type(original_value, new_value)
|
|
192
|
-
if original_value.is_a?(Hash)
|
|
193
|
-
merge_hash_values(original_value, new_value)
|
|
194
|
-
# elsif original_value.is_a?(Array)
|
|
195
|
-
# merge_array_values(original_value, new_value)
|
|
196
|
-
else
|
|
197
|
-
new_value
|
|
198
|
-
end
|
|
199
|
-
end
|
|
200
|
-
|
|
201
|
-
def merge_values(original_value, new_value, act)
|
|
202
|
-
return new_value if act == 'overwrite'
|
|
203
|
-
return new_value if original_value.blank?
|
|
204
|
-
return original_value if new_value.blank?
|
|
205
|
-
|
|
206
|
-
merge_by_type(original_value, new_value)
|
|
158
|
+
def update_field_value(key, idx, value)
|
|
159
|
+
object.properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx]['value'] = value
|
|
207
160
|
end
|
|
208
161
|
|
|
209
162
|
def set_table(field, field_table_objs, obj)
|
|
210
163
|
col_ids = field_table_objs.map { |x| x.values[0] }
|
|
211
164
|
col_ids.each do |col_id|
|
|
212
165
|
field['sub_values'].each do |sub_value|
|
|
213
|
-
unless sub_value[col_id].present? && sub_value[col_id]['value'].present? && sub_value[col_id]['value']['el_id'].present?
|
|
214
|
-
next
|
|
215
|
-
end
|
|
166
|
+
next unless sub_value[col_id].present? && sub_value[col_id]['value'].present? && sub_value[col_id]['value']['el_id'].present?
|
|
216
167
|
|
|
217
168
|
find_obj = obj.constantize.find_by(id: sub_value[col_id]['value']['el_id'])
|
|
218
169
|
next if find_obj.blank?
|
|
@@ -230,35 +181,23 @@ module Labimotion
|
|
|
230
181
|
|
|
231
182
|
def update_molecule_sub_value(sub_value, col_id, find_obj)
|
|
232
183
|
sub_value[col_id]['value'].merge!({
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
184
|
+
'el_svg' => File.join('/images', 'molecules', find_obj.molecule_svg_file),
|
|
185
|
+
'el_inchikey' => find_obj.inchikey,
|
|
186
|
+
'el_smiles' => find_obj.cano_smiles,
|
|
187
|
+
'el_iupac' => find_obj.iupac_name,
|
|
188
|
+
'el_molecular_weight' => find_obj.molecular_weight
|
|
189
|
+
})
|
|
239
190
|
end
|
|
240
191
|
|
|
241
192
|
def update_sample_sub_value(sub_value, col_id, find_obj)
|
|
242
193
|
sub_value[col_id]['value'].merge!({
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
end
|
|
251
|
-
|
|
252
|
-
def merge_hash_values(original, new_value)
|
|
253
|
-
return original unless new_value.is_a?(Hash)
|
|
254
|
-
|
|
255
|
-
original.merge(new_value)
|
|
256
|
-
end
|
|
257
|
-
|
|
258
|
-
def merge_array_values(original, new_value)
|
|
259
|
-
return original unless new_value.respond_to?(:to_a)
|
|
260
|
-
|
|
261
|
-
(original + new_value.to_a).uniq
|
|
194
|
+
'el_svg' => find_obj.get_svg_path,
|
|
195
|
+
'el_label' => find_obj.short_label,
|
|
196
|
+
'el_short_label' => find_obj.short_label,
|
|
197
|
+
'el_name' => find_obj.name,
|
|
198
|
+
'el_external_label' => find_obj.external_label,
|
|
199
|
+
'el_molecular_weight' => find_obj.decoupled ? find_obj.molecular_mass : find_obj.molecule.molecular_weight
|
|
200
|
+
})
|
|
262
201
|
end
|
|
263
202
|
end
|
|
264
|
-
end
|
|
203
|
+
end
|
|
@@ -6,15 +6,24 @@ module Labimotion
|
|
|
6
6
|
class VocabularyEntity < ApplicationEntity
|
|
7
7
|
expose :id, :identifier, :name, :label, :field_type, :opid, :term_id,
|
|
8
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
|
+
|
|
9
19
|
expose :voc do |obj|
|
|
10
20
|
voc = (obj[:properties] && obj[:properties]['voc']) || {}
|
|
11
21
|
|
|
12
22
|
case voc['source']
|
|
13
23
|
when Labimotion::Prop::ELEMENT
|
|
14
|
-
voc['
|
|
15
|
-
# if voc['identifier'] == 'element.name'
|
|
24
|
+
if voc['identifier'] == 'element.name'
|
|
16
25
|
# voc['source_name'] = ElementKlass.find_by(identifier: voc['source_id'])&.name
|
|
17
|
-
|
|
26
|
+
end
|
|
18
27
|
when Labimotion::Prop::SEGMENT
|
|
19
28
|
voc['source_name'] = SegmentKlass.find_by(identifier: voc['source_id'])&.label
|
|
20
29
|
when Labimotion::Prop::DATASET
|
|
@@ -127,12 +127,11 @@ module Labimotion
|
|
|
127
127
|
attributes['properties']['uuid'] = uuid
|
|
128
128
|
attributes['uuid'] = uuid
|
|
129
129
|
attributes['klass_uuid'] = properties['klass_uuid']
|
|
130
|
-
element.
|
|
130
|
+
element.update(attributes)
|
|
131
131
|
end
|
|
132
132
|
element.save_segments(segments: params[:segments], current_user_id: current_user.id)
|
|
133
133
|
element.reload
|
|
134
134
|
element.properties = update_vocabularies(element.properties, current_user, element)
|
|
135
|
-
## element.user_for_revision = current_user
|
|
136
135
|
element.save!
|
|
137
136
|
element
|
|
138
137
|
rescue StandardError => e
|
|
@@ -9,12 +9,7 @@ module Labimotion
|
|
|
9
9
|
extend Grape::API::Helpers
|
|
10
10
|
|
|
11
11
|
def authenticate_admin!(type)
|
|
12
|
-
|
|
13
|
-
if %w[standard_layers vocabularies].include?(type)
|
|
14
|
-
unauthorized.call unless current_user.generic_admin.values_at('elements', 'segments', 'datasets').any?
|
|
15
|
-
else
|
|
16
|
-
unauthorized.call unless current_user.generic_admin[type]
|
|
17
|
-
end
|
|
12
|
+
error!('401 Unauthorized', 401) unless current_user.generic_admin[type]
|
|
18
13
|
end
|
|
19
14
|
|
|
20
15
|
def fetch_klass(name, id)
|