mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-08 16:36:13 +00:00
Get users or groups available to share with via SHAREE API
This commit is contained in:
parent
0793d3fca7
commit
3b3b992a79
@ -1,4 +1,7 @@
|
|||||||
/* ownCloud Android Library is available under MIT license
|
/* ownCloud Android Library is available under MIT license
|
||||||
|
*
|
||||||
|
* @author masensio
|
||||||
|
* @author David A. Velasco
|
||||||
* Copyright (C) 2015 ownCloud Inc.
|
* Copyright (C) 2015 ownCloud Inc.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
@ -24,12 +27,14 @@
|
|||||||
|
|
||||||
package com.owncloud.android.lib.resources.users;
|
package com.owncloud.android.lib.resources.users;
|
||||||
|
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.util.Pair;
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
|
|
||||||
import org.apache.commons.httpclient.NameValuePair;
|
|
||||||
import org.apache.commons.httpclient.methods.GetMethod;
|
import org.apache.commons.httpclient.methods.GetMethod;
|
||||||
import org.apache.http.HttpStatus;
|
import org.apache.http.HttpStatus;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
@ -57,69 +62,69 @@ public class GetRemoteUsersOrGroupsOperation extends RemoteOperation{
|
|||||||
private static final String TAG = GetRemoteUsersOrGroupsOperation.class.getSimpleName();
|
private static final String TAG = GetRemoteUsersOrGroupsOperation.class.getSimpleName();
|
||||||
|
|
||||||
// OCS Routes
|
// OCS Routes
|
||||||
private static final String OCS_ROUTE_USERS ="/ocs/v1.php/cloud/users?format=json";
|
private static final String OCS_ROUTE = "ocs/v2.php/apps/files_sharing/api/v1/sharees"; // from OC 8.2
|
||||||
private static final String OCS_ROUTE_GROUPS ="/ocs/v1.php/cloud/groups?format=json";
|
|
||||||
|
|
||||||
// Arguments
|
// Arguments - names
|
||||||
|
private static final String PARAM_FORMAT = "format";
|
||||||
|
private static final String PARAM_ITEM_TYPE = "itemType";
|
||||||
private static final String PARAM_SEARCH = "search";
|
private static final String PARAM_SEARCH = "search";
|
||||||
private static final String PARAM_LIMIT = "limit";
|
private static final String PARAM_PAGE = "page"; // default = 1
|
||||||
private static final String PARAM_OFFSET = "offset";
|
private static final String PARAM_PER_PAGE = "perPage"; // default = 200
|
||||||
|
|
||||||
|
// Arguments - constant values
|
||||||
|
private static final String VALUE_FORMAT = "json";
|
||||||
|
private static final String VALUE_ITEM_TYPE = "search"; // to get the server search for users / groups
|
||||||
|
|
||||||
|
|
||||||
// JSON Node names
|
// JSON Node names
|
||||||
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_EXACT = "exact";
|
||||||
private static final String NODE_USERS = "users";
|
private static final String NODE_USERS = "users";
|
||||||
private static final String NODE_GROUPS = "groups";
|
private static final String NODE_GROUPS = "groups";
|
||||||
|
private static final String NODE_VALUE = "value";
|
||||||
|
private static final String PROPERTY_LABEL = "label";
|
||||||
|
private static final String PROPERTY_SHARE_TYPE = "shareType";
|
||||||
|
|
||||||
private ArrayList<String> mNames; // List of users or groups
|
// Result types
|
||||||
|
public static final Byte USER_TYPE = 0;
|
||||||
|
public static final Byte GROUP_TYPE = 1;
|
||||||
|
|
||||||
private String mSearchString;
|
private String mSearchString;
|
||||||
private int mLimit;
|
private int mPage;
|
||||||
private int mOffset;
|
private int mPerPage;
|
||||||
private boolean mGetGroup = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param searchString string for searching users, optional
|
* @param searchString string for searching users, optional
|
||||||
* @param limit limit, optional
|
* @param page page index in the list of results; beginning in 1
|
||||||
* @param offset offset, optional
|
* @param perPage maximum number of results in a single page
|
||||||
* @param getGroups true: for searching groups, false: for searching users
|
|
||||||
*/
|
*/
|
||||||
public GetRemoteUsersOrGroupsOperation(String searchString, int limit, int offset,
|
public GetRemoteUsersOrGroupsOperation(String searchString, int page, int perPage) {
|
||||||
boolean getGroups) {
|
|
||||||
mSearchString = searchString;
|
mSearchString = searchString;
|
||||||
mLimit = limit;
|
mPage = page;
|
||||||
mOffset = offset;
|
mPerPage = perPage;
|
||||||
mGetGroup = getGroups;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected RemoteOperationResult run(OwnCloudClient client) {
|
protected RemoteOperationResult run(OwnCloudClient client) {
|
||||||
RemoteOperationResult result = null;
|
RemoteOperationResult result = null;
|
||||||
int status = -1;
|
int status;
|
||||||
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{
|
||||||
|
Uri requestUri = client.getBaseUri();
|
||||||
|
Uri.Builder uriBuilder = requestUri.buildUpon();
|
||||||
|
uriBuilder.appendEncodedPath(OCS_ROUTE);
|
||||||
|
uriBuilder.appendQueryParameter(PARAM_FORMAT, VALUE_FORMAT);
|
||||||
|
uriBuilder.appendQueryParameter(PARAM_ITEM_TYPE, VALUE_ITEM_TYPE);
|
||||||
|
uriBuilder.appendQueryParameter(PARAM_SEARCH, Uri.encode(mSearchString));
|
||||||
|
uriBuilder.appendQueryParameter(PARAM_PAGE, String.valueOf(mPage));
|
||||||
|
uriBuilder.appendQueryParameter(PARAM_PER_PAGE, String.valueOf(mPerPage));
|
||||||
|
|
||||||
// Get Method
|
// Get Method
|
||||||
get = new GetMethod(client.getBaseUri() + ocs_route);
|
get = new GetMethod(uriBuilder.build().toString());
|
||||||
|
|
||||||
// Add Parameters to Get Method
|
|
||||||
get.setQueryString(new NameValuePair[]{
|
|
||||||
new NameValuePair(PARAM_SEARCH, mSearchString),
|
|
||||||
new NameValuePair(PARAM_LIMIT, String.valueOf(mLimit)),
|
|
||||||
new NameValuePair(PARAM_OFFSET, String.valueOf(mOffset))
|
|
||||||
});
|
|
||||||
|
|
||||||
//¿?
|
|
||||||
get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
|
|
||||||
|
|
||||||
status = client.executeMethod(get);
|
status = client.executeMethod(get);
|
||||||
|
|
||||||
@ -131,15 +136,30 @@ public class GetRemoteUsersOrGroupsOperation 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 respUsersOrGroups = respData.getJSONArray(nodeUsersOrGroups);
|
JSONObject respExact = respData.getJSONObject(NODE_EXACT);
|
||||||
mNames = new ArrayList<String>();
|
JSONArray respExactUsers = respExact.getJSONArray(NODE_USERS);
|
||||||
|
JSONArray respExactGroups = respExact.getJSONArray(NODE_GROUPS);
|
||||||
|
JSONArray respPartialUsers = respData.getJSONArray(NODE_USERS);
|
||||||
|
JSONArray respPartialGroups = respData.getJSONArray(NODE_GROUPS);
|
||||||
|
JSONArray[] jsonResults = {
|
||||||
|
respExactUsers,
|
||||||
|
respExactGroups,
|
||||||
|
respPartialUsers,
|
||||||
|
respPartialGroups
|
||||||
|
};
|
||||||
|
|
||||||
ArrayList<Object> data = new ArrayList<Object>(); // For result data
|
ArrayList<Object> data = new ArrayList<Object>(); // For result data
|
||||||
for(int i=0; i<= respUsersOrGroups.length(); i++){
|
Pair<String, Byte> match;
|
||||||
JSONObject jsonUser = respUsersOrGroups.getJSONObject(i);
|
for (int i=0; i<4; i++) {
|
||||||
String name = jsonUser.toString();
|
for(int j=0; j< jsonResults[i].length(); j++){
|
||||||
mNames.add(name);
|
JSONObject jsonResult = jsonResults[i].getJSONObject(j);
|
||||||
data.add(name);
|
match = new Pair<String, Byte>(
|
||||||
Log_OC.d(TAG, "*** "+ nodeUsersOrGroups + " : " + name);
|
jsonResult.getString(PROPERTY_LABEL),
|
||||||
|
(byte)jsonResult.getJSONObject(NODE_VALUE).getInt(PROPERTY_SHARE_TYPE)
|
||||||
|
);
|
||||||
|
data.add(match);
|
||||||
|
Log_OC.d(TAG, "*** Added item: " + match.first);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Result
|
// Result
|
||||||
|
Loading…
x
Reference in New Issue
Block a user