From 81f40b85c31e613ce6e26accbdf9645504267c26 Mon Sep 17 00:00:00 2001
From: Jesper Zedlitz <jesper@zedlitz.de>
Date: Fri, 3 Dec 2021 14:45:12 +0100
Subject: [PATCH] bulk_update_private und bulk_update_public

---
 .gitlab-ci.yml                                |  1 +
 pom.xml                                       | 24 +++++++-------
 .../java/de/landsh/opendata/ckan/CkanAPI.java | 31 +++++++++++++++++++
 3 files changed, 44 insertions(+), 12 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 731bca9..90d1560 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -16,3 +16,4 @@ build:
   artifacts:
     paths:
       - target/*.jar
+
diff --git a/pom.xml b/pom.xml
index a68a964..9237daf 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
 
     <groupId>de.landsh.opendata</groupId>
     <artifactId>dcat-uploader</artifactId>
-    <version>1.0.4</version>
+    <version>1.1.0</version>
 
     <build>
         <plugins>
@@ -33,61 +33,61 @@
         <dependency>
             <groupId>org.apache.httpcomponents</groupId>
             <artifactId>httpclient</artifactId>
-            <version>4.5.12</version>
+            <version>4.5.13</version>
         </dependency>
         <dependency>
             <groupId>org.apache.httpcomponents</groupId>
             <artifactId>httpmime</artifactId>
-            <version>4.5.7</version>
+            <version>4.5.13</version>
         </dependency>
 
         <dependency>
             <groupId>org.dom4j</groupId>
             <artifactId>dom4j</artifactId>
-            <version>2.1.1</version>
+            <version>2.1.3</version>
         </dependency>
         <dependency>
             <groupId>jaxen</groupId>
             <artifactId>jaxen</artifactId>
-            <version>1.1.6</version>
+            <version>1.2.0</version>
         </dependency>
         <dependency>
             <groupId>ch.qos.logback</groupId>
             <artifactId>logback-core</artifactId>
-            <version>1.2.3</version>
+            <version>1.2.7</version>
         </dependency>
         <dependency>
             <groupId>ch.qos.logback</groupId>
             <artifactId>logback-classic</artifactId>
-            <version>1.2.3</version>
+            <version>1.2.7</version>
         </dependency>
         <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-api</artifactId>
-            <version>1.7.28</version>
+            <version>1.7.32</version>
         </dependency>
         <dependency>
             <groupId>org.apache.commons</groupId>
             <artifactId>commons-lang3</artifactId>
-            <version>3.6</version>
+            <version>3.12.0</version>
         </dependency>
 
         <dependency>
             <groupId>org.json</groupId>
             <artifactId>json</artifactId>
-            <version>20190722</version>
+            <version>20210307</version>
         </dependency>
         <dependency>
             <groupId>org.projectlombok</groupId>
             <artifactId>lombok</artifactId>
-            <version>1.18.10</version>
+            <version>1.18.22</version>
             <scope>provided</scope>
         </dependency>
 
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
-            <version>4.13</version>
+            <version>4.13.2</version>
             <scope>test</scope>
         </dependency>
         <dependency>
diff --git a/src/main/java/de/landsh/opendata/ckan/CkanAPI.java b/src/main/java/de/landsh/opendata/ckan/CkanAPI.java
index c7f6628..cc3ad15 100644
--- a/src/main/java/de/landsh/opendata/ckan/CkanAPI.java
+++ b/src/main/java/de/landsh/opendata/ckan/CkanAPI.java
@@ -433,4 +433,35 @@ public class CkanAPI {
         return responseJSON.getBoolean("success");
     }
 
+    public boolean makePackagePrivate(String packageId) throws IOException {
+        final String organization = getOrganization(packageId);
+        final JSONObject json = new JSONObject();
+        json.put("datasets", packageId);
+        json.put("org_id", organization);
+
+        final HttpPost httpPost = new HttpPost(baseURL + "/api/action/bulk_update_private");
+        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");
+    }
+
+    public boolean makePackagePublic(String packageId) throws IOException {
+        final String organization = getOrganization(packageId);
+        final JSONObject json = new JSONObject();
+        json.put("datasets", packageId);
+        json.put("org_id", organization);
+
+        final HttpPost httpPost = new HttpPost(baseURL + "/api/action/bulk_update_public");
+        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