mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-10-31 02:17:41 +00:00 
			
		
		
		
	Add Get Groups Operation to the library
This commit is contained in:
		
							parent
							
								
									fa17c6947e
								
							
						
					
					
						commit
						cea7054a3d
					
				| @ -40,8 +40,10 @@ import java.util.ArrayList; | |||||||
| /** | /** | ||||||
|  * Created by masensio on 08/10/2015. |  * Created by masensio on 08/10/2015. | ||||||
|  * |  * | ||||||
|  * Retrieves a list of users from the ownCloud server. Authentication is done by sending a Basic HTTP Authorization header. |  * Retrieves a list of users or groups from the ownCloud server. | ||||||
|  * Syntax: ocs/v1.php/cloud/users |  * Authentication is done by sending a Basic HTTP Authorization header. | ||||||
|  |  * Syntax: ocs/v1.php/cloud/users (Users) | ||||||
|  |  *         ocs/v1.php/cloud/groups (Groups) | ||||||
|  *    HTTP method: GET |  *    HTTP method: GET | ||||||
|  *    url arguments: search - string, optional search string |  *    url arguments: search - string, optional search string | ||||||
|  *    url arguments: limit - int, optional limit value |  *    url arguments: limit - int, optional limit value | ||||||
| @ -50,12 +52,13 @@ import java.util.ArrayList; | |||||||
|  * Status codes: |  * Status codes: | ||||||
|  *    100 - successful |  *    100 - successful | ||||||
|  */ |  */ | ||||||
| public class GetRemoteUsersOperation extends RemoteOperation{ | public class GetRemoteUsersOrGroupsOperation extends RemoteOperation{ | ||||||
| 
 | 
 | ||||||
|     private static final String TAG = GetRemoteUserNameOperation.class.getSimpleName(); |     private static final String TAG = GetRemoteUsersOrGroupsOperation.class.getSimpleName(); | ||||||
| 
 | 
 | ||||||
|     // OCS Route |     // OCS Routes | ||||||
|     private static final String OCS_ROUTE ="/ocs/v1.php/cloud/users?format=json"; |     private static final String OCS_ROUTE_USERS ="/ocs/v1.php/cloud/users?format=json"; | ||||||
|  |     private static final String OCS_ROUTE_GROUPS ="/ocs/v1.php/cloud/groups?format=json"; | ||||||
| 
 | 
 | ||||||
|     // Arguments |     // Arguments | ||||||
|     private static final String PARAM_SEARCH = "search"; |     private static final String PARAM_SEARCH = "search"; | ||||||
| @ -66,12 +69,14 @@ public class GetRemoteUsersOperation extends RemoteOperation{ | |||||||
|     private static final String NODE_OCS = "ocs"; |     private static final String NODE_OCS = "ocs"; | ||||||
|     private static final String NODE_DATA = "data"; |     private static final String NODE_DATA = "data"; | ||||||
|     private static final String NODE_USERS = "users"; |     private static final String NODE_USERS = "users"; | ||||||
|  |     private static final String NODE_GROUPS = "groups"; | ||||||
| 
 | 
 | ||||||
|     private ArrayList<String> mUsers;  // List of users |     private ArrayList<String> mNames;  // List of users or groups | ||||||
| 
 | 
 | ||||||
|     private String mSearchString; |     private String mSearchString; | ||||||
|     private int mLimit; |     private int mLimit; | ||||||
|     private int mOffset; |     private int mOffset; | ||||||
|  |     private boolean mGetGroup = false; | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Constructor |      * Constructor | ||||||
| @ -79,11 +84,14 @@ public class GetRemoteUsersOperation extends RemoteOperation{ | |||||||
|      * @param searchString  	string for searching users, optional |      * @param searchString  	string for searching users, optional | ||||||
|      * @param limit 			limit, optional |      * @param limit 			limit, optional | ||||||
|      * @param offset			offset, optional |      * @param offset			offset, optional | ||||||
|  |      * @param getGroups         true: for searching groups, false: for searching users | ||||||
|      */ |      */ | ||||||
|     public GetRemoteUsersOperation(String searchString, int limit, int offset) { |     public GetRemoteUsersOrGroupsOperation(String searchString, int limit, int offset, | ||||||
|  |                                            boolean getGroups) { | ||||||
|         mSearchString = searchString; |         mSearchString = searchString; | ||||||
|         mLimit = limit; |         mLimit = limit; | ||||||
|         mOffset = offset; |         mOffset = offset; | ||||||
|  |         mGetGroup = getGroups; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
| @ -92,9 +100,16 @@ public class GetRemoteUsersOperation extends RemoteOperation{ | |||||||
|         int status = -1; |         int status = -1; | ||||||
|         GetMethod get = null; |         GetMethod get = null; | ||||||
| 
 | 
 | ||||||
|  |         String ocs_route = OCS_ROUTE_USERS; | ||||||
|  |         String nodeUsersOrGroups = NODE_USERS; | ||||||
|  |         if(mGetGroup){ | ||||||
|  |             ocs_route = OCS_ROUTE_GROUPS; | ||||||
|  |             nodeUsersOrGroups = NODE_GROUPS; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         try{ |         try{ | ||||||
|             // Get Method |             // Get Method | ||||||
|             get = new GetMethod(client.getBaseUri() + OCS_ROUTE); |             get = new GetMethod(client.getBaseUri() + ocs_route); | ||||||
| 
 | 
 | ||||||
|             // Add Parameters to Get Method |             // Add Parameters to Get Method | ||||||
|             get.setQueryString(new NameValuePair[]{ |             get.setQueryString(new NameValuePair[]{ | ||||||
| @ -116,27 +131,27 @@ public class GetRemoteUsersOperation extends RemoteOperation{ | |||||||
|                 JSONObject respJSON = new JSONObject(response); |                 JSONObject respJSON = new JSONObject(response); | ||||||
|                 JSONObject respOCS = respJSON.getJSONObject(NODE_OCS); |                 JSONObject respOCS = respJSON.getJSONObject(NODE_OCS); | ||||||
|                 JSONObject respData = respOCS.getJSONObject(NODE_DATA); |                 JSONObject respData = respOCS.getJSONObject(NODE_DATA); | ||||||
|                 JSONArray  respUsers = respData.getJSONArray(NODE_USERS); |                 JSONArray  respUsersOrGroups = respData.getJSONArray(nodeUsersOrGroups); | ||||||
|                 mUsers = new ArrayList<String>(); |                 mNames = new ArrayList<String>(); | ||||||
|                 ArrayList<Object> data = new ArrayList<Object>(); // For result data |                 ArrayList<Object> data = new ArrayList<Object>(); // For result data | ||||||
|                 for(int i=0; i<= respUsers.length(); i++){ |                 for(int i=0; i<= respUsersOrGroups.length(); i++){ | ||||||
|                     JSONObject jsonUser = respUsers.getJSONObject(i); |                     JSONObject jsonUser = respUsersOrGroups.getJSONObject(i); | ||||||
|                     String user = jsonUser.toString(); |                     String name = jsonUser.toString(); | ||||||
|                     mUsers.add(user); |                     mNames.add(name); | ||||||
|                     data.add(user); |                     data.add(name); | ||||||
|                     Log_OC.d(TAG, "*** USER : " + user); |                     Log_OC.d(TAG, "*** "+ nodeUsersOrGroups + " : " + name); | ||||||
|                 } |                 } | ||||||
| 
 | 
 | ||||||
|                 // Result |                 // Result | ||||||
|                 result = new RemoteOperationResult(true, status, get.getResponseHeaders()); |                 result = new RemoteOperationResult(true, status, get.getResponseHeaders()); | ||||||
|                 result.setData(data); |                 result.setData(data); | ||||||
| 
 | 
 | ||||||
|                 Log_OC.d(TAG, "*** Get Users completed " ); |                 Log_OC.d(TAG, "*** Get Users or groups completed " ); | ||||||
| 
 | 
 | ||||||
|             } else { |             } else { | ||||||
|                 result = new RemoteOperationResult(false, status, get.getResponseHeaders()); |                 result = new RemoteOperationResult(false, status, get.getResponseHeaders()); | ||||||
|                 String response = get.getResponseBodyAsString(); |                 String response = get.getResponseBodyAsString(); | ||||||
|                 Log_OC.e(TAG, "Failed response while getting users from the server "); |                 Log_OC.e(TAG, "Failed response while getting users/groups from the server "); | ||||||
|                 if (response != null) { |                 if (response != null) { | ||||||
|                     Log_OC.e(TAG, "*** status code: " + status + "; response message: " + response); |                     Log_OC.e(TAG, "*** status code: " + status + "; response message: " + response); | ||||||
|                 } else { |                 } else { | ||||||
| @ -146,7 +161,7 @@ public class GetRemoteUsersOperation extends RemoteOperation{ | |||||||
| 
 | 
 | ||||||
|         } catch (Exception e) { |         } catch (Exception e) { | ||||||
|             result = new RemoteOperationResult(e); |             result = new RemoteOperationResult(e); | ||||||
|             Log_OC.e(TAG, "Exception while getting users", e); |             Log_OC.e(TAG, "Exception while getting users/groups", e); | ||||||
| 
 | 
 | ||||||
|         } finally { |         } finally { | ||||||
|             if (get != null) { |             if (get != null) { | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user