labimotion 1.5.0.rc9 → 2.0.0
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/standard_api.rb +1 -2
- data/lib/labimotion/apis/standard_layer_api.rb +4 -17
- data/lib/labimotion/apis/vocabulary_api.rb +6 -20
- data/lib/labimotion/constants.rb +25 -0
- data/lib/labimotion/entities/dataset_entity.rb +0 -1
- data/lib/labimotion/entities/element_entity.rb +1 -0
- data/lib/labimotion/entities/properties_entity.rb +104 -44
- data/lib/labimotion/entities/segment_entity.rb +0 -2
- data/lib/labimotion/entities/vocabulary_entity.rb +3 -12
- data/lib/labimotion/helpers/element_helpers.rb +5 -4
- data/lib/labimotion/helpers/generic_helpers.rb +6 -1
- data/lib/labimotion/helpers/param_helpers.rb +0 -16
- data/lib/labimotion/helpers/segment_helpers.rb +1 -1
- data/lib/labimotion/libs/converter.rb +0 -1
- data/lib/labimotion/libs/data/mapper/Chemwiki.json +236 -0
- data/lib/labimotion/libs/data/mapper/Source.json +78 -0
- data/lib/labimotion/libs/data/vocab/Standard.json +5 -5
- data/lib/labimotion/libs/data/vocab/System.json +14 -14
- data/lib/labimotion/libs/dataset_builder.rb +70 -0
- data/lib/labimotion/libs/export_dataset.rb +343 -98
- data/lib/labimotion/libs/nmr_mapper.rb +204 -247
- data/lib/labimotion/libs/sample_association.rb +4 -0
- data/lib/labimotion/libs/vocabulary_handler.rb +18 -12
- data/lib/labimotion/models/concerns/generic_klass_revisions.rb +1 -0
- data/lib/labimotion/models/concerns/generic_revisions.rb +3 -0
- data/lib/labimotion/models/element.rb +3 -0
- data/lib/labimotion/models/std_layer.rb +2 -2
- data/lib/labimotion/models/std_layers_revision.rb +2 -2
- data/lib/labimotion/utils/mapper_utils.rb +169 -0
- data/lib/labimotion/utils/utils.rb +21 -0
- data/lib/labimotion/version.rb +1 -1
- data/lib/labimotion.rb +3 -3
- metadata +9 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c1fa1527f921643836476d930d66fedc973e06e2a6300d9e100e2852fc96168
|
4
|
+
data.tar.gz: 4ccc2fe165c170aa98fba5db9d63c576ed997e9650e54da439b1b295da65c816
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39915628df304676e86ad4e601d6776e994eb5007cc2f857c48b64498c24dba596d3ae1a46136b1d9c909dc3620724c10f0605682ba34224430c5405324d9076
|
7
|
+
data.tar.gz: fae1a472384cd8ba2c7e93c647399add301ed35e4404038382f451c6b2f2c7644331004c67cba91e76872e844b334fb8041e4a1dbf682dc6644010d9fd7630fe
|
@@ -13,8 +13,7 @@ module Labimotion
|
|
13
13
|
use :create_std_layer_params
|
14
14
|
end
|
15
15
|
post do
|
16
|
-
|
17
|
-
# create_element_klass(current_user, params)
|
16
|
+
authenticate_admin!('standard_layers')
|
18
17
|
create_std_layer(current_user, params)
|
19
18
|
status 201
|
20
19
|
rescue ActiveRecord::RecordInvalid => e
|
@@ -7,14 +7,13 @@ module Labimotion
|
|
7
7
|
class StandardLayerAPI < Grape::API
|
8
8
|
include Grape::Kaminari
|
9
9
|
helpers Labimotion::ParamHelpers
|
10
|
+
helpers Labimotion::GenericHelpers
|
10
11
|
|
11
12
|
resource :layers do
|
12
13
|
namespace :get_all_layers do
|
13
14
|
desc 'get all standard layers for designer'
|
14
15
|
get do
|
15
16
|
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
17
|
return { mc: 'ss00', data: list }
|
19
18
|
rescue StandardError => e
|
20
19
|
Labimotion.log_exception(e, current_user)
|
@@ -24,17 +23,9 @@ module Labimotion
|
|
24
23
|
|
25
24
|
namespace :get_standard_layer do
|
26
25
|
desc 'get standard layer by id'
|
27
|
-
# params do
|
28
|
-
# requires :id, type: Integer, desc: 'Layer id'
|
29
|
-
# end
|
30
26
|
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
27
|
get do
|
28
|
+
authenticate_admin!('standard_layers')
|
38
29
|
entity = Labimotion::StdLayer.find(params[:id])
|
39
30
|
return { mc: 'ss00', data: entity }
|
40
31
|
rescue StandardError => e
|
@@ -50,13 +41,9 @@ module Labimotion
|
|
50
41
|
use :std_layer_save
|
51
42
|
end
|
52
43
|
before do
|
44
|
+
authenticate_admin!('standard_layers')
|
53
45
|
cur_layer = Labimotion::StdLayer.find_by(name: params[:key])
|
54
46
|
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
47
|
end
|
61
48
|
post do
|
62
49
|
attributes = {
|
@@ -83,7 +70,7 @@ module Labimotion
|
|
83
70
|
end
|
84
71
|
route_param :id do
|
85
72
|
before do
|
86
|
-
|
73
|
+
authenticate_admin!('standard_layers')
|
87
74
|
end
|
88
75
|
delete do
|
89
76
|
entity = Labimotion::StdLayer.find(params[:id])
|
@@ -7,6 +7,7 @@ module Labimotion
|
|
7
7
|
class VocabularyAPI < Grape::API
|
8
8
|
include Grape::Kaminari
|
9
9
|
helpers Labimotion::ParamHelpers
|
10
|
+
helpers Labimotion::GenericHelpers
|
10
11
|
|
11
12
|
resource :vocab do
|
12
13
|
namespace :save_vocabulary do
|
@@ -15,7 +16,7 @@ module Labimotion
|
|
15
16
|
use :vocab_save
|
16
17
|
end
|
17
18
|
before do
|
18
|
-
|
19
|
+
authenticate_admin!('vocabularies')
|
19
20
|
rescue ActiveRecord::RecordNotFound
|
20
21
|
error!('404 Not Found', 404)
|
21
22
|
end
|
@@ -30,7 +31,7 @@ module Labimotion
|
|
30
31
|
source_id: params[:source_id],
|
31
32
|
layer_id: params[:layer_id],
|
32
33
|
field_id: params[:name],
|
33
|
-
identifier:
|
34
|
+
identifier: SecureRandom.uuid,
|
34
35
|
created_by: current_user.id,
|
35
36
|
properties: declared(params, include_missing: false),
|
36
37
|
}
|
@@ -46,17 +47,8 @@ module Labimotion
|
|
46
47
|
namespace :get_all_vocabularies do
|
47
48
|
desc 'get all standard layers for designer'
|
48
49
|
get do
|
49
|
-
|
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'
|
50
|
+
authenticate_admin!('vocabularies')
|
58
51
|
combined_data = Labimotion::VocabularyHandler.load_all_vocabularies
|
59
|
-
# combined_data = Labimotion::VocabularyEntity.represent(vocabularies, serializable: true)
|
60
52
|
return { mc: 'ss00', data: combined_data }
|
61
53
|
rescue StandardError => e
|
62
54
|
Labimotion.log_exception(e, current_user)
|
@@ -67,15 +59,9 @@ module Labimotion
|
|
67
59
|
namespace :field_klasses do
|
68
60
|
desc 'get all field klasses for admin function'
|
69
61
|
get do
|
70
|
-
|
71
|
-
# file_content = File.read(file_path)
|
72
|
-
# json_data = JSON.parse(file_content)
|
73
|
-
# merged_data.concat(json_data)
|
74
|
-
# end
|
62
|
+
authenticate_admin!('vocabularies')
|
75
63
|
vocabularies = Labimotion::VocabularyHandler.load_app_vocabularies
|
76
64
|
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'
|
79
65
|
merged_data
|
80
66
|
rescue StandardError => e
|
81
67
|
Labimotion.log_exception(e, current_user)
|
@@ -90,7 +76,7 @@ module Labimotion
|
|
90
76
|
end
|
91
77
|
route_param :id do
|
92
78
|
before do
|
93
|
-
|
79
|
+
authenticate_admin!('vocabularies')
|
94
80
|
end
|
95
81
|
delete do
|
96
82
|
entity = Labimotion::Vocabulary.find(params[:id])
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Labimotion
|
4
|
+
module Constants
|
5
|
+
module DateTime
|
6
|
+
DATE_FORMAT = '%Y-%m-%d'
|
7
|
+
DATETIME_FORMAT = '%Y-%m-%d %H:%M:%S %Z'
|
8
|
+
TIME_FORMAT = '%H:%M:%S %Z'
|
9
|
+
TIME_ZONE = 'UTC'
|
10
|
+
end
|
11
|
+
|
12
|
+
module File
|
13
|
+
ENCODING = 'UTF-8'
|
14
|
+
end
|
15
|
+
|
16
|
+
module CHMO
|
17
|
+
CV = 'Cyclic Voltammetry'
|
18
|
+
end
|
19
|
+
|
20
|
+
module Mapper
|
21
|
+
NMR_CONFIG = ::File.join(__dir__, 'libs', 'data', 'mapper', 'Source.json').freeze
|
22
|
+
WIKI_CONFIG = ::File.join(__dir__, 'libs', 'data', 'mapper', 'Chemwiki.json').freeze
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -12,7 +12,7 @@ module Labimotion
|
|
12
12
|
private
|
13
13
|
|
14
14
|
def process_layers
|
15
|
-
(object&.properties.is_a?(Hash) && object.properties[Labimotion::Prop::LAYERS]&.keys || []).each do |key|
|
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
|
@@ -21,11 +21,12 @@ module Labimotion
|
|
21
21
|
process_sample_and_molecule_fields(key, layer)
|
22
22
|
process_reaction_fields(key, layer)
|
23
23
|
process_table_fields(key, layer)
|
24
|
-
process_voc_fields(key, layer)
|
24
|
+
# process_voc_fields(key, layer)
|
25
25
|
end
|
26
26
|
|
27
27
|
def process_sample_and_molecule_fields(key, layer)
|
28
|
-
select_fields(layer,
|
28
|
+
select_fields(layer,
|
29
|
+
[Labimotion::FieldType::DRAG_SAMPLE, Labimotion::FieldType::DRAG_MOLECULE]).each do |field, idx|
|
29
30
|
update_sample_or_molecule_field(key, field, idx)
|
30
31
|
end
|
31
32
|
end
|
@@ -52,7 +53,7 @@ module Labimotion
|
|
52
53
|
fields = layer[Labimotion::Prop::FIELDS]
|
53
54
|
fields = fields.select { |f| types.include?(f['type']) } if types
|
54
55
|
fields = fields.select { |f| f['is_voc'] == true } if is_voc
|
55
|
-
fields.map { |f| [f,
|
56
|
+
fields.map { |f| [f, layer[Labimotion::Prop::FIELDS].index(f)] }
|
56
57
|
end
|
57
58
|
|
58
59
|
def update_sample_or_molecule_field(key, field, idx)
|
@@ -60,13 +61,20 @@ module Labimotion
|
|
60
61
|
return unless sid.present?
|
61
62
|
|
62
63
|
el = field['type'] == Labimotion::FieldType::DRAG_SAMPLE ? Sample.find_by(id: sid) : Molecule.find_by(id: sid)
|
63
|
-
return unless el.present? && object.properties.dig(Labimotion::Prop::LAYERS, key, Labimotion::Prop::FIELDS, idx,
|
64
|
+
return unless el.present? && object.properties.dig(Labimotion::Prop::LAYERS, key, Labimotion::Prop::FIELDS, idx,
|
65
|
+
'value').present?
|
64
66
|
|
67
|
+
label = field['type'] == Labimotion::FieldType::DRAG_SAMPLE ? el&.short_label : el.iupac_name
|
65
68
|
update_field_value(key, idx, {
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
69
|
+
'el_label' => label,
|
70
|
+
'el_tip' => label,
|
71
|
+
'el_svg' => if field['type'] == Labimotion::FieldType::DRAG_SAMPLE
|
72
|
+
el&.get_svg_path
|
73
|
+
else
|
74
|
+
File.join('/images',
|
75
|
+
'molecules', el&.molecule_svg_file || 'nosvg')
|
76
|
+
end
|
77
|
+
})
|
70
78
|
end
|
71
79
|
|
72
80
|
def update_reaction_field(key, field, idx)
|
@@ -79,28 +87,38 @@ module Labimotion
|
|
79
87
|
return
|
80
88
|
end
|
81
89
|
|
82
|
-
return unless object.properties.dig(Labimotion::Prop::LAYERS, key, Labimotion::Prop::FIELDS, idx,
|
90
|
+
return unless object.properties.dig(Labimotion::Prop::LAYERS, key, Labimotion::Prop::FIELDS, idx,
|
91
|
+
'value').present?
|
83
92
|
|
84
93
|
update_field_value(key, idx, {
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
94
|
+
'el_label' => el.short_label,
|
95
|
+
'el_tip' => el.short_label,
|
96
|
+
'el_svg' => el.reaction_svg_file
|
97
|
+
})
|
89
98
|
end
|
90
99
|
|
91
100
|
def update_table_field(key, field, idx)
|
92
101
|
return unless field['sub_values'].present? && field[Labimotion::Prop::SUBFIELDS].present?
|
93
102
|
|
94
|
-
field_table_molecules = field[Labimotion::Prop::SUBFIELDS].select
|
95
|
-
|
103
|
+
field_table_molecules = field[Labimotion::Prop::SUBFIELDS].select do |ss|
|
104
|
+
ss['type'] == Labimotion::FieldType::DRAG_MOLECULE
|
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?
|
96
115
|
|
97
|
-
|
98
|
-
|
116
|
+
object.properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx] =
|
117
|
+
set_table(field, field_table_samples, Labimotion::Prop::SAMPLE)
|
99
118
|
end
|
100
119
|
|
101
120
|
def update_voc_field(key, field, idx)
|
102
121
|
root_element = get_root_element
|
103
|
-
|
104
122
|
case field['source']
|
105
123
|
when Labimotion::Prop::ELEMENT
|
106
124
|
update_element_voc_field(key, field, idx, root_element)
|
@@ -123,9 +141,9 @@ module Labimotion
|
|
123
141
|
end
|
124
142
|
|
125
143
|
def update_element_voc_field(key, field, idx, root_element)
|
126
|
-
|
127
|
-
|
128
|
-
|
144
|
+
return unless field['identifier'] == 'element.name'
|
145
|
+
|
146
|
+
update_field_value(key, idx, root_element&.name)
|
129
147
|
end
|
130
148
|
|
131
149
|
def update_segment_voc_field(key, field, idx, root_element)
|
@@ -133,21 +151,28 @@ module Labimotion
|
|
133
151
|
return if segs.empty? || field['layer_id'].blank? || field['field_id'].blank?
|
134
152
|
|
135
153
|
seg = segs&.first
|
136
|
-
seg_fields = seg.properties.dig(Labimotion::Prop::LAYERS, field['layer_id'],
|
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
|
137
158
|
seg_field = seg_fields&.first
|
138
159
|
update_field_value(key, idx, seg_field['value'])
|
139
160
|
end
|
140
161
|
|
141
162
|
def update_dataset_voc_field(key, field, idx, root_element)
|
142
|
-
dk = DatasetKlass.find_by(identifier: field[
|
143
|
-
dk[
|
144
|
-
anas = root_element.analyses.select
|
163
|
+
dk = DatasetKlass.find_by(identifier: field['source_id'])
|
164
|
+
dk['ols_term_id']
|
165
|
+
anas = root_element.analyses.select do |ana|
|
166
|
+
ana.extended_metadata['kind'].split('|')&.first&.strip == dk['ols_term_id']
|
167
|
+
end
|
145
168
|
anas.each do |ana|
|
146
169
|
ana.children.each do |cds|
|
147
170
|
next unless cds.dataset.present?
|
148
171
|
|
149
172
|
ds_prop = cds.dataset.properties
|
150
|
-
ds_fields = ds_prop.dig(Labimotion::Prop::LAYERS, field['layer_id'], Labimotion::Prop::FIELDS).select
|
173
|
+
ds_fields = ds_prop.dig(Labimotion::Prop::LAYERS, field['layer_id'], Labimotion::Prop::FIELDS).select do |ff|
|
174
|
+
ff['field'] == field['field_id']
|
175
|
+
end
|
151
176
|
ds_field = ds_fields&.first
|
152
177
|
if object.properties[Labimotion::Prop::LAYERS][key].present? && ds_field['value'].present?
|
153
178
|
update_field_value(key, idx, ds_field['value'])
|
@@ -156,15 +181,38 @@ module Labimotion
|
|
156
181
|
end
|
157
182
|
end
|
158
183
|
|
159
|
-
def update_field_value(key, idx, value)
|
160
|
-
object.properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx]
|
184
|
+
def update_field_value(key, idx, value, act = 'merge')
|
185
|
+
field_path = object.properties[Labimotion::Prop::LAYERS][key][Labimotion::Prop::FIELDS][idx]
|
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)
|
161
207
|
end
|
162
208
|
|
163
209
|
def set_table(field, field_table_objs, obj)
|
164
210
|
col_ids = field_table_objs.map { |x| x.values[0] }
|
165
211
|
col_ids.each do |col_id|
|
166
212
|
field['sub_values'].each do |sub_value|
|
167
|
-
|
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
|
168
216
|
|
169
217
|
find_obj = obj.constantize.find_by(id: sub_value[col_id]['value']['el_id'])
|
170
218
|
next if find_obj.blank?
|
@@ -182,23 +230,35 @@ module Labimotion
|
|
182
230
|
|
183
231
|
def update_molecule_sub_value(sub_value, col_id, find_obj)
|
184
232
|
sub_value[col_id]['value'].merge!({
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
233
|
+
'el_svg' => File.join('/images', 'molecules', find_obj.molecule_svg_file),
|
234
|
+
'el_inchikey' => find_obj.inchikey,
|
235
|
+
'el_smiles' => find_obj.cano_smiles,
|
236
|
+
'el_iupac' => find_obj.iupac_name,
|
237
|
+
'el_molecular_weight' => find_obj.molecular_weight
|
238
|
+
})
|
191
239
|
end
|
192
240
|
|
193
241
|
def update_sample_sub_value(sub_value, col_id, find_obj)
|
194
242
|
sub_value[col_id]['value'].merge!({
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
243
|
+
'el_svg' => find_obj.get_svg_path,
|
244
|
+
'el_label' => find_obj.short_label,
|
245
|
+
'el_short_label' => find_obj.short_label,
|
246
|
+
'el_name' => find_obj.name,
|
247
|
+
'el_external_label' => find_obj.external_label,
|
248
|
+
'el_molecular_weight' => find_obj.decoupled ? find_obj.molecular_mass : find_obj.molecule.molecular_weight
|
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
|
202
262
|
end
|
203
263
|
end
|
204
|
-
end
|
264
|
+
end
|
@@ -6,24 +6,15 @@ 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
|
-
|
19
9
|
expose :voc do |obj|
|
20
10
|
voc = (obj[:properties] && obj[:properties]['voc']) || {}
|
21
11
|
|
22
12
|
case voc['source']
|
23
13
|
when Labimotion::Prop::ELEMENT
|
24
|
-
|
14
|
+
voc['source_name'] = ElementKlass.find_by(identifier: voc['source_id'])&.label
|
15
|
+
# if voc['identifier'] == 'element.name'
|
25
16
|
# voc['source_name'] = ElementKlass.find_by(identifier: voc['source_id'])&.name
|
26
|
-
end
|
17
|
+
# end
|
27
18
|
when Labimotion::Prop::SEGMENT
|
28
19
|
voc['source_name'] = SegmentKlass.find_by(identifier: voc['source_id'])&.label
|
29
20
|
when Labimotion::Prop::DATASET
|
@@ -113,7 +113,6 @@ module Labimotion
|
|
113
113
|
params.delete(:properties)
|
114
114
|
update_element_labels(element, params[:user_labels], current_user.id)
|
115
115
|
params.delete(:user_labels)
|
116
|
-
|
117
116
|
attributes = declared(params.except(:segments), include_missing: false)
|
118
117
|
properties['pkg'] = Labimotion::Utils.pkg(properties['pkg'])
|
119
118
|
if element.klass_uuid != properties['klass_uuid'] || element.properties != properties || element.name != params[:name]
|
@@ -124,15 +123,17 @@ module Labimotion
|
|
124
123
|
properties.delete('flow') unless properties['flow'].nil?
|
125
124
|
properties.delete('flowObject') unless properties['flowObject'].nil?
|
126
125
|
properties.delete('select_options') unless properties['select_options'].nil?
|
127
|
-
|
128
126
|
attributes['properties'] = properties
|
129
127
|
attributes['properties']['uuid'] = uuid
|
130
128
|
attributes['uuid'] = uuid
|
131
129
|
attributes['klass_uuid'] = properties['klass_uuid']
|
132
|
-
|
133
|
-
element.update(attributes)
|
130
|
+
element.update_columns(attributes)
|
134
131
|
end
|
135
132
|
element.save_segments(segments: params[:segments], current_user_id: current_user.id)
|
133
|
+
element.reload
|
134
|
+
element.properties = update_vocabularies(element.properties, current_user, element)
|
135
|
+
## element.user_for_revision = current_user
|
136
|
+
element.save!
|
136
137
|
element
|
137
138
|
rescue StandardError => e
|
138
139
|
Labimotion.log_exception(e, current_user)
|
@@ -9,7 +9,12 @@ module Labimotion
|
|
9
9
|
extend Grape::API::Helpers
|
10
10
|
|
11
11
|
def authenticate_admin!(type)
|
12
|
-
error!('401 Unauthorized', 401)
|
12
|
+
unauthorized = -> { error!('401 Unauthorized', 401) }
|
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
|
13
18
|
end
|
14
19
|
|
15
20
|
def fetch_klass(name, id)
|
@@ -134,21 +134,5 @@ module Labimotion
|
|
134
134
|
optional :select_options, type: Hash, desc: 'selections'
|
135
135
|
optional :option_layers, type: String, desc: 'option'
|
136
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
|
153
137
|
end
|
154
138
|
end
|
@@ -72,7 +72,7 @@ module Labimotion
|
|
72
72
|
# el_attributes['properties_template'] = response['element_klass']['properties_release']
|
73
73
|
# Labimotion::ElementKlass.create!(el_attributes)
|
74
74
|
attributes['element_klass_id'] = element_klass.id
|
75
|
-
segment_klass = Labimotion::SegmentKlass.find_by(identifier: attributes['identifier'])
|
75
|
+
segment_klass = Labimotion::SegmentKlass.find_by(identifier: attributes['identifier']) if attributes['identifier'].present?
|
76
76
|
if segment_klass.present?
|
77
77
|
if segment_klass['uuid'] == attributes['uuid'] && segment_klass['version'] == attributes['version']
|
78
78
|
return { status: 'success', message: "This segment: #{attributes['label']} has the latest version!" }
|
@@ -123,7 +123,6 @@ module Labimotion
|
|
123
123
|
tmp_file.write(response.parsed_response)
|
124
124
|
tmp_file.rewind
|
125
125
|
|
126
|
-
# name = response&.headers && response&.headers['content-disposition']&.split('=')&.last
|
127
126
|
filename = oat.filename
|
128
127
|
name = "#{File.basename(filename, '.*')}.zip"
|
129
128
|
att = Attachment.new(
|