From 1cfb08779ea0e00be69e072a940b3063e049fe6b Mon Sep 17 00:00:00 2001 From: Ofir Sonsino Date: Wed, 31 Jan 2018 17:19:00 +0200 Subject: org.onap migration Change-Id: I52f0b2851f2c765752b6d21f49b32136d7d72a3d Issue-ID: VID-86 Signed-off-by: Ofir Sonsino --- .../main/resources/scripts/category_parameter.sh | 64 ++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 vid-app-common/src/main/resources/scripts/category_parameter.sh (limited to 'vid-app-common/src/main/resources/scripts/category_parameter.sh') diff --git a/vid-app-common/src/main/resources/scripts/category_parameter.sh b/vid-app-common/src/main/resources/scripts/category_parameter.sh new file mode 100644 index 000000000..0ff1c73c3 --- /dev/null +++ b/vid-app-common/src/main/resources/scripts/category_parameter.sh @@ -0,0 +1,64 @@ +#!/bin/bash +usage() { echo -e "Usage: $0 [-o ] [-p ] [-c category_name] [-f FAMILY]" 1>&2; exit 1; } +while getopts ":o:p:c:f:" opt; do + case ${opt} in + o) + OPERATION=${OPTARG} + ;; + p) + FILE=${OPTARG} + ;; + c) + CATEGORY=${OPTARG} + ;; + f) + FAMILY=${OPTARG} + ;; + *) + usage + ;; + esac +done +shift $((OPTIND-1)) +if [ -z "${FILE}" ] || [ -z "${OPERATION}" ]; then + usage +fi +if [ ${OPERATION} != 'ADD' ] && [ ${OPERATION} != 'GET' ]; then + usage +fi +if [ ${OPERATION} = 'ADD' ]; then + if [ -z "${CATEGORY}" ] ; then + usage + fi + OPERATION='POST' +fi +if [ ${OPERATION} = 'GET' ]; then + if [ -z "${FAMILY}" ] ; then + usage + fi +fi +URL="http://127.0.0.1:8080/vid/maintenance/category_parameter" +if [ ${OPERATION} = 'GET' ]; then + FULLURL="${URL}?familyName=${FAMILY}" + echo "Sending request: ${FULLURL}" + echo -e "------------------------\nwget output:" + wget -nv -O "${FILE}" "${FULLURL}" + RC=$? + echo "---------------------------" + if [ $RC -eq 0 ]; then + echo "Result saved to ${FILE}" + else + echo "Failed to get category parameters list" + fi +else + BODY=$(cat ${FILE} | awk ' BEGIN { ; print " {\"options\" : [ "} { gsub(/ /, "", $0) ; printf "%s\"%s\"",separator,$1 ;separator = ", ";} END { printf " ]} "}') + FULLURL="${URL}/${CATEGORY}" + echo "Sending request: ${FULLURL} ${OPERATION} ${BODY}" + echo -e "------------------------\nwget output:" + wget --method="${OPERATION}" --body-data="${BODY}" --header=Content-Type:application/json --content-on-error -nv -O - "${FULLURL}" + RC=$? + echo "---------------------------" + if [ $RC -ne 0 ]; then + echo "Failed to ADD options to category ${CATEGORY}" + fi +fi -- cgit 1.2.3-korg