mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 16:06:08 +00:00
Add option to retrieve share details in CreateRemoteShareOperation; by default the server only returns the share id
This commit is contained in:
parent
3b3b992a79
commit
68e0633b74
@ -62,6 +62,7 @@ public class CreateRemoteShareOperation extends RemoteOperation {
|
||||
private boolean mPublicUpload;
|
||||
private String mPassword;
|
||||
private int mPermissions;
|
||||
private boolean mGetShareDetails;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@ -81,8 +82,14 @@ public class CreateRemoteShareOperation extends RemoteOperation {
|
||||
* To obtain combinations, add the desired values together.
|
||||
* For instance, for Re-Share, delete, read, update, add 16+8+2+1 = 27.
|
||||
*/
|
||||
public CreateRemoteShareOperation(String remoteFilePath, ShareType shareType, String shareWith, boolean publicUpload,
|
||||
String password, int permissions) {
|
||||
public CreateRemoteShareOperation(
|
||||
String remoteFilePath,
|
||||
ShareType shareType,
|
||||
String shareWith,
|
||||
boolean publicUpload,
|
||||
String password,
|
||||
int permissions
|
||||
) {
|
||||
|
||||
mRemoteFilePath = remoteFilePath;
|
||||
mShareType = shareType;
|
||||
@ -90,6 +97,15 @@ public class CreateRemoteShareOperation extends RemoteOperation {
|
||||
mPublicUpload = publicUpload;
|
||||
mPassword = password;
|
||||
mPermissions = permissions;
|
||||
mGetShareDetails = false; // defaults to false for backwards compatibility
|
||||
}
|
||||
|
||||
public boolean isGettingShareDetails () {
|
||||
return mGetShareDetails;
|
||||
}
|
||||
|
||||
public void setGetShareDetails(boolean set) {
|
||||
mGetShareDetails = set;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -141,11 +157,25 @@ public class CreateRemoteShareOperation extends RemoteOperation {
|
||||
sharesObjects.add(share);
|
||||
}
|
||||
result.setData(sharesObjects);
|
||||
|
||||
if (mGetShareDetails) {
|
||||
// retrieve more info
|
||||
OCShare emptyShare = (OCShare) sharesObjects.get(0);
|
||||
|
||||
GetRemoteShareOperation getInfo = new GetRemoteShareOperation(emptyShare.getIdRemoteShared());
|
||||
result = getInfo.execute(client);
|
||||
}
|
||||
|
||||
} else {
|
||||
result = new RemoteOperationResult(ResultCode.UNKNOWN_ERROR);
|
||||
Log_OC.e(TAG, "Successful response with no share in it");
|
||||
}
|
||||
|
||||
} else if (xmlParser.isFileNotFound()){
|
||||
result = new RemoteOperationResult(ResultCode.SHARE_NOT_FOUND);
|
||||
|
||||
} else if (xmlParser.isFailure()) {
|
||||
// TODO need deeper processing
|
||||
result = new RemoteOperationResult(ResultCode.SHARE_FORBIDDEN);
|
||||
|
||||
} else {
|
||||
|
@ -0,0 +1,110 @@
|
||||
/* ownCloud Android Library is available under MIT license
|
||||
* @author David A. Velasco
|
||||
* Copyright (C) 2015 ownCloud Inc.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.owncloud.android.lib.resources.shares;
|
||||
|
||||
import android.net.Uri;
|
||||
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
|
||||
import org.apache.commons.httpclient.methods.GetMethod;
|
||||
import org.apache.http.HttpStatus;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* Get the data about a Share resource, known its remote ID.
|
||||
*/
|
||||
|
||||
public class GetRemoteShareOperation extends RemoteOperation {
|
||||
|
||||
private static final String TAG = GetRemoteShareOperation.class.getSimpleName();
|
||||
|
||||
private long mRemoteId;
|
||||
|
||||
|
||||
public GetRemoteShareOperation(long remoteId) {
|
||||
mRemoteId = remoteId;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected RemoteOperationResult run(OwnCloudClient client) {
|
||||
RemoteOperationResult result = null;
|
||||
int status = -1;
|
||||
|
||||
// Get Method
|
||||
GetMethod get = null;
|
||||
|
||||
// Get the response
|
||||
try{
|
||||
get = new GetMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH + "/" + Long.toString(mRemoteId));
|
||||
//get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
|
||||
status = client.executeMethod(get);
|
||||
if(isSuccess(status)) {
|
||||
String response = get.getResponseBodyAsString();
|
||||
|
||||
// Parse xml response --> obtain the response in ShareFiles ArrayList
|
||||
// convert String into InputStream
|
||||
InputStream is = new ByteArrayInputStream(response.getBytes());
|
||||
ShareXMLParser xmlParser = new ShareXMLParser();
|
||||
List<OCShare> shares = xmlParser.parseXMLResponse(is);
|
||||
if (shares != null && shares.size() > 0) {
|
||||
Log_OC.d(TAG, "Got " + shares.size() + " shares");
|
||||
result = new RemoteOperationResult(ResultCode.OK);
|
||||
ArrayList<Object> sharesObjects = new ArrayList<Object>();
|
||||
sharesObjects.add(shares.get(0));
|
||||
result.setData(sharesObjects);
|
||||
}
|
||||
} else {
|
||||
result = new RemoteOperationResult(false, status, get.getResponseHeaders());
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
result = new RemoteOperationResult(e);
|
||||
Log_OC.e(TAG, "Exception while getting remote shares ", e);
|
||||
|
||||
} finally {
|
||||
if (get != null) {
|
||||
get.releaseConnection();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private boolean isSuccess(int status) {
|
||||
return (status == HttpStatus.SC_OK);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -39,7 +39,7 @@ import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
|
||||
|
||||
/**
|
||||
* Get the data from the server to know shares
|
||||
* Get the data from the server about ALL the known shares owned by the requester.
|
||||
*
|
||||
* @author masensio
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user