labimotion 2.3.0.rc1 → 2.3.0.rc4
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/converter_api.rb +98 -23
- data/lib/labimotion/libs/converter.rb +43 -5
- data/lib/labimotion/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bf074c0e6f0eb9c3b52aec0dcde8e8c2a9b2f386027eae477a089e2ff19f4572
|
|
4
|
+
data.tar.gz: 6927c3bc49367aed7830fa2744769deb6fad51c4b24897da10531dab1cb235ce
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 30cf888e8b21894ebcf8b9bc1b1b7618271a56b73678c5f83e3ce17b420a1f8452c16ecc7b073f3bd756edc33765316714a0247a623479505a4db54a8cc7c1ab
|
|
7
|
+
data.tar.gz: 6938831a6aa29266675e58aba6e092aadc5a1252b7df453376509fe38904a5254eb42a01b333a8954039c1fc7e5b9106ad234cc5a1b71ded6b1b8d0596dbb1a0
|
|
@@ -2,39 +2,103 @@
|
|
|
2
2
|
|
|
3
3
|
module Labimotion
|
|
4
4
|
class ConverterAPI < Grape::API
|
|
5
|
+
helpers Labimotion::DatasetHelpers
|
|
5
6
|
helpers do
|
|
7
|
+
def load_converter_config!
|
|
8
|
+
@conf = Rails.configuration.converter&.url
|
|
9
|
+
@profile = Rails.configuration.converter&.profile
|
|
10
|
+
error!(406) unless @conf && @profile
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def require_converter_admin!
|
|
14
|
+
error!(401) unless current_user.profile&.data&.fetch('converter_admin', false)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def uploaded_file
|
|
18
|
+
params[:file].is_a?(Array) ? params[:file][0] : params[:file]
|
|
19
|
+
end
|
|
6
20
|
end
|
|
21
|
+
|
|
7
22
|
resource :converter do
|
|
23
|
+
resource :datasets do
|
|
24
|
+
desc 'list Generic Dataset Klass'
|
|
25
|
+
get do
|
|
26
|
+
list = klass_list(true, false)
|
|
27
|
+
list.map do |kl|
|
|
28
|
+
pr = kl.properties_release
|
|
29
|
+
pr['name'] = kl.label
|
|
30
|
+
pr['ols'] = kl.ols_term_id
|
|
31
|
+
pr
|
|
32
|
+
end || []
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
resource :datasets_units do
|
|
37
|
+
desc 'list Generic Dataset Klass'
|
|
38
|
+
get do
|
|
39
|
+
Labimotion::Units::FIELDS
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
8
43
|
resource :profiles do
|
|
44
|
+
|
|
9
45
|
before do
|
|
10
|
-
|
|
11
|
-
@profile = Rails.configuration.try(:converter).try(:profile)
|
|
12
|
-
error!(406) unless @conf && @profile
|
|
46
|
+
load_converter_config!
|
|
13
47
|
end
|
|
14
|
-
|
|
48
|
+
|
|
49
|
+
desc 'Fetch profiles (no admin required)'
|
|
15
50
|
get do
|
|
16
51
|
profiles = Labimotion::Converter.fetch_profiles
|
|
17
52
|
{ profiles: profiles, client: @profile }
|
|
18
53
|
end
|
|
19
|
-
|
|
54
|
+
|
|
55
|
+
desc 'Create profile'
|
|
20
56
|
post do
|
|
57
|
+
require_converter_admin!
|
|
21
58
|
Labimotion::Converter.create_profile(params)
|
|
22
59
|
end
|
|
23
|
-
|
|
60
|
+
|
|
24
61
|
route_param :id do
|
|
62
|
+
desc 'Update profile'
|
|
25
63
|
put do
|
|
64
|
+
require_converter_admin!
|
|
26
65
|
Labimotion::Converter.update_profile(params)
|
|
27
66
|
end
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
route_param :id do
|
|
67
|
+
|
|
68
|
+
desc 'Delete profile'
|
|
31
69
|
delete do
|
|
32
|
-
|
|
33
|
-
Labimotion::Converter.delete_profile(id)
|
|
70
|
+
require_converter_admin!
|
|
71
|
+
Labimotion::Converter.delete_profile(params[:id])
|
|
34
72
|
end
|
|
35
73
|
end
|
|
36
|
-
end
|
|
37
74
|
|
|
75
|
+
resource :restore do
|
|
76
|
+
route_param :profile_id,
|
|
77
|
+
requirements: {
|
|
78
|
+
profile_id: /[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/
|
|
79
|
+
} do
|
|
80
|
+
|
|
81
|
+
route_param :profile_version,
|
|
82
|
+
requirements: {
|
|
83
|
+
profile_version: /\d+\.\d+/
|
|
84
|
+
} do
|
|
85
|
+
get do
|
|
86
|
+
{test_version: params[:profile_id], version: params[:profile_version]}
|
|
87
|
+
end
|
|
88
|
+
desc 'Restore profile'
|
|
89
|
+
post do
|
|
90
|
+
require_converter_admin!
|
|
91
|
+
|
|
92
|
+
Labimotion::Converter.restore(
|
|
93
|
+
params[:profile_id],
|
|
94
|
+
params[:profile_version],
|
|
95
|
+
params[:hard]
|
|
96
|
+
)
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
38
102
|
resource :structure do
|
|
39
103
|
helpers do
|
|
40
104
|
def convert_structure(molfile)
|
|
@@ -66,10 +130,8 @@ module Labimotion
|
|
|
66
130
|
|
|
67
131
|
resource :options do
|
|
68
132
|
before do
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
@profile = Rails.configuration.try(:converter).try(:profile)
|
|
72
|
-
error!(406) unless @conf && @profile
|
|
133
|
+
load_converter_config!
|
|
134
|
+
require_converter_admin!
|
|
73
135
|
end
|
|
74
136
|
desc 'fetch options'
|
|
75
137
|
get do
|
|
@@ -80,18 +142,31 @@ module Labimotion
|
|
|
80
142
|
|
|
81
143
|
resource :tables do
|
|
82
144
|
before do
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
@profile = Rails.configuration.try(:converter).try(:profile)
|
|
86
|
-
error!(406) unless @conf && @profile
|
|
145
|
+
load_converter_config!
|
|
146
|
+
require_converter_admin!
|
|
87
147
|
end
|
|
88
148
|
desc 'create tables'
|
|
89
149
|
post do
|
|
90
|
-
|
|
91
|
-
res
|
|
150
|
+
file = uploaded_file
|
|
151
|
+
res = Labimotion::Converter.create_tables(file['tempfile']) unless file.nil?
|
|
152
|
+
res['metadata']['file_name'] = file['filename']
|
|
92
153
|
res
|
|
93
154
|
end
|
|
94
155
|
end
|
|
156
|
+
|
|
157
|
+
resource :conversions do
|
|
158
|
+
before do
|
|
159
|
+
load_converter_config!
|
|
160
|
+
require_converter_admin!
|
|
161
|
+
end
|
|
162
|
+
desc 'convert file'
|
|
163
|
+
post do
|
|
164
|
+
file = uploaded_file
|
|
165
|
+
res = Labimotion::Converter.test_conversions(file['tempfile'], params[:format]) unless file.nil?
|
|
166
|
+
res
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
|
|
95
170
|
end
|
|
96
171
|
end
|
|
97
|
-
end
|
|
172
|
+
end
|
|
@@ -125,7 +125,6 @@ module Labimotion
|
|
|
125
125
|
tmp_file.rewind
|
|
126
126
|
|
|
127
127
|
filename = oat.filename
|
|
128
|
-
# name = "#{File.basename(filename, '.*')}.zip"
|
|
129
128
|
name = "#{File.basename(filename, '.*')}#{File.extname(filename) == '.zip' ? '.bagit.zip' : '.zip'}"
|
|
130
129
|
att = Attachment.new(
|
|
131
130
|
filename: name,
|
|
@@ -247,14 +246,22 @@ module Labimotion
|
|
|
247
246
|
dsr.each do |ds|
|
|
248
247
|
layer = layers[ds[:layer]]
|
|
249
248
|
next if layer.blank? || layer[Labimotion::Prop::FIELDS].blank?
|
|
249
|
+
is_unit = ds[:field].start_with?(Prop::CONVERTER_FIELD_UINT_PREFIX)
|
|
250
|
+
next if is_unit && ds[:value].nil?
|
|
250
251
|
|
|
251
|
-
|
|
252
|
+
field_name = ds[:field].delete_prefix(Prop::CONVERTER_FIELD_UINT_PREFIX)
|
|
253
|
+
|
|
254
|
+
fields = layer[Labimotion::Prop::FIELDS].select{ |f| f['field'] == field_name }
|
|
252
255
|
fi = fields&.first
|
|
253
256
|
next if fi.blank?
|
|
254
257
|
|
|
255
258
|
idx = layer[Labimotion::Prop::FIELDS].find_index(fi)
|
|
256
|
-
|
|
257
|
-
|
|
259
|
+
if is_unit
|
|
260
|
+
fi['value_system'] = ds[:value]
|
|
261
|
+
else
|
|
262
|
+
fi['value'] = ds[:value]
|
|
263
|
+
fi['device'] = ds[:device] || ds[:value]
|
|
264
|
+
end
|
|
258
265
|
new_prop[Labimotion::Prop::LAYERS][ds[:layer]][Labimotion::Prop::FIELDS][idx] = fi
|
|
259
266
|
end
|
|
260
267
|
element = Container.find(dataset.element_id)&.root_element
|
|
@@ -320,6 +327,37 @@ module Labimotion
|
|
|
320
327
|
res
|
|
321
328
|
end
|
|
322
329
|
|
|
330
|
+
def self.test_conversions(tmpfile, format)
|
|
331
|
+
res = {}
|
|
332
|
+
File.open(tmpfile.path, 'r') do |file|
|
|
333
|
+
body = { file: file, format: format }
|
|
334
|
+
response = HTTParty.post(
|
|
335
|
+
uri('conversions'),
|
|
336
|
+
basic_auth: auth,
|
|
337
|
+
body: body,
|
|
338
|
+
timeout: timeout,
|
|
339
|
+
)
|
|
340
|
+
res = response.parsed_response
|
|
341
|
+
end
|
|
342
|
+
res
|
|
343
|
+
end
|
|
344
|
+
|
|
345
|
+
def self.restore(profile_id, version, hard)
|
|
346
|
+
body = { hard: hard }
|
|
347
|
+
response = HTTParty.post(
|
|
348
|
+
uri("profiles/restore/#{profile_id}/#{version}"),
|
|
349
|
+
headers: {
|
|
350
|
+
"Content-Type" => "application/json"
|
|
351
|
+
},
|
|
352
|
+
basic_auth: auth,
|
|
353
|
+
body: body.to_json,
|
|
354
|
+
timeout: timeout,
|
|
355
|
+
)
|
|
356
|
+
res = response.parsed_response
|
|
357
|
+
|
|
358
|
+
res
|
|
359
|
+
end
|
|
360
|
+
|
|
323
361
|
def self.metadata(id, current_user)
|
|
324
362
|
att = Attachment.find(id)
|
|
325
363
|
return if att.nil? || att.attachable_id.nil? || att.attachable_type != Labimotion::Prop::CONTAINER
|
|
@@ -334,4 +372,4 @@ end
|
|
|
334
372
|
# rubocop: enable Metrics/AbcSize
|
|
335
373
|
# rubocop: enable Metrics/MethodLength
|
|
336
374
|
# rubocop: enable Metrics/ClassLength
|
|
337
|
-
# rubocop: enable Metrics/CyclomaticComplexity
|
|
375
|
+
# rubocop: enable Metrics/CyclomaticComplexity
|
data/lib/labimotion/version.rb
CHANGED
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: 2.3.0.
|
|
4
|
+
version: 2.3.0.rc4
|
|
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: 2026-07-
|
|
12
|
+
date: 2026-07-10 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: caxlsx
|