Merge pull request #81 from opencultureconsulting:felixlohmeier/transform-error-handling-78
put get_id at the beginning
This commit is contained in:
commit
7032bb20b2
32
orcli
32
orcli
|
@ -864,8 +864,9 @@ orcli_list_command() {
|
|||
orcli_info_command() {
|
||||
# src/info_command.sh
|
||||
# shellcheck shell=bash disable=SC2154
|
||||
get_id "${args[project]}"
|
||||
|
||||
# get project id
|
||||
projectid="$(get_id "${args[project]}")"
|
||||
echo "$projectid"
|
||||
}
|
||||
|
||||
# :command.function
|
||||
|
@ -885,6 +886,9 @@ orcli_transform_command() {
|
|||
files=()
|
||||
eval "files=(${args[file]})"
|
||||
|
||||
# get project id
|
||||
projectid="$(get_id "${args[project]}")"
|
||||
|
||||
# create tmp directory
|
||||
tmpdir="$(mktemp -d)"
|
||||
trap 'rm -rf "$tmpdir"' 0 2 3 15
|
||||
|
@ -925,13 +929,13 @@ orcli_transform_command() {
|
|||
fi
|
||||
for line in "${jsonlines[@]}"; do
|
||||
# parse one line/operation into array
|
||||
declare -A data="($(echo "$line" | jq -r 'to_entries | map("[\(.key)]=" + @sh "\(.value|tostring)") | .[]'))"
|
||||
if [[ ! ${data[op]} ]]; then
|
||||
declare -A array="($(echo "$line" | jq -r 'to_entries | map("[\(.key)]=" + @sh "\(.value|tostring)") | .[]'))"
|
||||
if [[ ! ${array[op]} ]]; then
|
||||
error "parsing ${files[$i]} failed!"
|
||||
fi
|
||||
# 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/}"
|
||||
com="${array[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
|
||||
|
@ -947,19 +951,19 @@ orcli_transform_command() {
|
|||
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]"
|
||||
unset "array[op]"
|
||||
# rename engineConfig to engine
|
||||
data[engine]="${data[engineConfig]}"
|
||||
unset "data[engineConfig]"
|
||||
array[engine]="${array[engineConfig]}"
|
||||
unset "array[engineConfig]"
|
||||
# drop description
|
||||
unset "data[description]"
|
||||
unset "array[description]"
|
||||
# prepare curl options
|
||||
mapfile -t curloptions < <(for K in "${!data[@]}"; do
|
||||
mapfile -t curloptions < <(for K in "${!array[@]}"; do
|
||||
echo "--data"
|
||||
echo "$K=${data[$K]}"
|
||||
echo "$K=${array[$K]}"
|
||||
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
|
||||
# get csrf token and post data to it's individual endpoint
|
||||
if response="$(curl -fs --data "project=${projectid}" "${curloptions[@]}" "${OPENREFINE_URL}/command/core/${com}$(get_csrf)")"; then
|
||||
response_code="$(jq -r '.code' <<<"$response")"
|
||||
if [[ $response_code == "ok" ]]; then
|
||||
log "transformed ${args[project]} with ${com}" "Response: $(jq -r '.historyEntry.description' <<<"$response")"
|
||||
|
@ -969,7 +973,7 @@ orcli_transform_command() {
|
|||
else
|
||||
error "transforming ${args[project]} with ${com} from ${files[$i]} failed!"
|
||||
fi
|
||||
unset data
|
||||
unset array
|
||||
done
|
||||
done
|
||||
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
# shellcheck shell=bash disable=SC2154
|
||||
get_id "${args[project]}"
|
||||
# get project id
|
||||
projectid="$(get_id "${args[project]}")"
|
||||
echo "$projectid"
|
|
@ -12,6 +12,9 @@ fi
|
|||
files=()
|
||||
eval "files=(${args[file]})"
|
||||
|
||||
# get project id
|
||||
projectid="$(get_id "${args[project]}")"
|
||||
|
||||
# create tmp directory
|
||||
tmpdir="$(mktemp -d)"
|
||||
trap 'rm -rf "$tmpdir"' 0 2 3 15
|
||||
|
@ -52,13 +55,13 @@ for i in "${!files[@]}"; do
|
|||
fi
|
||||
for line in "${jsonlines[@]}"; do
|
||||
# parse one line/operation into array
|
||||
declare -A data="($(echo "$line" | jq -r 'to_entries | map("[\(.key)]=" + @sh "\(.value|tostring)") | .[]'))"
|
||||
if [[ ! ${data[op]} ]]; then
|
||||
declare -A array="($(echo "$line" | jq -r 'to_entries | map("[\(.key)]=" + @sh "\(.value|tostring)") | .[]'))"
|
||||
if [[ ! ${array[op]} ]]; then
|
||||
error "parsing ${files[$i]} failed!"
|
||||
fi
|
||||
# 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/}"
|
||||
com="${array[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
|
||||
|
@ -74,19 +77,19 @@ for i in "${!files[@]}"; do
|
|||
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]"
|
||||
unset "array[op]"
|
||||
# rename engineConfig to engine
|
||||
data[engine]="${data[engineConfig]}"
|
||||
unset "data[engineConfig]"
|
||||
array[engine]="${array[engineConfig]}"
|
||||
unset "array[engineConfig]"
|
||||
# drop description
|
||||
unset "data[description]"
|
||||
unset "array[description]"
|
||||
# prepare curl options
|
||||
mapfile -t curloptions < <(for K in "${!data[@]}"; do
|
||||
mapfile -t curloptions < <(for K in "${!array[@]}"; do
|
||||
echo "--data"
|
||||
echo "$K=${data[$K]}"
|
||||
echo "$K=${array[$K]}"
|
||||
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
|
||||
# get csrf token and post data to it's individual endpoint
|
||||
if response="$(curl -fs --data "project=${projectid}" "${curloptions[@]}" "${OPENREFINE_URL}/command/core/${com}$(get_csrf)")"; then
|
||||
response_code="$(jq -r '.code' <<<"$response")"
|
||||
if [[ $response_code == "ok" ]]; then
|
||||
log "transformed ${args[project]} with ${com}" "Response: $(jq -r '.historyEntry.description' <<<"$response")"
|
||||
|
@ -96,6 +99,6 @@ for i in "${!files[@]}"; do
|
|||
else
|
||||
error "transforming ${args[project]} with ${com} from ${files[$i]} failed!"
|
||||
fi
|
||||
unset data
|
||||
unset array
|
||||
done
|
||||
done
|
||||
|
|
Loading…
Reference in New Issue