[CONF] Apache Syncope > Delete several users at once

2015-11-10 Thread Francesco Chicchiricco (Confluence)
Title: Message Title



 
 
 
 
 
 
 

Francesco Chicchiricco created a page 
 
 
  
 
 
 
 
 
 
 
  
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Delete several users at once 
 
 
  
 
 
 
 
 
 

 
 
 Syncope Client Library  
 Raw HTTP requests  
 
  
 
Version warning 
 
 
Content of this page applies to Apache Syncope >= 1.2.0 
 
 Syncope Client Library In order to leverage the Syncope Client Library (from Java), you need to setup a Maven-based project with at least the following dependency (replace 1.2.6 with your actual Syncope version): 
 
 

  org.apache.syncope
  syncope-client
  1.2.6
 
 
 The following code snippet will first query for all users and then request bulk action to delete all users. Naturally, depending on the actual total number of users, some adjustments might be needed. 
 
 
SyncopeClient syncopeClient = new SyncopeClientFactoryBean().
setAddress("http://localhost:9080/syncope/rest/").
create("admin", "password");
UserService service = syncopeClient.getService(UserService.class);

BulkAction bulkAction = new BulkAction();
bulkAction.setOperation(BulkAction.Type.DELETE);

final int pageSize = 100;
final int count = service.list(1, 1).getTotalCount();
for (int page = 1; page <= (count / pageSize) + 1; page++) {
for (UserTO user : service.list(page, pageSize, null, false).getResult()) {
bulkAction.getTargets().add(String.valueOf(user.getId()));
}
}

BulkActionResult bulkResult = service.bulk(bulkAction);
bulkResult.getResultMap(); 
 
 Please note the false parameter in the call at line 12: this saves time as will not require Syncope to fetch virtual attributes' values from external resources. Rather then deleting all users, a restricting search condition can be used by replacing line 10 with 
 
 
final String fiql = SyncopeClient.getUserSearchConditionBuilder().is("id").lessThan(150).query();
final int count = service.search(fiql, 1, 1).getTotalCount(); 
 
 and line 12 with 
 
 
for (UserTO user : service.search(fiql, page, pageSize, null, false).getResult()) { 
 
 Raw HTTP requests When only relying on raw HTTP requests, the following steps are required: 
 
invoke GET /rest/users?page=X=Y where X and Y are respectively page number and page size; for each invocation take note of id property for each reported user 
 invoke POST /rest/users/bulk with headers Accept: application/json, Content-Type: application/json and payload like as follows: 
 
 
{
  "operation":"DELETE",
  "targets":[
"100", "101", "107"
  ]
} 
 
  
 More information on the REST API reference.  
 
 
  
 
 
 
 
 
 
 
 
 
 

View page
• 
 
 
 
 
 
 

Add comment
• 
 
 
 
 
 
 

Like 
 
 
  
 
 
  
 
 
  
 
 
  
 
 
 
 
 
 
 
 
 
 
Stop watching space
• 
 
 
 
 
 
 
Manage notifications 
 
 
 
 
 
 
 
 
 
 
  
 
 
This message was sent by Atlassian Confluence 5.8.4  
 
 
  
 
 
 
 
 
 
 
 
 




[CONF] Apache Syncope > Delete several users at once

2015-11-10 Thread Francesco Chicchiricco (Confluence)
Title: Message Title



 
 
 
 
 
 
 

Francesco Chicchiricco edited a page 
 
 
  
 
 
 
 
 
 
 
  
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Delete several users at once 
 
 
  
 
 
 
 
 
 
 ... 
 
invoke GET /rest/users?page=X=Y where X and Y are respectively page number and page size; for each invocation take note of id property for each reported user 
 invoke POST /rest/users/bulk with headers Accept: application/json, Content-Type: application/json and payload like as follows: 
 
 
 
 Code Block 
 
 
 
 
 
 
 
 
language 
js 
 
 
  
 
 
 
 
 {
  "operation":"DELETE",
  "targets":[
"100", "101", "107"
  ]
}  
 
 
  
  More information on Rather then deleting all users, a restricting search condition can be used by replacing the first invocation above with GET /rest/users/search?fiql=id%3Dlt%3D150=X=Y   More information by consulting the REST API reference.  
 
 
  
 
 
 
 
 
 
 
 
 
 

View page
• 
 
 
 
 
 
 

Add comment
• 
 
 
 
 
 
 

Like 
 
 
  
 
 
  
 
 
  
 
 
  
 
 
 
 
 
 
 
 
 
 
Stop watching space
• 
 
 
 
 
 
 
Manage notifications 
 
 
 
 
 
 
 
 
 
 
  
 
 
This message was sent by Atlassian Confluence 5.8.4