From d2c7cda4214a179cfb07233ef36bedbcb54b668b Mon Sep 17 00:00:00 2001 From: Olivier DOSSMANN Date: Fri, 7 Feb 2020 16:30:48 +0100 Subject: [PATCH] by_json: Generate circulation policies * Generate a new circulation policies file: policies.svg * Parses Circulation policies * Parses Item Types --- by_json/Makefile | 5 +- by_json/filters/circulation_policies | 12 ++++ by_json/filters/item_types | 6 ++ by_json/gen_policies.sh | 27 +++++++++ by_json/process_cp.sh | 59 +++++++++++++++++++ by_json/process_it.sh | 27 +++++++++ by_json/templates/gizmo.tmpl | 2 +- .../templates/label_circulation_policies.tmpl | 5 ++ by_json/templates/label_item_types.tmpl | 1 + by_json/templates/label_settings.tmpl | 1 + 10 files changed, 143 insertions(+), 2 deletions(-) create mode 100644 by_json/filters/circulation_policies create mode 100644 by_json/filters/item_types create mode 100755 by_json/gen_policies.sh create mode 100644 by_json/process_cp.sh create mode 100644 by_json/process_it.sh create mode 100644 by_json/templates/label_circulation_policies.tmpl create mode 100644 by_json/templates/label_item_types.tmpl create mode 100644 by_json/templates/label_settings.tmpl diff --git a/by_json/Makefile b/by_json/Makefile index 1079603..f304f20 100644 --- a/by_json/Makefile +++ b/by_json/Makefile @@ -1,4 +1,4 @@ -all: orgas.svg +all: orgas.svg policies.svg # All .dot files are generated by gen_%.sh file (gen_orgas.sh for example) %.dot: gen_%.sh @@ -9,3 +9,6 @@ all: orgas.svg clean: rm -f *.svg *.dot + +# Keep temporary files (dot files) for debug +.PRECIOUS: %.dot diff --git a/by_json/filters/circulation_policies b/by_json/filters/circulation_policies new file mode 100644 index 0000000..9a035c1 --- /dev/null +++ b/by_json/filters/circulation_policies @@ -0,0 +1,12 @@ +.[] | { + pid, + name, + description, + organisation: .organisation."$ref", + allow_checkout, + checkout_duration, + allow_requests, + policy_library_level, + libraries: [.libraries[]?], + settings +} diff --git a/by_json/filters/item_types b/by_json/filters/item_types new file mode 100644 index 0000000..a993ec9 --- /dev/null +++ b/by_json/filters/item_types @@ -0,0 +1,6 @@ +.[] | { + pid, + name, + organisation: .organisation."$ref", + type +} diff --git a/by_json/gen_policies.sh b/by_json/gen_policies.sh new file mode 100755 index 0000000..d20d3d5 --- /dev/null +++ b/by_json/gen_policies.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +# +# Generate a dot file to create graph of RERO-ils data +# + +# CONFIG +RERO_DIR="${HOME}/projets/rero/rero-ils" + +# Load commons variables, functions and statements +source commons.sh + +# Graph header +title="Circulation policies details." +save "templates/header.tmpl" + +# ORGANISATIONS +source process_orgas.sh +# LIBRARIES +source process_lib.sh +# CIRCULATION POLICIES +source process_cp.sh + +# Graph footer +save "templates/footer.tmpl" + +# END of program +exit 0 diff --git a/by_json/process_cp.sh b/by_json/process_cp.sh new file mode 100644 index 0000000..c4894f0 --- /dev/null +++ b/by_json/process_cp.sh @@ -0,0 +1,59 @@ +# DEPENDS ON: Organisations (process_orgas.sh), Libraries (process_lib.sh) + +# Main configuration +while read cp +do + # main info + pid=$(echo $cp|jq -r .pid) + name=$(echo $cp|jq -r .name) + description=$(echo $cp|jq -r .description) + orga=$(echo $cp|jq -r .organisation) + + # Additional info + checkout=$(echo $cp|jq -r .allow_checkout) + duration=$(echo $cp|jq -r .checkout_duration) + requests=$(echo $cp|jq -r .allow_requests) + library_level=$(echo $cp|jq -r .policy_library_level) + + # reset values (because settings overwrites them) + shape="doubleoctagon" + color="${COLOR5}" + border_color="${COLOR5}" + additionals="" + # write result in output + identifier="CP${pid}" + label="$(render templates/label_circulation_policies.tmpl)" + save "${tmpl_gizmo}" + + # Make a link with organisation if present + if [[ -n "${orga}" ]]; then + orga_pid=$(echo $orga|rev|cut -d "/" -f 1|rev) + relation="Orga${orga_pid}" + save "${tmpl_link}" + fi + + # Parse settings (if have content) + settings=$(echo $cp|jq -r .settings) + if [[ "${settings}" != "null" ]]; then + for setting in $(echo $settings|jq -c '.[]') + do + pt_pid=$(echo $setting|jq -r '.patron_type."$ref"'|rev| cut -d"/" -f1 |rev) + it_pid=$(echo $setting|jq -r '.item_type."$ref"'|rev|cut -d"/" -f1|rev) + + # reset values + shape="Mrecord" + color="${COLOR4}" + border_color="black" + additionals="" + # write result in output + identifier="Setting${pid}${pt_pid}${it_pid}" + label=$(render templates/label_settings.tmpl) + save "${tmpl_gizmo}" + + # Make a link between setting and Circulation Policy + relation="CP${pid}" + save "${tmpl_link}" + done + fi + +done <<< $(parse_json "circulation_policies") diff --git a/by_json/process_it.sh b/by_json/process_it.sh new file mode 100644 index 0000000..348e9cc --- /dev/null +++ b/by_json/process_it.sh @@ -0,0 +1,27 @@ +# DEPENDS ON: Organisations (process_orgas.sh) + +# Colors +IT_COLOR="${COLOR4}" # item_types + +# Main configuration +shape="polygon" +color="${IT_COLOR}" +additionals="sides=6" +while read it +do + pid=$(echo $it|jq -r .pid) + name=$(echo $it|jq -r .name) + orga=$(echo $it|jq -r .organisation) + itype="$(echo $it|jq -r '.type')" + # write result in output + identifier="IType${pid}" + label="$(render templates/label_item_types.tmpl)" + save "${tmpl_gizmo}" + + # Make a link with organisation if present + if [[ -n "${orga}" ]]; then + orga_pid=$(echo $orga|rev|cut -d "/" -f 1|rev) + relation="Orga${orga_pid}" + save "${tmpl_link}" + fi +done <<< $(parse_json "item_types") diff --git a/by_json/templates/gizmo.tmpl b/by_json/templates/gizmo.tmpl index 58e5950..37e6906 100644 --- a/by_json/templates/gizmo.tmpl +++ b/by_json/templates/gizmo.tmpl @@ -1 +1 @@ -\"${identifier}\" [shape=${shape} color=\"transparent\" style=filled fillcolor=\"${color}\" label=${label} ${additionals}] +\"${identifier}\" [shape=${shape} color=\"${border_color:-transparent}\" style=filled fillcolor=\"${color}\" label=${label} ${additionals}] diff --git a/by_json/templates/label_circulation_policies.tmpl b/by_json/templates/label_circulation_policies.tmpl new file mode 100644 index 0000000..adfdc99 --- /dev/null +++ b/by_json/templates/label_circulation_policies.tmpl @@ -0,0 +1,5 @@ +<${name}
${description}
+Checkout: ${checkout} (duration: ${duration})
+Requests: ${requests}
+Policy library level: ${library_level}
+PID: ${pid}> diff --git a/by_json/templates/label_item_types.tmpl b/by_json/templates/label_item_types.tmpl new file mode 100644 index 0000000..02e4239 --- /dev/null +++ b/by_json/templates/label_item_types.tmpl @@ -0,0 +1 @@ +<${name}
(type: ${itype})
PID: ${pid}> diff --git a/by_json/templates/label_settings.tmpl b/by_json/templates/label_settings.tmpl new file mode 100644 index 0000000..7fe9813 --- /dev/null +++ b/by_json/templates/label_settings.tmpl @@ -0,0 +1 @@ +\"Patron type PID: ${pt_pid} | Item type PID: ${it_pid}\"