From eba215d012eb08fe42de1eafe1bd49a64950753b Mon Sep 17 00:00:00 2001 From: Jesper Zedlitz <jesper@zedlitz.de> Date: Wed, 14 Apr 2021 09:54:09 +0200 Subject: [PATCH] Version 1.0.3 --- pom.xml | 2 +- .../java/de/landsh/opendata/ckan/CkanAPI.java | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 5b5f0bb..ecf386d 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ <groupId>de.landsh.opendata</groupId> <artifactId>dcat-uploader</artifactId> - <version>1.0.2</version> + <version>1.0.3</version> <build> <plugins> diff --git a/src/main/java/de/landsh/opendata/ckan/CkanAPI.java b/src/main/java/de/landsh/opendata/ckan/CkanAPI.java index 657be12..c7f6628 100644 --- a/src/main/java/de/landsh/opendata/ckan/CkanAPI.java +++ b/src/main/java/de/landsh/opendata/ckan/CkanAPI.java @@ -401,8 +401,8 @@ public class CkanAPI { } boolean doesDatasetExist(String packageId) throws IOException { - HttpGet requestPackageShow = new HttpGet(baseURL + "/api/3/action/package_show?id=" + packageId); - JSONObject response = restClient.executeHttpRequest(requestPackageShow); + final HttpGet requestPackageShow = new HttpGet(baseURL + "/api/3/action/package_show?id=" + packageId); + final JSONObject response = restClient.executeHttpRequest(requestPackageShow); return isResponseSuccess(response); } @@ -419,4 +419,18 @@ public class CkanAPI { return updatePackage(packageObject); } + public boolean deleteResource(String resourceId) throws IOException { + final JSONObject json = new JSONObject(); + json.put("id", resourceId); + + final HttpPost httpPost = new HttpPost(baseURL + "/api/action/resource_delete"); + httpPost.addHeader("Authorization", apiKey.toString()); + httpPost.addHeader("Content-Type", "application/json"); + httpPost.setEntity(new StringEntity(json.toString(), StandardCharsets.UTF_8)); + + final JSONObject responseJSON = restClient.executeHttpRequest(httpPost); + + return responseJSON.getBoolean("success"); + } + } -- GitLab