Skip to content

Commit

Permalink
task: finish sample refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominick Leppich committed Sep 18, 2024
1 parent 734b96b commit 0f625a2
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 5 deletions.
40 changes: 38 additions & 2 deletions install/install_samples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,23 @@ curl_call() {
--data "$2"
}

curl_file_upload_call() {
curl --location "$HOST:$PORT/api/v1/$1" \
--header "Authorization: Bearer $TOKEN" \
--fail \
--silent \
--form "file=@\"$2\""
}

for INSTALL_DIR in $(ls $SAMPLE_PATH); do
ENDPOINT=$(echo $INSTALL_DIR | cut -d'_' -f2)
echo "Installing $ENDPOINT"
for ITEM in $(ls $SAMPLE_PATH/$INSTALL_DIR | grep ".json"); do
ITEM_NAME=$(echo "$ITEM" | cut -d'.' -f1)
ITEM_IDENTIFIER=${ENDPOINT}_"${ITEM_NAME}"

ID=$(cat $CACHE_FILE | grep $ITEM_IDENTIFIER | cut -d';' -f2)
if [ -z $ID ]; then
ID=$(cat $CACHE_FILE | grep "$ITEM_IDENTIFIER;" | cut -d';' -f2)
if [ -z "$ID" ]; then
JSON=$(cat $SAMPLE_PATH/$INSTALL_DIR/$ITEM)

# Replace ID placeholders
Expand All @@ -72,8 +80,36 @@ for INSTALL_DIR in $(ls $SAMPLE_PATH); do
ID=$(echo $RESULT | jq ".id")
echo "$ITEM_IDENTIFIER;$ID" >> $CACHE_FILE
echo -e "\tInstalled $ITEM_NAME with ID $ID"

if [ $ENDPOINT = "schemas" ]; then
echo $RESULT | jq -r ".definitions[] | \"${ITEM_IDENTIFIER}_definitions_\(.name);\(.id)\"" >> $CACHE_FILE
fi
else
echo -e "\tSkipping $ITEM_NAME, already present with ID $ID"
fi
done
for ITEM in $(ls $SAMPLE_PATH/$INSTALL_DIR | grep ".csv"); do
VOCABULARY_NAME=$(echo "$ITEM" | cut -d'.' -f1)
VOCABULARY_IDENTIFIER=vocabularies_${VOCABULARY_NAME}
VOCABULARY_ID=$(cat $CACHE_FILE | grep $VOCABULARY_IDENTIFIER | cut -d';' -f2)

if [ ! -z "$VOCABULARY_ID" ]; then
curl_file_upload_call "vocabularies/$VOCABULARY_ID/import/csv" "$SAMPLE_PATH/$INSTALL_DIR/$ITEM"
echo -e "\tImported \"$VOCABULARY_NAME\" vocabulary records"
else
echo -e "\tSkipping record imports into \"$VOCABULARY_NAME\" vocabulary, vocabulary not created beforehand!"
fi
done
for ITEM in $(ls $SAMPLE_PATH/$INSTALL_DIR | grep ".xlsx"); do
VOCABULARY_NAME=$(echo "$ITEM" | cut -d'.' -f1)
VOCABULARY_IDENTIFIER=vocabularies_${VOCABULARY_NAME}
VOCABULARY_ID=$(cat $CACHE_FILE | grep $VOCABULARY_IDENTIFIER | cut -d';' -f2)

if [ ! -z "$VOCABULARY_ID" ]; then
curl_file_upload_call "vocabularies/$VOCABULARY_ID/import/excel" "$SAMPLE_PATH/$INSTALL_DIR/$ITEM"
echo -e "\tImported \"$VOCABULARY_NAME\" vocabulary records"
else
echo -e "\tSkipping record imports into \"$VOCABULARY_NAME\" vocabulary, vocabulary not created beforehand!"
fi
done
done
2 changes: 1 addition & 1 deletion install/samples/books/3_schemas/Colors_Schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
]
},
{
"name": "Color Code",
"name": "Farbcode",
"typeId": {{types_Hex_RGB}},
"required": false,
"unique": true,
Expand Down
12 changes: 12 additions & 0 deletions install/samples/books/7_records/Authors.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
ID,Name (ger),Name (eng),Name (fre)
,Johann Wolfgang von Goethe,Johann Wolfgang von Goethe,Johann Wolfgang von Goethe
,William Shakespeare,William Shakespeare,William Shakespeare
,Ernest Hemingway,Ernest Hemingway,Ernest Hemingway
,Leo Tolstoy,Leo Tolstoy,Leo Tolstoï
,George Orwell,George Orwell,George Orwell
,Fyodor Dostoevsky,Fyodor Dostoevsky,Fyodor Dostoïevski
,Marcel Proust,Marcel Proust,Marcel Proust
,Franz Kafka,Franz Kafka,Franz Kafka
,Jane Austen,Jane Austen,Jane Austen
,Christopher Marlowe,Christopher Marlowe,Christopher Marlowe
,F. Scott Fitzgerald,Francis Scott Fitzgerald,Francis Scott Fitzgerald
16 changes: 16 additions & 0 deletions install/samples/books/7_records/Colors.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
ID,Name (ger),Name (eng),Name (fre),Farbcode
,Schwarz,Black,Noir,#000000
,Weiß,White,Blanc,#FFFFFF
,Rot,Red,Rouge,#FF0000
,Grün,Green,Vert,#00FF00
,Blau,Blue,Bleu,#0000FF
,Gelb,Yellow,Jaune,#FFFF00
,Orange,Orange,Orange,#FFA500
,Lila,Purple,Violet,#800080
,Rosa,Pink,Rose,#FFC0CB
,Grau,Gray,Gris,#808080
,Cyan,Cyan,Cyan,#00FFFF
,Magenta,Magenta,Magenta,#FF00FF
,Braun,Brown,Marron,#A52A2A
,Beige,Beige,Beige,#F5F5DC
,Olivgrün,Olive,Olive,#808000
4 changes: 4 additions & 0 deletions install/samples/books/7_records/Locations.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ID,Name (ger),Name (eng),Name (fre)
,Göttingen,Göttingen,Göttingen
,Hamburg,Hamburg,Hambourg
,Brüssel,Brussels,Bruxelles
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"schemaId": {{schemas_SKOS_Data}},
"metadataSchemaId": {{schemas_SKOS_Metadata}},
"name": "SKOS",
"description": "SKOS example vocabulary."
"name": "Role",
"description": "An example SKOS vocabulary."
}
Binary file added install/samples/skos/5_records/Role.xlsx
Binary file not shown.

0 comments on commit 0f625a2

Please sign in to comment.