Skip to content

Commit

Permalink
Merge pull request #34 from nfdi4health/feat/dv-permalinks
Browse files Browse the repository at this point in the history
feat(k8s.dataverse): update Dataverse configuration for Permalinks
  • Loading branch information
vera authored Dec 13, 2024
2 parents 615ad6f + 218efca commit 5b0c623
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 50 deletions.
2 changes: 1 addition & 1 deletion k8s/dataverse/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.8.0
version: 0.8.1

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
52 changes: 19 additions & 33 deletions k8s/dataverse/persona/nfdi4health/generate-permalink.sql
Original file line number Diff line number Diff line change
@@ -1,47 +1,33 @@
-- A script for creating, through a database stored procedure, sequential
-- 8 character identifiers from a base36 representation of current timestamp.
-- Adapted from: https://guides.dataverse.org/en/latest/_downloads/772201110a1c1b429e7c3336b6e9d36d/identifier_from_timestamp.sql
-- Adapted from: https://github.com/IQSS/dataverse/blob/a36db2d7df0d9976c00179b82f11cfb338a6cfc8/doc/sphinx-guides/source/_static/util/createsequence.sql

CREATE OR REPLACE FUNCTION base36_encode(
IN digits bigint, IN min_width int = 0)
RETURNS varchar AS $$
DO $$
DECLARE
chars char[];
ret varchar;
val bigint;
last_val bigint;
BEGIN
chars := ARRAY[
'0','1','2','3','4','5','6','7','8','9',
'A','B','C','D','E','F','G','H','I','J',
'K','L','M','N','O','P','Q','R','S','T',
'U','V','W','X','Y','Z'];
val := digits;
ret := '';
IF val < 0 THEN
val := val * -1;
END IF;
WHILE val != 0 LOOP
ret := chars[(val % 36)+1] || ret;
val := val / 36;
END LOOP;
-- Get the last value of the existing sequence
SELECT last_value INTO last_val FROM dvobject_id_seq;

IF min_width > 0 AND char_length(ret) < min_width THEN
ret := lpad(ret, min_width, '0');
END IF;
-- Create the new sequence with the desired start and min values
EXECUTE format('
CREATE SEQUENCE datasetidentifier_seq
INCREMENT BY 1
MINVALUE %s
MAXVALUE 9223372036854775807
CACHE 1
', last_val + 1);
END $$;

RETURN ret;
END;
$$ LANGUAGE plpgsql IMMUTABLE;
ALTER TABLE datasetidentifier_seq OWNER TO "dataverse";

-- And now create a PostgreSQL FUNCTION, for JPA to
-- access as a NamedStoredProcedure:

CREATE OR REPLACE FUNCTION generateIdentifierFromStoredProcedure()
RETURNS varchar AS $$
DECLARE
curr_time_msec bigint;
identifier varchar;
identifier varchar;
BEGIN
curr_time_msec := extract(epoch from now())*1000;
identifier := base36_encode(curr_time_msec);
identifier := nextval('datasetidentifier_seq')::varchar;
RETURN identifier;
END;
$$ LANGUAGE plpgsql IMMUTABLE;
10 changes: 6 additions & 4 deletions k8s/dataverse/persona/nfdi4health/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ echo "# hide progress meter
# fail script on server error
--fail-with-body" > ~/.curlrc

echo "Configuring PID permalink generator function"
PGPASSWORD=$DATAVERSE_DB_PASSWORD psql -h $DATAVERSE_DB_HOST -U $DATAVERSE_DB_USER < /scripts/bootstrap/nfdi4health/generate-permalink.sql
echo

echo "Setting superuser status"
curl -X PUT "${DATAVERSE_URL}/api/admin/superuser/dataverseAdmin" -d true
echo
Expand Down Expand Up @@ -141,6 +137,12 @@ while IFS= read -r DATAVERSE; do
fi
done <<< "${DATAVERSES}"

# This should be done after creating dataverses if we want a chance of keeping the database IDs and Permalink IDs of our
# datasets in sync
echo "Configuring PID permalink generator function"
PGPASSWORD=$DATAVERSE_DB_PASSWORD psql -h $DATAVERSE_DB_HOST -U $DATAVERSE_DB_USER < /scripts/bootstrap/nfdi4health/generate-permalink.sql
echo

# Last step as existence of one block is the indicator for a complete bootstrapped installation
echo "Load custom metadata blocks"
#curl -X POST -H "Content-type: text/tab-separated-values" $DATAVERSE_HOST/api/admin/datasetfield/load --upload-file customMDS.tsv
Expand Down
16 changes: 4 additions & 12 deletions k8s/dataverse/templates/dataverse-pod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,26 +97,18 @@ spec:
- name: DATAVERSE_PID_PROVIDERS
value: "fake,csh,ctgov,euctr,per,isrctn,ctri,jprn,actrn,drks"
- name: DATAVERSE_PID_DEFAULT_PROVIDER
value: "fake"
- name: DATAVERSE_PID_FAKE_TYPE
value: "FAKE"
- name: DATAVERSE_PID_FAKE_LABEL
value: "Fake DOI Provider"
- name: DATAVERSE_PID_FAKE_SHOULDER
value: "FK2/"
- name: DATAVERSE_PID_FAKE_AUTHORITY
value: "10.5072"
value: "csh"
- name: DATAVERSE_PID_CSH_TYPE
value: "perma"
- name: DATAVERSE_PID_CSH_LABEL
value: "Permalink Provider"
- name: DATAVERSE_PID_CSH_AUTHORITY
value: {{.Values.dataverse.pid.permalink.authority}}
- name: DATAVERSE_PID_CSH_SHOULDER
value: {{.Values.dataverse.pid.permalink.shoulder}}
- name: DATAVERSE_PID_CSH_BASE_URL
value: ""
- name: DATAVERSE_PID_CSH_PERMALINK_BASE_URL
value: {{.Values.dataverse.pid.permalink.base_url}}
- name: DATAVERSE_PID_CSH_SEPARATOR
- name: DATAVERSE_PID_CSH_PERMALINK_SEPARATOR
value: {{.Values.dataverse.pid.permalink.separator | quote}}
- name: DATAVERSE_PID_CSH_IDENTIFIER_GENERATION_STYLE
value: "storedProcGenerated"
Expand Down

0 comments on commit 5b0c623

Please sign in to comment.