diff --git a/vars/uploadCube.groovy b/vars/uploadCube.groovy index fbe5b4d..6b209f0 100644 --- a/vars/uploadCube.groovy +++ b/vars/uploadCube.groovy @@ -10,10 +10,7 @@ drafter.deleteDraftset(PMD, credentials, jobDraft.id as String) } def newJobDraft = drafter.createDraftset(PMD, credentials, env.JOB_NAME as String) - String datasetPath = datasetLabel.toLowerCase() - .replaceAll('[^\\w/]', '-') - .replaceAll('-+', '-') - .replaceAll('-\$', '') + String datasetPath = util.slugise(datasetLabel) drafter.deleteGraph(PMD, credentials, newJobDraft.id as String, "http://gss-data.org.uk/graph/${datasetPath}/metadata") drafter.deleteGraph(PMD, credentials, newJobDraft.id as String, @@ -27,4 +24,4 @@ "http://gss-data.org.uk/graph/${datasetPath}") } } -} \ No newline at end of file +} diff --git a/vars/uploadDraftset.groovy b/vars/uploadDraftset.groovy index 61d413b..a51bcb2 100644 --- a/vars/uploadDraftset.groovy +++ b/vars/uploadDraftset.groovy @@ -27,10 +27,7 @@ } def newJobDraft = drafter.createDraftset(PMD, credentials, env.JOB_NAME) if (!datasetPath) { - datasetPath = datasetLabel.toLowerCase() - .replaceAll('[^\\w/]', '-') - .replaceAll('-+', '-') - .replaceAll('-\$', '') + datasetPath = util.slugise(datasetLabel) } drafter.deleteGraph(PMD, credentials, newJobDraft.id, "http://gss-data.org.uk/graph/${datasetPath}/metadata") @@ -51,4 +48,4 @@ ]) } } -} \ No newline at end of file +} diff --git a/vars/uploadTidy.groovy b/vars/uploadTidy.groovy index 077fb57..5e0901f 100644 --- a/vars/uploadTidy.groovy +++ b/vars/uploadTidy.groovy @@ -27,20 +27,14 @@ drafter.deleteDraftset(PMD, credentials, jobDraft.id) } def newJobDraft = drafter.createDraftset(PMD, credentials, env.JOB_NAME) - String datasetPath = env.JOB_NAME.toLowerCase() - .replaceAll('[^\\w/]', '-') - .replaceAll('-+', '-') - .replaceAll('-\$', '') + String datasetPath = util.slugise(env.JOB_NAME) String datasetGraph = "${baseURI}/graph/${datasetPath}" String metadataGraph = "${datasetGraph}/metadata" drafter.deleteGraph(PMD, credentials, newJobDraft.id, metadataGraph) drafter.deleteGraph(PMD, credentials, newJobDraft.id, datasetGraph) if (oldLabel) { echo "Deleting old graphs from label ${oldLabel}" - String oldDatasetPath = oldLabel.toLowerCase() - .replaceAll('[^\\w/]', '-') - .replaceAll('-+', '-') - .replaceAll('-\$', '') + String oldDatasetPath = util.slugise(oldLabel) String oldDatasetGraph = "${baseURI}/graph/${oldDatasetPath}" String oldMetadataGraph = "${oldDatasetGraph}/metadata" drafter.deleteGraph(PMD, credentials, newJobDraft.id, oldMetadataGraph) diff --git a/vars/util.groovy b/vars/util.groovy new file mode 100644 index 0000000..745ed9b --- /dev/null +++ b/vars/util.groovy @@ -0,0 +1,6 @@ +String slugise(String string) { + string.toLowerCase() + .replaceAll('[^\\w/]', '-') + .replaceAll('-+', '-') + .replaceAll('-\$', '') +}