Skip to content

Commit

Permalink
Merge branch 'rpb-158-relatedPerson' of https://github.com/hbz/rpb in…
Browse files Browse the repository at this point in the history
  • Loading branch information
fsteeg committed Apr 18, 2024
2 parents 4763f0d + 398fd45 commit b74b45f
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions conf/rppd-strapi-to-strapi.flux
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Create a shell script to update a specific field in Strapi (relatedPerson),
// 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 Strapi export data, then run with host and API token to be used:
// 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.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("
if is_empty('data.relatedPerson[]')
reject()
end
do once('map')
put_filemap('conf/maps/gndId-to-label.tsv', 'label_to_gnd', key_column:'1', value_column:'0', sep_char: '\t', expected_columns:'-1')
end
do list_as(person: 'data.relatedPerson[].*')
copy_field('person.value', _temp)
lookup(_temp, 'label_to_gnd', delete: 'true')
if exists(_temp)
prepend(_temp, 'http://rppd.lobid.org/')
move_field(_temp, 'person.value')
end
remove_field('person.id')
end
retain('id', 'data.relatedPerson[]')
")
| 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")
;

0 comments on commit b74b45f

Please sign in to comment.