Skip to content

Commit

Permalink
Add namespace utils
Browse files Browse the repository at this point in the history
  • Loading branch information
falko committed Jan 3, 2023
1 parent 47732e0 commit dec27d8
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
15 changes: 15 additions & 0 deletions xsd/dmn-namespace-utils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

DMN11='http://www.omg.org/spec/DMN/20151101/dmn.xsd'
DMN12='http://www.omg.org/spec/DMN/20180521/MODEL/'
DMN13='https://www.omg.org/spec/DMN/20191111/MODEL/'
DMN14='https://www.omg.org/spec/DMN/20211108/MODEL/'
DMNDI11='http://www.omg.org/spec/DMN/20151101/DMNDI'
DMNDI12='http://www.omg.org/spec/DMN/20180521/DMNDI/'
DMNDI13='https://www.omg.org/spec/DMN/20191111/DMNDI/'
DI='http://www.omg.org/spec/DMN/20180521/DI/'
DC='http://www.omg.org/spec/DMN/20180521/DC/'
FEEL10='http://www.omg.org/spec/FEEL/20140401'
FEEL12='http://www.omg.org/spec/DMN/20180521/FEEL/'
FEEL13='https://www.omg.org/spec/DMN/20191111/FEEL/'
FEEL14='https://www.omg.org/spec/DMN/20211108/FEEL/'
43 changes: 43 additions & 0 deletions xsd/migrate-to-new-namespaces.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash
set -euxo pipefail

XSD_DIR="$(dirname $0)"

source "$XSD_DIR/dmn-namespace-utils.sh"

find_dmn13_files() {
grep -Hirl $DMN13 --exclude='*.biodi.dmn' --exclude='test-xsd*' --exclude='dmn-namespace-utils.sh' --exclude='migrate-to-new-namespaces.sh' --exclude='DMN13.xsd' --exclude-dir=.git --exclude-dir=target
}

#find_dmn13_files

# (grep -Hirl 'http://www.omg.org/spec/DMN/20151101/dmn.xsd' --exclude='*.biodi.dmn' --exclude='test-xsd*' --exclude='migrate-to-new-namespaces.sh' --exclude='DMN12.xsd' && find -iname '*.xsd') | xargs sed -i \
# -e 's#http://www.omg.org/spec/DMN/20151101/dmn.xsd#http://www.omg.org/spec/DMN/20180521/MODEL/#' \
# -e 's#http://www.omg.org/spec/DMN/20151101/DMNDI#http://www.omg.org/spec/DMN/20180521/DMNDI/#' \
# -e 's#http://www.omg.org/spec/DMN/20151101/DI#http://www.omg.org/spec/DMN/20180521/DI/#' \
# -e 's#http://www.omg.org/spec/DMN/20151101/DC#http://www.omg.org/spec/DMN/20180521/DC/#' \
# -e 's#http://www.omg.org/spec/FEEL/20140401#http://www.omg.org/spec/DMN/20180521/FEEL/#'

# (grep -Hirl 'http://www.omg.org/spec/DMN/20151101/dmn.xsd' --exclude '*.biodi.dmn' --exclude='test-xsd*' && find -iname '*.xsd') | xargs sed -i \
# -e 's#http://www.omg.org/spec/DMN/20151101/dmn.xsd#http://www.omg.org/spec/DMN/20180521/DMN12.xsd#' \
# -e 's#http://www.omg.org/spec/DMN/20151101/DMNDI#http://www.omg.org/spec/DMN/20180521/DMNDI12.xsd#' \
# -e 's#http://www.omg.org/spec/DMN/20151101/DI#http://www.omg.org/spec/DMN/20180521/DI.xsd#' \
# -e 's#http://www.omg.org/spec/DMN/20151101/DC#http://www.omg.org/spec/DMN/20180521/DC.xsd#'

# grep -Hirl 'http://www.omg.org/spec/FEEL/20140401' --exclude=DMN11.xsd --exclude='migrate-to-new-namespaces.sh'
# grep -Hirl 'http://www.omg.org/spec/FEEL/20140401' --exclude=DMN11.xsd --exclude='migrate-to-new-namespaces.sh' | xargs sed -i -e 's#http://www.omg.org/spec/FEEL/20140401#http://www.omg.org/spec/DMN/20180521/FEEL/#'

upgrade_dmn_13_to_dmn_14() {
sed \
-e "s#$DMN13#$DMN14#g" \
-e "s#$FEEL13#$FEEL14#g" \
"$1"
}

# recursively search all DMN files in the current directory and perform a schema validation with the DMN 1.1 and 1.2 schemas
declare -i NUMBER_OF_FILES=0
while IFS= read -r -d '' DMN_FILE; do
NUMBER_OF_FILES+=1
#echo "$NUMBER_OF_FILES: $DMN_FILE"
upgrade_dmn_13_to_dmn_14 "$DMN_FILE" | sponge "$DMN_FILE"
done < <(find . '(' -iname '*.dmn*.xml' -o -iname '*.dmn' ')' -type f -print0)

0 comments on commit dec27d8

Please sign in to comment.