-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen_serialization_map.sh
75 lines (70 loc) · 2.77 KB
/
gen_serialization_map.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/bash
# sudo apt install libxml2-utils
echo Check that all destination repos are in the current branch!
read -p "Press any key to proceed..."
echo Generate JSON2XML and XML2JSON mapping XSLTs
# Define an array of template configurations
declare -A template1=(
[template]="/umm_templates/ruby_json2xml_binding.rb.erb"
[output]="/BallotDefinition/json2xml.xsl"
[module]="BallotDefinition"
[model]="~/Prometheus/Generated_Code/BallotDefinition UML Model-0.0.0.rb"
[prefix]="BallotDefinition"
[schema]="http://itl.nist.gov/ns/voting/1500-20/v1"
)
declare -A template2=(
[template]="/umm_templates/ruby_json2xml_binding.rb.erb"
[output]="/CastVoteRecords/json2xml.xsl"
[module]="CVR"
[model]="~/Prometheus/Generated_Code/NIST-1.0.0.rb"
[prefix]="CVR"
[schema]="http://itl.nist.gov/ns/voting/1500-103/v1"
)
declare -A template3=(
[template]="/umm_templates/ruby_json2xml_binding.rb.erb"
[output]="/ElectionEventLogging/json2xml.xsl"
[module]="EventLogging"
[model]="~/Prometheus/Generated_Code/EventLogging-1.0.0.rb"
[prefix]="EventLogging"
[schema]="http://itl.nist.gov/ns/voting/1500-101/v1"
)
declare -A template4=(
[template]="/umm_templates/ruby_json2xml_binding.rb.erb"
[output]="/ElectionResultsReporting/json2xml.xsl"
[module]="ElectionResults"
[model]="~/Prometheus/Generated_Code/NIST-2.0.0.rb"
[prefix]="ElectionResults"
[schema]="http://itl.nist.gov/ns/voting/1500-101/v1"
)
declare -A template5=(
[template]="/umm_templates/ruby_json2xml_binding.rb.erb"
[output]="/VoterRecordsInterchange/json2xml.xsl"
[module]="VRI"
[model]="~/Prometheus/Generated_Code/VRI Implementation-0.0.0.rb"
[prefix]="VRI"
[schema]="http://itl.nist.gov/ns/voting/1500-102/v1"
)
# Store all templates in an array
templates=(template2)
set -x
# Iterate through the templates and execute `umm_template`
for template_name in "${templates[@]}"; do
eval "declare -n template=$template_name"
echo 🛠️ JSON2XML for "${template[model]}"
umm_template \
"${template[model]}" \
-t "${template[template]}" \
-o "${template[output]}" \
-l outer_module="${template[module]}",target_schema="${template[schema]}" \
-p "${template[module]}" \
# Post-processing: Check if the output is a valid XML file
if xmllint --noout "${template[output]}" 2>/dev/null; then
echo "🟩 Validation passed: ${template[output]} is a valid XML file."
# Format the XML document and overwrite the original
xmllint --format "${template[output]}" --output "${template[output]}"
echo "🦋 Formatted and overwritten: ${template[output]}"
else
echo "😡 Validation failed: ${template[output]} is not a valid XML file." >&2
fi
done
echo XML2JSON