From c17243cdc36809fff78ce5cc56350796e365eade Mon Sep 17 00:00:00 2001 From: Fabian Steeg Date: Thu, 13 Jun 2024 18:56:02 +0200 Subject: [PATCH] Add workflow for updating `created` in Strapi (RPB-170) Based on Allegro `f95_` values and Strapi `id`, merged via `rppdId` --- conf/rppd-strapi-to-strapi-created.flux | 47 +++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 conf/rppd-strapi-to-strapi-created.flux diff --git a/conf/rppd-strapi-to-strapi-created.flux b/conf/rppd-strapi-to-strapi-created.flux new file mode 100644 index 0000000..56674de --- /dev/null +++ b/conf/rppd-strapi-to-strapi-created.flux @@ -0,0 +1,47 @@ +// Create a shell script to update a specific field in Strapi (created), +// using curl and the Strapi update API (can't send from here, need ID in path): +// https://docs.strapi.io/dev-docs/api/rest#update-an-entry + +// Use export data from Allegro (for `f95_` values) and Strapi (for record `id`), merged via `rppdId`: +// sbt "runMain rpb.ETL conf/rppd-to-strapi.flux IN_FILE=RPB-Export_HBZ_Bio.txt OUT_FILE=output-rppd-strapi.ndjson" +// zgrep -a '"type":"api::person.person"' conf/strapi-export.tar.gz > conf/output/rppd-export.jsonl +// sbt "runMain rpb.ETL conf/rppd-strapi-to-strapi-created.flux HOST=test-metadaten-nrw:1339 API_TOKEN=bb0..." +// bash conf/output/rppd-strapi-update.sh + +default HOST = "localhost:1337"; // pass e.g. HOST=test-metadaten-nrw:1339 +default API_TOKEN = ""; // pass e.g. API_TOKEN=bb0... + +"conf/output/rppd-export.jsonl" +| open-file +| as-lines +| decode-json +| fix(" +unless all_match('data.rppdId', 'p.+') + reject() +end +move_field('data.rppdId', '_id') +retain('id', '_id') +") +| stream-to-triples(redirect="true") +| @X; + +"conf/output/output-rppd-strapi.ndjson" +| open-file +| as-lines +| decode-json +| fix(" +move_field('rppdId', '_id') +move_field('f95_', 'data.created') +retain('data.created', '_id') +") +| stream-to-triples(redirect="true") +| @X; + +@X +| wait-for-inputs("2") +| sort-triples(by="subject") +| collect-triples +| encode-json(prettyPrinting="false") +| match(pattern=".+?id...(.+)...data..(.+).+", replacement="curl -X PUT -H 'Content-Type: application/json' -d '{\"data\":$2}' -H 'Authorization: Bearer " + API_TOKEN + "' -w '\\\\n' http://" + HOST + "/api/persons/$1") +| write(FLUX_DIR + "output/rppd-strapi-update.sh") +;