proformaxml 1.4.0 → 1.5.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/.rubocop/naming.yml +4 -0
- data/.rubocop/rspec.yml +0 -4
- data/.rubocop.yml +2 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +39 -39
- data/lib/proformaxml/services/exporter.rb +7 -14
- data/lib/proformaxml/services/importer.rb +10 -13
- data/lib/proformaxml/services/service_base.rb +9 -0
- data/lib/proformaxml/services/transform_task.rb +88 -0
- data/lib/proformaxml/services/validator.rb +8 -15
- data/lib/proformaxml/services/version_and_namespace_extractor.rb +31 -0
- data/lib/proformaxml/version.rb +1 -1
- data/lib/proformaxml.rb +4 -0
- metadata +7 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d18194bbaa507eb74a566d374f500824deb6d40380291f0a691d9d98d5050466
|
|
4
|
+
data.tar.gz: 9903f5f2beae7909cb1e02f7e351f41d8c60fc3135a6ad8ea447441d07f696d0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 828392048a14868c751d143d338416a08b283f85d3d16665a3267ea466ec701589851ca711deef2880064c966a6cbb9cbded366c4fddea4da470695f063ce631
|
|
7
|
+
data.tar.gz: b7b22d6e668c3bbfbba4a8280991c3800b4b340260dfc8096f3c96d1e755e888647c30c0b2f0f0b6d0736284b7716bbc9227be071fbfb7ec81a971151add6504
|
data/.rubocop/naming.yml
ADDED
data/.rubocop/rspec.yml
CHANGED
data/.rubocop.yml
CHANGED
|
@@ -3,12 +3,14 @@ require:
|
|
|
3
3
|
- rubocop-performance
|
|
4
4
|
- rubocop-rails
|
|
5
5
|
- rubocop-rspec
|
|
6
|
+
- rubocop-rspec_rails
|
|
6
7
|
|
|
7
8
|
inherit_from:
|
|
8
9
|
- .rubocop/factory-bot.yml
|
|
9
10
|
- .rubocop/layout.yml
|
|
10
11
|
- .rubocop/lint.yml
|
|
11
12
|
- .rubocop/metrics.yml
|
|
13
|
+
- .rubocop/naming.yml
|
|
12
14
|
- .rubocop/rspec.yml
|
|
13
15
|
- .rubocop/style.yml
|
|
14
16
|
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
proformaxml (1.
|
|
4
|
+
proformaxml (1.5.1)
|
|
5
5
|
activemodel (>= 5.2.3, < 8.0.0)
|
|
6
6
|
activesupport (>= 5.2.3, < 8.0.0)
|
|
7
7
|
dachsfisch (~> 1.0.0)
|
|
@@ -11,24 +11,25 @@ PATH
|
|
|
11
11
|
GEM
|
|
12
12
|
remote: https://rubygems.org/
|
|
13
13
|
specs:
|
|
14
|
-
activemodel (7.1
|
|
15
|
-
activesupport (= 7.1
|
|
16
|
-
activesupport (7.1
|
|
14
|
+
activemodel (7.2.1)
|
|
15
|
+
activesupport (= 7.2.1)
|
|
16
|
+
activesupport (7.2.1)
|
|
17
17
|
base64
|
|
18
18
|
bigdecimal
|
|
19
|
-
concurrent-ruby (~> 1.0, >= 1.
|
|
19
|
+
concurrent-ruby (~> 1.0, >= 1.3.1)
|
|
20
20
|
connection_pool (>= 2.2.5)
|
|
21
21
|
drb
|
|
22
22
|
i18n (>= 1.6, < 2)
|
|
23
|
+
logger (>= 1.4.2)
|
|
23
24
|
minitest (>= 5.1)
|
|
24
|
-
|
|
25
|
-
tzinfo (~> 2.0)
|
|
25
|
+
securerandom (>= 0.3)
|
|
26
|
+
tzinfo (~> 2.0, >= 2.0.5)
|
|
26
27
|
ast (2.4.2)
|
|
27
28
|
base64 (0.2.0)
|
|
28
29
|
bigdecimal (3.1.8)
|
|
29
30
|
byebug (11.1.3)
|
|
30
31
|
coderay (1.1.3)
|
|
31
|
-
concurrent-ruby (1.3.
|
|
32
|
+
concurrent-ruby (1.3.4)
|
|
32
33
|
connection_pool (2.4.1)
|
|
33
34
|
dachsfisch (1.0.0)
|
|
34
35
|
nokogiri (>= 1.14.1, < 2.0.0)
|
|
@@ -37,7 +38,7 @@ GEM
|
|
|
37
38
|
drb (2.2.1)
|
|
38
39
|
factory_bot (6.4.6)
|
|
39
40
|
activesupport (>= 5.0.0)
|
|
40
|
-
ffi (1.
|
|
41
|
+
ffi (1.17.0)
|
|
41
42
|
formatador (1.1.0)
|
|
42
43
|
guard (2.18.1)
|
|
43
44
|
formatador (>= 0.2.4)
|
|
@@ -60,20 +61,20 @@ GEM
|
|
|
60
61
|
listen (3.9.0)
|
|
61
62
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
|
62
63
|
rb-inotify (~> 0.9, >= 0.9.10)
|
|
64
|
+
logger (1.6.0)
|
|
63
65
|
lumberjack (1.2.10)
|
|
64
66
|
method_source (1.1.0)
|
|
65
67
|
mini_portile2 (2.8.7)
|
|
66
|
-
minitest (5.
|
|
67
|
-
mutex_m (0.2.0)
|
|
68
|
+
minitest (5.25.1)
|
|
68
69
|
nenv (0.3.0)
|
|
69
|
-
nokogiri (1.16.
|
|
70
|
+
nokogiri (1.16.7)
|
|
70
71
|
mini_portile2 (~> 2.8.2)
|
|
71
72
|
racc (~> 1.4)
|
|
72
73
|
notiffany (0.1.3)
|
|
73
74
|
nenv (~> 0.1)
|
|
74
75
|
shellany (~> 0.0)
|
|
75
|
-
parallel (1.
|
|
76
|
-
parser (3.3.
|
|
76
|
+
parallel (1.26.3)
|
|
77
|
+
parser (3.3.4.2)
|
|
77
78
|
ast (~> 2.4.1)
|
|
78
79
|
racc
|
|
79
80
|
pry (0.14.2)
|
|
@@ -82,16 +83,16 @@ GEM
|
|
|
82
83
|
pry-byebug (3.10.1)
|
|
83
84
|
byebug (~> 11.0)
|
|
84
85
|
pry (>= 0.13, < 0.15)
|
|
85
|
-
racc (1.8.
|
|
86
|
-
rack (3.
|
|
86
|
+
racc (1.8.1)
|
|
87
|
+
rack (3.1.7)
|
|
87
88
|
rainbow (3.1.1)
|
|
88
89
|
rake (13.2.1)
|
|
89
90
|
rb-fsevent (0.11.2)
|
|
90
|
-
rb-inotify (0.
|
|
91
|
+
rb-inotify (0.11.1)
|
|
91
92
|
ffi (~> 1.0)
|
|
92
|
-
regexp_parser (2.9.
|
|
93
|
-
rexml (3.
|
|
94
|
-
strscan
|
|
93
|
+
regexp_parser (2.9.2)
|
|
94
|
+
rexml (3.3.6)
|
|
95
|
+
strscan
|
|
95
96
|
rspec (3.13.0)
|
|
96
97
|
rspec-core (~> 3.13.0)
|
|
97
98
|
rspec-expectations (~> 3.13.0)
|
|
@@ -100,7 +101,7 @@ GEM
|
|
|
100
101
|
rspec-expectations (>= 2.99.0.beta1)
|
|
101
102
|
rspec-core (3.13.0)
|
|
102
103
|
rspec-support (~> 3.13.0)
|
|
103
|
-
rspec-expectations (3.13.
|
|
104
|
+
rspec-expectations (3.13.1)
|
|
104
105
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
105
106
|
rspec-support (~> 3.13.0)
|
|
106
107
|
rspec-github (2.4.0)
|
|
@@ -109,40 +110,37 @@ GEM
|
|
|
109
110
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
110
111
|
rspec-support (~> 3.13.0)
|
|
111
112
|
rspec-support (3.13.1)
|
|
112
|
-
rubocop (1.
|
|
113
|
+
rubocop (1.65.1)
|
|
113
114
|
json (~> 2.3)
|
|
114
115
|
language_server-protocol (>= 3.17.0)
|
|
115
116
|
parallel (~> 1.10)
|
|
116
117
|
parser (>= 3.3.0.2)
|
|
117
118
|
rainbow (>= 2.2.2, < 4.0)
|
|
118
|
-
regexp_parser (>=
|
|
119
|
+
regexp_parser (>= 2.4, < 3.0)
|
|
119
120
|
rexml (>= 3.2.5, < 4.0)
|
|
120
121
|
rubocop-ast (>= 1.31.1, < 2.0)
|
|
121
122
|
ruby-progressbar (~> 1.7)
|
|
122
123
|
unicode-display_width (>= 2.4.0, < 3.0)
|
|
123
|
-
rubocop-ast (1.
|
|
124
|
+
rubocop-ast (1.32.1)
|
|
124
125
|
parser (>= 3.3.1.0)
|
|
125
|
-
rubocop-
|
|
126
|
-
rubocop (~> 1.
|
|
127
|
-
rubocop-
|
|
128
|
-
rubocop (~> 1.41)
|
|
129
|
-
rubocop-performance (1.21.0)
|
|
126
|
+
rubocop-factory_bot (2.26.1)
|
|
127
|
+
rubocop (~> 1.61)
|
|
128
|
+
rubocop-performance (1.21.1)
|
|
130
129
|
rubocop (>= 1.48.1, < 2.0)
|
|
131
130
|
rubocop-ast (>= 1.31.1, < 2.0)
|
|
132
|
-
rubocop-rails (2.
|
|
131
|
+
rubocop-rails (2.26.0)
|
|
133
132
|
activesupport (>= 4.2.0)
|
|
134
133
|
rack (>= 1.1)
|
|
135
|
-
rubocop (>= 1.
|
|
134
|
+
rubocop (>= 1.52.0, < 2.0)
|
|
136
135
|
rubocop-ast (>= 1.31.1, < 2.0)
|
|
137
|
-
rubocop-rspec (
|
|
138
|
-
rubocop (~> 1.
|
|
139
|
-
|
|
140
|
-
rubocop
|
|
141
|
-
rubocop-
|
|
142
|
-
rubocop-rspec_rails (2.28.3)
|
|
143
|
-
rubocop (~> 1.40)
|
|
136
|
+
rubocop-rspec (3.0.4)
|
|
137
|
+
rubocop (~> 1.61)
|
|
138
|
+
rubocop-rspec_rails (2.30.0)
|
|
139
|
+
rubocop (~> 1.61)
|
|
140
|
+
rubocop-rspec (~> 3, >= 3.0.1)
|
|
144
141
|
ruby-progressbar (1.13.0)
|
|
145
142
|
rubyzip (2.3.2)
|
|
143
|
+
securerandom (0.3.1)
|
|
146
144
|
shellany (0.0.1)
|
|
147
145
|
simplecov (0.22.0)
|
|
148
146
|
docile (~> 1.1)
|
|
@@ -172,10 +170,12 @@ DEPENDENCIES
|
|
|
172
170
|
rspec-collection_matchers
|
|
173
171
|
rspec-github
|
|
174
172
|
rubocop
|
|
173
|
+
rubocop-factory_bot
|
|
175
174
|
rubocop-performance
|
|
176
175
|
rubocop-rails
|
|
177
176
|
rubocop-rspec
|
|
177
|
+
rubocop-rspec_rails
|
|
178
178
|
simplecov
|
|
179
179
|
|
|
180
180
|
BUNDLED WITH
|
|
181
|
-
2.5.
|
|
181
|
+
2.5.15
|
|
@@ -3,14 +3,17 @@
|
|
|
3
3
|
require 'proformaxml/helpers/export_helpers'
|
|
4
4
|
|
|
5
5
|
module ProformaXML
|
|
6
|
-
class Exporter
|
|
6
|
+
class Exporter < ServiceBase
|
|
7
7
|
include ProformaXML::Helpers::ExportHelpers
|
|
8
8
|
|
|
9
9
|
def initialize(task:, version: nil)
|
|
10
|
+
super()
|
|
10
11
|
@files = {}
|
|
11
12
|
@task = task
|
|
12
13
|
@version = version || SCHEMA_VERSIONS.first
|
|
13
|
-
|
|
14
|
+
if @version != SCHEMA_VERSION_LATEST
|
|
15
|
+
ProformaXML::TransformTask.call(task: @task, from_version: SCHEMA_VERSION_LATEST, to_version: @version)
|
|
16
|
+
end
|
|
14
17
|
end
|
|
15
18
|
|
|
16
19
|
def perform
|
|
@@ -49,7 +52,7 @@ module ProformaXML
|
|
|
49
52
|
add_dachsfisch_node(xml, @task.submission_restrictions)
|
|
50
53
|
xml.files { files(xml) }
|
|
51
54
|
add_dachsfisch_node(xml, @task.external_resources)
|
|
52
|
-
xml.send(:'model-solutions') { model_solutions(xml) } if @task.model_solutions.any?
|
|
55
|
+
xml.send(:'model-solutions') { model_solutions(xml) } if @task.model_solutions.any?
|
|
53
56
|
xml.tests { tests(xml) }
|
|
54
57
|
add_dachsfisch_node(xml, @task.grading_hints)
|
|
55
58
|
end
|
|
@@ -98,15 +101,6 @@ module ProformaXML
|
|
|
98
101
|
end
|
|
99
102
|
end
|
|
100
103
|
|
|
101
|
-
# ms-placeholder only necessary for version 2.0 where model-solutions were mandatory
|
|
102
|
-
def add_placeholders
|
|
103
|
-
return if @task.model_solutions&.any?
|
|
104
|
-
|
|
105
|
-
file = TaskFile.new(content: '', id: 'ms-placeholder-file', used_by_grader: false, visible: 'no', binary: false)
|
|
106
|
-
model_solution = ModelSolution.new(id: 'ms-placeholder', files: [file])
|
|
107
|
-
@task.model_solutions = [model_solution]
|
|
108
|
-
end
|
|
109
|
-
|
|
110
104
|
def headers
|
|
111
105
|
{
|
|
112
106
|
'xmlns' => "urn:proforma:v#{@version}",
|
|
@@ -117,8 +111,7 @@ module ProformaXML
|
|
|
117
111
|
end
|
|
118
112
|
|
|
119
113
|
def validate(doc)
|
|
120
|
-
|
|
121
|
-
validator.perform
|
|
114
|
+
ProformaXML::Validator.call(doc:, expected_version: @version)
|
|
122
115
|
end
|
|
123
116
|
|
|
124
117
|
def write_to_zip(xmldoc)
|
|
@@ -4,10 +4,11 @@ require 'active_support/core_ext/string'
|
|
|
4
4
|
require 'proformaxml/helpers/import_helpers'
|
|
5
5
|
|
|
6
6
|
module ProformaXML
|
|
7
|
-
class Importer
|
|
7
|
+
class Importer < ServiceBase
|
|
8
8
|
include ProformaXML::Helpers::ImportHelpers
|
|
9
9
|
|
|
10
10
|
def initialize(zip:, expected_version: nil)
|
|
11
|
+
super()
|
|
11
12
|
@zip = zip
|
|
12
13
|
@expected_version = expected_version
|
|
13
14
|
|
|
@@ -18,22 +19,19 @@ module ProformaXML
|
|
|
18
19
|
@task = Task.new
|
|
19
20
|
end
|
|
20
21
|
|
|
21
|
-
def proforma_namespace
|
|
22
|
-
namespace_regex = /^urn:proforma:v\d.*$/
|
|
23
|
-
namespaces = @doc.namespaces.filter do |_, href|
|
|
24
|
-
href.match? namespace_regex
|
|
25
|
-
end
|
|
26
|
-
namespaces.first.first.gsub('xmlns:', '')
|
|
27
|
-
end
|
|
28
|
-
|
|
29
22
|
def perform
|
|
23
|
+
version_name_extractor = VersionAndNamespaceExtractor.new doc: @doc
|
|
24
|
+
@pro_ns, @doc_schema_version = version_name_extractor.perform&.values_at(:namespace, :version)
|
|
25
|
+
|
|
30
26
|
errors = validate
|
|
31
27
|
raise PreImportValidationError.new(errors.map(&:message)) if errors.any?
|
|
32
28
|
|
|
33
|
-
@pro_ns = proforma_namespace
|
|
34
29
|
@task_node = @doc.xpath("/#{@pro_ns}:task")
|
|
35
30
|
|
|
36
31
|
set_data
|
|
32
|
+
if @doc_schema_version != SCHEMA_VERSION_LATEST
|
|
33
|
+
ProformaXML::TransformTask.call(task: @task, from_version: @doc_schema_version, to_version: SCHEMA_VERSION_LATEST)
|
|
34
|
+
end
|
|
37
35
|
@task
|
|
38
36
|
end
|
|
39
37
|
|
|
@@ -111,7 +109,7 @@ module ProformaXML
|
|
|
111
109
|
model_solution.files = files_from_filerefs(model_solution_node.xpath("#{@pro_ns}:filerefs"))
|
|
112
110
|
set_value_from_xml(object: model_solution, node: model_solution_node, name: 'description')
|
|
113
111
|
set_value_from_xml(object: model_solution, node: model_solution_node, name: 'internal-description')
|
|
114
|
-
@task.model_solutions << model_solution
|
|
112
|
+
@task.model_solutions << model_solution
|
|
115
113
|
end
|
|
116
114
|
|
|
117
115
|
def add_file(file_node)
|
|
@@ -147,8 +145,7 @@ module ProformaXML
|
|
|
147
145
|
end
|
|
148
146
|
|
|
149
147
|
def validate
|
|
150
|
-
|
|
151
|
-
validator.perform
|
|
148
|
+
ProformaXML::Validator.call(doc: @doc, expected_version: @expected_version)
|
|
152
149
|
end
|
|
153
150
|
end
|
|
154
151
|
end
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'active_support/core_ext/array/wrap'
|
|
4
|
+
|
|
5
|
+
module ProformaXML
|
|
6
|
+
class TransformTask < ServiceBase
|
|
7
|
+
def initialize(task:, from_version:, to_version:)
|
|
8
|
+
super()
|
|
9
|
+
@task = task
|
|
10
|
+
@from_version = from_version
|
|
11
|
+
@to_version = to_version
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def perform
|
|
15
|
+
if SCHEMA_VERSIONS.include?(@from_version) && SCHEMA_VERSIONS.include?(@to_version)
|
|
16
|
+
|
|
17
|
+
method_name = "transform_from_#{@from_version.tr('.', '_')}_to_#{@to_version.tr('.', '_')}"
|
|
18
|
+
|
|
19
|
+
send(method_name) if defined? method_name
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
def transform_from_2_0_to_2_1
|
|
26
|
+
transform_submission_restrictions_from_2_0_to_2_1 unless @task.submission_restrictions.nil?
|
|
27
|
+
transform_external_resources_from_2_0_to_2_1 unless @task.external_resources.nil?
|
|
28
|
+
|
|
29
|
+
@task.model_solutions.filter! {|model_solution| model_solution.id != 'ms-placeholder' }
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def transform_external_resources_from_2_0_to_2_1
|
|
33
|
+
ensure_array(@task.external_resources['external-resources']['external-resource']).each do |external_resource|
|
|
34
|
+
external_resource['@used-by-grader'] = external_resource['@used-by-grader'] || 'false'
|
|
35
|
+
external_resource['@visible'] = external_resource['@visible'] || 'no'
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def transform_submission_restrictions_from_2_0_to_2_1
|
|
40
|
+
ensure_array(@task.submission_restrictions['submission-restrictions']['file-restriction']).each do |fr|
|
|
41
|
+
fr['@use'] = if fr['@required'].nil? || fr.delete('@required') == 'true'
|
|
42
|
+
'required'
|
|
43
|
+
else
|
|
44
|
+
'optional'
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def transform_from_2_1_to_2_0
|
|
50
|
+
transform_submission_restrictions_from_2_1_to_2_0 unless @task.submission_restrictions.nil?
|
|
51
|
+
transform_external_resources_from_2_1_to_2_0 unless @task.external_resources.nil?
|
|
52
|
+
add_model_solution_placeholder
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def transform_external_resources_from_2_1_to_2_0
|
|
56
|
+
ensure_array(@task.external_resources['external-resources']['external-resource']).each do |external_resource|
|
|
57
|
+
external_resource.delete('@visible')
|
|
58
|
+
external_resource.delete('@usage-by-lms')
|
|
59
|
+
external_resource.delete('@used-by-grader')
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def transform_submission_restrictions_from_2_1_to_2_0
|
|
64
|
+
transform_file_restrictions_from_2_1_to_2_0
|
|
65
|
+
@task.submission_restrictions['submission-restrictions'].delete('description')
|
|
66
|
+
@task.submission_restrictions['submission-restrictions'].delete('internal-description')
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def transform_file_restrictions_from_2_1_to_2_0
|
|
70
|
+
ensure_array(@task.submission_restrictions['submission-restrictions']['file-restriction']).each do |file_restriction|
|
|
71
|
+
file_restriction['@required'] = (file_restriction['@use'].nil? || file_restriction.delete('@use') == 'required').to_s
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# when only one field is present, dachsfisch does not create an array. This method ensure, that we can work with an array
|
|
76
|
+
def ensure_array(data)
|
|
77
|
+
Array.wrap(data)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def add_model_solution_placeholder
|
|
81
|
+
return if @task.model_solutions&.any?
|
|
82
|
+
|
|
83
|
+
file = TaskFile.new(content: '', id: 'ms-placeholder-file', used_by_grader: false, visible: 'no', binary: false)
|
|
84
|
+
model_solution = ModelSolution.new(id: 'ms-placeholder', files: [file])
|
|
85
|
+
@task.model_solutions = [model_solution]
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
@@ -1,29 +1,22 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module ProformaXML
|
|
4
|
-
class Validator
|
|
5
|
-
def initialize(doc
|
|
4
|
+
class Validator < ServiceBase
|
|
5
|
+
def initialize(doc:, expected_version: nil)
|
|
6
|
+
super()
|
|
6
7
|
@doc = doc
|
|
7
8
|
@expected_version = expected_version
|
|
8
9
|
end
|
|
9
10
|
|
|
10
11
|
def perform
|
|
12
|
+
version_name_extractor = VersionAndNamespaceExtractor.new doc: @doc
|
|
13
|
+
@pro_ns, @doc_schema_version = version_name_extractor.perform&.values_at(:namespace, :version)
|
|
14
|
+
|
|
11
15
|
validate
|
|
12
16
|
end
|
|
13
17
|
|
|
14
18
|
private
|
|
15
19
|
|
|
16
|
-
def doc_schema_version
|
|
17
|
-
namespace_regex = /^urn:proforma:v(\d.*)$/
|
|
18
|
-
potential_namespaces = @doc.namespaces.filter do |_, href|
|
|
19
|
-
href.match? namespace_regex
|
|
20
|
-
end
|
|
21
|
-
return nil unless potential_namespaces.length == 1
|
|
22
|
-
|
|
23
|
-
@pro_ns = potential_namespaces.first[0].gsub('xmlns:', '')
|
|
24
|
-
@doc_schema_version ||= namespace_regex.match(potential_namespaces.first[1])&.captures&.dig(0)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
20
|
def node_as_doc_with_namespace(config_node)
|
|
28
21
|
doc = Nokogiri::XML::Document.new
|
|
29
22
|
doc.add_child(config_node.dup)
|
|
@@ -31,9 +24,9 @@ module ProformaXML
|
|
|
31
24
|
end
|
|
32
25
|
|
|
33
26
|
def validate
|
|
34
|
-
return ['no proformaxml version found'] if doc_schema_version.nil?
|
|
27
|
+
return ['no proformaxml version found'] if @doc_schema_version.nil?
|
|
35
28
|
|
|
36
|
-
version = @expected_version || doc_schema_version
|
|
29
|
+
version = @expected_version || @doc_schema_version
|
|
37
30
|
return ['version not supported'] unless SCHEMA_VERSIONS.include? version
|
|
38
31
|
|
|
39
32
|
# Both validations return an array of errors, which are empty if the validation was successful.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'proformaxml/helpers/export_helpers'
|
|
4
|
+
|
|
5
|
+
module ProformaXML
|
|
6
|
+
class VersionAndNamespaceExtractor < ServiceBase
|
|
7
|
+
def initialize(doc:)
|
|
8
|
+
super()
|
|
9
|
+
@doc = doc
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def perform
|
|
13
|
+
extract_schema_and_version
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
def extract_schema_and_version
|
|
19
|
+
namespace_regex = /^urn:proforma:v(\d.*)$/
|
|
20
|
+
potential_namespaces = @doc.namespaces.filter do |_, href|
|
|
21
|
+
href.match? namespace_regex
|
|
22
|
+
end
|
|
23
|
+
return unless potential_namespaces.length == 1
|
|
24
|
+
|
|
25
|
+
{
|
|
26
|
+
namespace: potential_namespaces.first[0].gsub('xmlns:', ''),
|
|
27
|
+
version: namespace_regex.match(potential_namespaces.first[1])&.captures&.dig(0),
|
|
28
|
+
}
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
data/lib/proformaxml/version.rb
CHANGED
data/lib/proformaxml.rb
CHANGED
|
@@ -9,15 +9,19 @@ require 'dachsfisch'
|
|
|
9
9
|
|
|
10
10
|
require 'proformaxml/version'
|
|
11
11
|
|
|
12
|
+
require 'proformaxml/services/service_base'
|
|
12
13
|
require 'proformaxml/services/importer'
|
|
13
14
|
require 'proformaxml/services/exporter'
|
|
15
|
+
require 'proformaxml/services/transform_task'
|
|
14
16
|
require 'proformaxml/services/validator'
|
|
17
|
+
require 'proformaxml/services/version_and_namespace_extractor'
|
|
15
18
|
require 'proformaxml/models/task'
|
|
16
19
|
|
|
17
20
|
module ProformaXML
|
|
18
21
|
SCHEMA_PATH = File.join(File.dirname(File.expand_path(__FILE__)), '../assets/schemas')
|
|
19
22
|
SCHEMA_FORMAT_PATH = "#{SCHEMA_PATH}/proforma-%s.xsd".freeze
|
|
20
23
|
SCHEMA_VERSIONS = %w[2.1 2.0].freeze
|
|
24
|
+
SCHEMA_VERSION_LATEST = '2.1'
|
|
21
25
|
|
|
22
26
|
TEST_TYPE_SCHEMA_NAMES = %w[java-checkstyle regexptest unittest].freeze
|
|
23
27
|
MAX_EMBEDDED_FILE_SIZE_KB = 50
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: proformaxml
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.5.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Karol
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2024-
|
|
11
|
+
date: 2024-08-26 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activemodel
|
|
@@ -117,6 +117,7 @@ files:
|
|
|
117
117
|
- ".rubocop/layout.yml"
|
|
118
118
|
- ".rubocop/lint.yml"
|
|
119
119
|
- ".rubocop/metrics.yml"
|
|
120
|
+
- ".rubocop/naming.yml"
|
|
120
121
|
- ".rubocop/rails.yml"
|
|
121
122
|
- ".rubocop/rspec.yml"
|
|
122
123
|
- ".rubocop/style.yml"
|
|
@@ -144,7 +145,10 @@ files:
|
|
|
144
145
|
- lib/proformaxml/models/test.rb
|
|
145
146
|
- lib/proformaxml/services/exporter.rb
|
|
146
147
|
- lib/proformaxml/services/importer.rb
|
|
148
|
+
- lib/proformaxml/services/service_base.rb
|
|
149
|
+
- lib/proformaxml/services/transform_task.rb
|
|
147
150
|
- lib/proformaxml/services/validator.rb
|
|
151
|
+
- lib/proformaxml/services/version_and_namespace_extractor.rb
|
|
148
152
|
- lib/proformaxml/version.rb
|
|
149
153
|
- proformaxml.gemspec
|
|
150
154
|
homepage: https://github.com/openHPI/proformaxml
|
|
@@ -167,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
167
171
|
- !ruby/object:Gem::Version
|
|
168
172
|
version: '0'
|
|
169
173
|
requirements: []
|
|
170
|
-
rubygems_version: 3.5.
|
|
174
|
+
rubygems_version: 3.5.15
|
|
171
175
|
signing_key:
|
|
172
176
|
specification_version: 4
|
|
173
177
|
summary: Implements parts of ProFormA-XML specification
|