diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..485dee6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea diff --git a/vars/drafter.groovy b/vars/drafter.groovy index be0cf40..756f18e 100644 --- a/vars/drafter.groovy +++ b/vars/drafter.groovy @@ -53,6 +53,21 @@ } } +def queryDraftset(String baseUrl, String credentials, String id, String query, String type) { + echo "Querying draftset ${id}" + String sparqlQuery = java.net.URLEncoder.encode(query, "UTF-8") + def response = httpRequest(customHeaders: [[name: 'Accept', value: type]], + authentication: credentials, + httpMode: 'GET', + validResponseCodes: '200:599', + url: "${baseUrl}/v1/draftset/${id}/query?query=${sparqlQuery}&union-with-live=true") + if (response.status == 200) { + return response.content + } else { + error "Problem querying draftset ${response.status} : ${response.content}" + } +} + def deleteGraph(String baseUrl, String credentials, String id, String graph) { echo "Deleting graph <${graph}> from draftset ${id}" String encGraph = java.net.URLEncoder.encode(graph, "UTF-8") diff --git a/vars/uploadCodelist.groovy b/vars/uploadCodelist.groovy new file mode 100644 index 0000000..1ddc6a6 --- /dev/null +++ b/vars/uploadCodelist.groovy @@ -0,0 +1,16 @@ +def call(String csv, String name) { + configFileProvider([configFile(fileId: 'pmd', variable: 'configfile')]) { + def config = readJSON(text: readFile(file: configfile)) + String PMD = config['pmd_api'] + String credentials = config['credentials'] + String PIPELINE = config['pipeline_api'] + String baseURI = config['base_uri'] + + def draft = jobDraft.find() + + runPipeline("${PIPELINE}/ons-table2qb.core/codelist/import", + draft.id, credentials, [[name: 'codelist-csv', + file: [name: csv, type: 'text/csv']], + [name: 'codelist-name', value: name]]) + } +} diff --git a/vars/uploadComponents.groovy b/vars/uploadComponents.groovy new file mode 100644 index 0000000..3f431bd --- /dev/null +++ b/vars/uploadComponents.groovy @@ -0,0 +1,15 @@ +def call(String csv) { + configFileProvider([configFile(fileId: 'pmd', variable: 'configfile')]) { + def config = readJSON(text: readFile(file: configfile)) + String PMD = config['pmd_api'] + String credentials = config['credentials'] + String PIPELINE = config['pipeline_api'] + String baseURI = config['base_uri'] + + def draft = jobDraft.find() + + runPipeline("${PIPELINE}/ons-table2qb.core/components/import", + draft.id, credentials, [[name: 'components-csv', + file: [name: csv, type: 'text/csv']]]) + } +}