From cdd92fc1811d1908fba21e6f68004e56874a04cf Mon Sep 17 00:00:00 2001 From: felixlohmeier Date: Sun, 13 Nov 2022 21:43:04 +0000 Subject: [PATCH] add mappings and improve error handling --- orcli | 28 ++++++++++++++++++++++++---- src/bashly.yml | 4 ++-- src/transform_command.sh | 24 ++++++++++++++++++++++-- 3 files changed, 48 insertions(+), 8 deletions(-) diff --git a/orcli b/orcli index b07d801..8287b81 100755 --- a/orcli +++ b/orcli @@ -79,7 +79,7 @@ orcli_usage() { printf " orcli export tsv \"duplicates\"\n" printf " orcli export tsv \"duplicates\" --output \"duplicates.tsv\"\n" printf " orcli run --interactive\n" - printf " orcli run << EOF\n orcli import csv \"https://git.io/fj5hF\" --projectName \"duplicates\"\n orcli info \"duplicates\"\n orcli export tsv \"duplicates\"\n EOF\n" + printf " orcli run << EOF\n orcli import csv \"https://git.io/fj5hF\" --projectName \"duplicates\"\n orcli transform \"duplicates\" \"https://git.io/fj5ju\"\n orcli export tsv \"duplicates\"\n EOF\n" echo # :command.footer @@ -490,7 +490,7 @@ orcli_run_usage() { # :command.usage_examples printf "Examples:\n" printf " orcli run --interactive\n" - printf " orcli run << EOF\n orcli import csv \"https://git.io/fj5hF\" --projectName \"duplicates\"\n orcli info \"duplicates\"\n orcli export tsv \"duplicates\"\n EOF\n" + printf " orcli run << EOF\n orcli import csv \"https://git.io/fj5hF\" --projectName \"duplicates\"\n orcli transform \"duplicates\" \"https://git.io/fj5ju\"\n orcli export tsv \"duplicates\"\n EOF\n" printf " orcli run --memory \"2000M\" --port \"3334\" << EOF\n orcli import csv \"https://git.io/fj5hF\" --projectName \"duplicates\" &\n orcli import csv \"https://git.io/fj5hF\" --projectName \"copy\" &\n wait\n echo \"finished import\"\n orcli export csv \"duplicates\" --output duplicates.csv &\n orcli export tsv \"duplicates\" --output duplicates.tsv &\n wait\n wc duplicates*\n EOF\n" printf " orcli run --interactive \"file1.sh\" \"file2.sh\" - << EOF\n echo \"finished in \$SECONDS seconds\"\n EOF\n" echo @@ -892,7 +892,22 @@ orcli_transform_command() { # parse one line/operation into array declare -A data="($(echo "$line" | jq -r 'to_entries | map("[\(.key)]=" + @sh "\(.value|tostring)") | .[]'))" # map operation names to command endpoints + # https://github.com/OpenRefine/OpenRefine/blob/master/main/webapp/modules/core/MOD-INF/controller.js com="${data[op]#core/}" + if [[ $com == "multivalued-cell-join" ]]; then com="join-multi-value-cells"; fi + if [[ $com == "multivalued-cell-split" ]]; then com="split-multi-value-cells"; fi + if [[ $com == "column-addition" ]]; then com="add-column"; fi + if [[ $com == "column-addition-by-fetching-urls" ]]; then com="add-column-by-fetching-urls"; fi + if [[ $com == "column-removal" ]]; then com="remove-column"; fi + if [[ $com == "column-rename" ]]; then com="rename-column"; fi + if [[ $com == "column-move" ]]; then com="move-column"; fi + if [[ $com == "column-split" ]]; then com="split-column"; fi + if [[ $com == "column-reorder" ]]; then com="reorder-columns"; fi + if [[ $com == "recon" ]]; then com="reconcile"; fi + if [[ $com == "extend-reconciled-data" ]]; then com="extend-data"; fi + if [[ $com == "row-star" ]]; then com="annotate-rows"; fi + if [[ $com == "row-flag" ]]; then com="annotate-rows"; fi + if [[ $com == "row-removal" ]]; then com="remove-rows"; fi if [[ $com == "row-reorder" ]]; then com="reorder-rows"; fi unset "data[op]" # rename engineConfig to engine @@ -907,9 +922,14 @@ orcli_transform_command() { done) # get project id and csrf token; post data to it's individual endpoint if response="$(curl -fs --data "project=$(get_id "${args[project]}")" "${curloptions[@]}" "${OPENREFINE_URL}/command/core/${com}$(get_csrf)")"; then - log "applied ${com} to ${args[project]}" "Response: $(jq '.historyEntry.description' <<< "$response")" + response_code="$(jq -r '.code' <<<"$response")" + if [[ $response_code == "ok" ]]; then + log "transformed ${args[project]} with ${com}" "Response: $(jq -r '.historyEntry.description' <<<"$response")" + else + error "transforming ${args[project]} with ${com} from ${files[$i]} failed!" "Response: $(jq -r '.message' <<<"$response")" + fi else - error "applying ${com} from ${files[$i]} to ${args[project]} failed!" + error "transforming ${args[project]} with ${com} from ${files[$i]} failed!" fi unset data done diff --git a/src/bashly.yml b/src/bashly.yml index 28f1cae..4f05d8b 100644 --- a/src/bashly.yml +++ b/src/bashly.yml @@ -23,7 +23,7 @@ examples: - |- orcli run << EOF orcli import csv "https://git.io/fj5hF" --projectName "duplicates" - orcli info "duplicates" + orcli transform "duplicates" "https://git.io/fj5ju" orcli export tsv "duplicates" EOF @@ -148,7 +148,7 @@ commands: - |- orcli run << EOF orcli import csv "https://git.io/fj5hF" --projectName "duplicates" - orcli info "duplicates" + orcli transform "duplicates" "https://git.io/fj5ju" orcli export tsv "duplicates" EOF - |- diff --git a/src/transform_command.sh b/src/transform_command.sh index 51aa9d6..fde2047 100644 --- a/src/transform_command.sh +++ b/src/transform_command.sh @@ -34,7 +34,22 @@ for i in "${!files[@]}"; do # parse one line/operation into array declare -A data="($(echo "$line" | jq -r 'to_entries | map("[\(.key)]=" + @sh "\(.value|tostring)") | .[]'))" # map operation names to command endpoints + # https://github.com/OpenRefine/OpenRefine/blob/master/main/webapp/modules/core/MOD-INF/controller.js com="${data[op]#core/}" + if [[ $com == "multivalued-cell-join" ]]; then com="join-multi-value-cells"; fi + if [[ $com == "multivalued-cell-split" ]]; then com="split-multi-value-cells"; fi + if [[ $com == "column-addition" ]]; then com="add-column"; fi + if [[ $com == "column-addition-by-fetching-urls" ]]; then com="add-column-by-fetching-urls"; fi + if [[ $com == "column-removal" ]]; then com="remove-column"; fi + if [[ $com == "column-rename" ]]; then com="rename-column"; fi + if [[ $com == "column-move" ]]; then com="move-column"; fi + if [[ $com == "column-split" ]]; then com="split-column"; fi + if [[ $com == "column-reorder" ]]; then com="reorder-columns"; fi + if [[ $com == "recon" ]]; then com="reconcile"; fi + if [[ $com == "extend-reconciled-data" ]]; then com="extend-data"; fi + if [[ $com == "row-star" ]]; then com="annotate-rows"; fi + if [[ $com == "row-flag" ]]; then com="annotate-rows"; fi + if [[ $com == "row-removal" ]]; then com="remove-rows"; fi if [[ $com == "row-reorder" ]]; then com="reorder-rows"; fi unset "data[op]" # rename engineConfig to engine @@ -49,9 +64,14 @@ for i in "${!files[@]}"; do done) # get project id and csrf token; post data to it's individual endpoint if response="$(curl -fs --data "project=$(get_id "${args[project]}")" "${curloptions[@]}" "${OPENREFINE_URL}/command/core/${com}$(get_csrf)")"; then - log "applied ${com} to ${args[project]}" "Response: $(jq '.historyEntry.description' <<< "$response")" + response_code="$(jq -r '.code' <<<"$response")" + if [[ $response_code == "ok" ]]; then + log "transformed ${args[project]} with ${com}" "Response: $(jq -r '.historyEntry.description' <<<"$response")" + else + error "transforming ${args[project]} with ${com} from ${files[$i]} failed!" "Response: $(jq -r '.message' <<<"$response")" + fi else - error "applying ${com} from ${files[$i]} to ${args[project]} failed!" + error "transforming ${args[project]} with ${com} from ${files[$i]} failed!" fi unset data done