Added method to purge groups
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/ckan-util-library@141607 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
89d9abc1b6
commit
8712b8ac54
|
@ -1,4 +1,8 @@
|
|||
<ReleaseNotes>
|
||||
<Changeset component="org.gcube.data-catalogue.ckan-util-library.2-1-1"
|
||||
date="2017-02-01">
|
||||
<Change>Added method to delete/purge group</Change>
|
||||
</Changeset>
|
||||
<Changeset component="org.gcube.data-catalogue.ckan-util-library.2-1-0"
|
||||
date="2016-12-01">
|
||||
<Change>Product creation methods improved</Change>
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -10,7 +10,7 @@
|
|||
</parent>
|
||||
<groupId>org.gcube.data-catalogue</groupId>
|
||||
<artifactId>ckan-util-library</artifactId>
|
||||
<version>2.1.0-SNAPSHOT</version>
|
||||
<version>2.1.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>CKan utility library</name>
|
||||
|
|
|
@ -502,4 +502,12 @@ public interface DataCatalogue {
|
|||
* @throws ClassNotFoundException
|
||||
*/
|
||||
List<String> getProductsIdsInGroupOrOrg(String orgOrGroupName, boolean isOrganization, int start, int rows) throws ClassNotFoundException, SQLException;
|
||||
|
||||
/**
|
||||
* Delete and purge (if purge is set to true) a group
|
||||
* @param groupName
|
||||
* @param purge
|
||||
* @return
|
||||
*/
|
||||
boolean deleteGroup(String groupName, boolean purge);
|
||||
}
|
||||
|
|
|
@ -2474,4 +2474,42 @@ public class DataCatalogueImpl implements DataCatalogue{
|
|||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteGroup(String groupName, boolean purge) {
|
||||
|
||||
checkNotNull(groupName);
|
||||
|
||||
logger.info("Request of deleting group " + groupName + ". Purge is " + Boolean.toString(purge));
|
||||
|
||||
try(CloseableHttpClient httpClient = HttpClientBuilder.create().build();){
|
||||
|
||||
String deletePath = getCatalogueUrl() + "/api/3/action/group_delete";
|
||||
String purgePath = getCatalogueUrl() + "/api/3/action/group_purge";
|
||||
|
||||
String requestToPerform = purge ? purgePath : deletePath;
|
||||
|
||||
HttpPost httpPostRequest = new HttpPost(requestToPerform);
|
||||
httpPostRequest.setHeader("Authorization", CKAN_TOKEN_SYS);
|
||||
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("id", groupName);
|
||||
|
||||
StringEntity params = new StringEntity(obj.toJSONString(), ContentType.APPLICATION_JSON);
|
||||
httpPostRequest.setEntity(params);
|
||||
|
||||
HttpResponse response = httpClient.execute(httpPostRequest);
|
||||
|
||||
if (response.getStatusLine().getStatusCode() < 200 || response.getStatusLine().getStatusCode() >= 300) {
|
||||
throw new RuntimeException("failed to delete/purge the group. response status line from "
|
||||
+ requestToPerform + " was: " + response.getStatusLine());
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}catch(Exception e){
|
||||
logger.error("Error while trying to delete/purge the group " + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue