mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-08 16:36:13 +00:00
use compiletime polymorphism over runtime polymorphism
This commit is contained in:
parent
06ec99aead
commit
7bc9a885b0
@ -32,22 +32,20 @@ import com.owncloud.android.lib.common.authentication.OwnCloudBasicCredentials;
|
|||||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||||
import com.owncloud.android.lib.common.authentication.OwnCloudCredentials;
|
import com.owncloud.android.lib.common.authentication.OwnCloudCredentials;
|
||||||
import com.owncloud.android.lib.common.http.methods.nonwebdav.PostMethod;
|
import com.owncloud.android.lib.common.http.methods.nonwebdav.PostMethod;
|
||||||
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
|
||||||
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.operations.RemoteOperationResult.ResultCode;
|
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import okhttp3.HttpUrl;
|
|
||||||
import okhttp3.MultipartBody;
|
import okhttp3.MultipartBody;
|
||||||
import okhttp3.RequestBody;
|
import okhttp3.RequestBody;
|
||||||
|
|
||||||
|
|
||||||
public class OAuth2GetAccessTokenOperation extends RemoteOperation {
|
public class OAuth2GetAccessTokenOperation extends RemoteOperation<Map<String, String>> {
|
||||||
|
|
||||||
private String mGrantType;
|
private String mGrantType;
|
||||||
private String mCode;
|
private String mCode;
|
||||||
@ -84,7 +82,7 @@ public class OAuth2GetAccessTokenOperation extends RemoteOperation {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected RemoteOperationResult run(OwnCloudClient client) {
|
protected RemoteOperationResult run(OwnCloudClient client) {
|
||||||
RemoteOperationResult result = null;
|
RemoteOperationResult<Map<String, String>> result = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
@ -122,22 +120,20 @@ public class OAuth2GetAccessTokenOperation extends RemoteOperation {
|
|||||||
mResponseParser.parseAccessTokenResult(tokenJson);
|
mResponseParser.parseAccessTokenResult(tokenJson);
|
||||||
if (accessTokenResult.get(OAuth2Constants.KEY_ERROR) != null ||
|
if (accessTokenResult.get(OAuth2Constants.KEY_ERROR) != null ||
|
||||||
accessTokenResult.get(OAuth2Constants.KEY_ACCESS_TOKEN) == null) {
|
accessTokenResult.get(OAuth2Constants.KEY_ACCESS_TOKEN) == null) {
|
||||||
result = new RemoteOperationResult(ResultCode.OAUTH2_ERROR);
|
result = new RemoteOperationResult<>(ResultCode.OAUTH2_ERROR);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
result = new RemoteOperationResult(ResultCode.OK);
|
result = new RemoteOperationResult<>(ResultCode.OK);
|
||||||
ArrayList<Object> data = new ArrayList<>();
|
result.setData(accessTokenResult);
|
||||||
data.add(accessTokenResult);
|
|
||||||
result.setData(data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
result = new RemoteOperationResult(ResultCode.OK);
|
result = new RemoteOperationResult<>(ResultCode.OK);
|
||||||
client.exhaustResponse(postMethod.getResponseAsStream());
|
client.exhaustResponse(postMethod.getResponseAsStream());
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
result = new RemoteOperationResult(e);
|
result = new RemoteOperationResult<>(e);
|
||||||
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -26,24 +26,22 @@ import android.net.Uri;
|
|||||||
import com.owncloud.android.lib.common.authentication.OwnCloudBasicCredentials;
|
import com.owncloud.android.lib.common.authentication.OwnCloudBasicCredentials;
|
||||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||||
import com.owncloud.android.lib.common.authentication.OwnCloudCredentials;
|
import com.owncloud.android.lib.common.authentication.OwnCloudCredentials;
|
||||||
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
|
||||||
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.operations.RemoteOperationResult.ResultCode;
|
|
||||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.http.methods.nonwebdav.PostMethod;
|
import com.owncloud.android.lib.common.http.methods.nonwebdav.PostMethod;
|
||||||
|
|
||||||
import okhttp3.HttpUrl;
|
|
||||||
import okhttp3.MultipartBody;
|
import okhttp3.MultipartBody;
|
||||||
import okhttp3.RequestBody;
|
import okhttp3.RequestBody;
|
||||||
|
|
||||||
public class OAuth2RefreshAccessTokenOperation extends RemoteOperation {
|
public class OAuth2RefreshAccessTokenOperation extends RemoteOperation<Map<String, String>> {
|
||||||
|
|
||||||
private static final String TAG = OAuth2RefreshAccessTokenOperation.class.getSimpleName();
|
private static final String TAG = OAuth2RefreshAccessTokenOperation.class.getSimpleName();
|
||||||
|
|
||||||
@ -76,7 +74,7 @@ public class OAuth2RefreshAccessTokenOperation extends RemoteOperation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected RemoteOperationResult run(OwnCloudClient client) {
|
protected RemoteOperationResult<Map<String, String>> run(OwnCloudClient client) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
@ -115,21 +113,20 @@ public class OAuth2RefreshAccessTokenOperation extends RemoteOperation {
|
|||||||
|
|
||||||
final Map<String, String> accessTokenResult =
|
final Map<String, String> accessTokenResult =
|
||||||
mResponseParser.parseAccessTokenResult(tokenJson);
|
mResponseParser.parseAccessTokenResult(tokenJson);
|
||||||
final ArrayList<Object> resultData = new ArrayList<>(1);
|
|
||||||
resultData.add(accessTokenResult);
|
final RemoteOperationResult<Map<String, String>> result = new RemoteOperationResult<>(ResultCode.OK);
|
||||||
final RemoteOperationResult result = new RemoteOperationResult(ResultCode.OK);
|
result.setData(accessTokenResult);
|
||||||
result.setData(resultData);
|
|
||||||
return (accessTokenResult.get(OAuth2Constants.KEY_ERROR) != null ||
|
return (accessTokenResult.get(OAuth2Constants.KEY_ERROR) != null ||
|
||||||
accessTokenResult.get(OAuth2Constants.KEY_ACCESS_TOKEN) == null)
|
accessTokenResult.get(OAuth2Constants.KEY_ACCESS_TOKEN) == null)
|
||||||
? new RemoteOperationResult(ResultCode.OAUTH2_ERROR)
|
? new RemoteOperationResult<>(ResultCode.OAUTH2_ERROR)
|
||||||
: result;
|
: result;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return new RemoteOperationResult(postMethod);
|
return new RemoteOperationResult<>(postMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return new RemoteOperationResult(e);
|
return new RemoteOperationResult<>(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ import java.util.Arrays;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Aggregate saving the list of URLs followed in a sequence of redirections during the exceution of a
|
* Aggregate saving the list of URLs followed in a sequence of redirections during the exceution of a
|
||||||
* {@link com.owncloud.android.lib.common.operations.RemoteOperation}, and the status codes corresponding to all
|
* {@link RemoteOperation}, and the status codes corresponding to all
|
||||||
* of them.
|
* of them.
|
||||||
*
|
*
|
||||||
* The last status code saved corresponds to the first response not being a redirection, unless the sequence exceeds
|
* The last status code saved corresponds to the first response not being a redirection, unless the sequence exceeds
|
||||||
|
@ -1,27 +1,3 @@
|
|||||||
/* ownCloud Android Library is available under MIT license
|
|
||||||
* Copyright (C) 2017 ownCloud GmbH.
|
|
||||||
*
|
|
||||||
* 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.common.operations;
|
package com.owncloud.android.lib.common.operations;
|
||||||
|
|
||||||
import android.accounts.Account;
|
import android.accounts.Account;
|
||||||
@ -41,16 +17,7 @@ import java.io.IOException;
|
|||||||
|
|
||||||
import okhttp3.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
|
|
||||||
|
public abstract class RemoteOperation<T extends Object> implements Runnable {
|
||||||
/**
|
|
||||||
* Operation which execution involves one or several interactions with an ownCloud server.
|
|
||||||
*
|
|
||||||
* Provides methods to onExecute the operation both synchronously or asynchronously.
|
|
||||||
*
|
|
||||||
* @author David A. Velasco
|
|
||||||
* @author David González Verdugo
|
|
||||||
*/
|
|
||||||
public abstract class RemoteOperation implements Runnable {
|
|
||||||
|
|
||||||
private static final String TAG = RemoteOperation.class.getSimpleName();
|
private static final String TAG = RemoteOperation.class.getSimpleName();
|
||||||
|
|
||||||
@ -67,106 +34,32 @@ public abstract class RemoteOperation implements Runnable {
|
|||||||
/**
|
/**
|
||||||
* ownCloud account in the remote ownCloud server to operate
|
* ownCloud account in the remote ownCloud server to operate
|
||||||
*/
|
*/
|
||||||
private Account mAccount = null;
|
protected Account mAccount = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Android Application context
|
* Android Application context
|
||||||
*/
|
*/
|
||||||
private Context mContext = null;
|
protected Context mContext = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Object to interact with the remote server
|
* Object to interact with the remote server
|
||||||
*/
|
*/
|
||||||
private OwnCloudClient mClient = null;
|
protected OwnCloudClient mClient = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Object to interact with the remote server
|
* Object to interact with the remote server
|
||||||
*/
|
*/
|
||||||
private OkHttpClient mHttpClient = null;
|
protected OkHttpClient mHttpClient = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback object to notify about the execution of the remote operation
|
* Callback object to notify about the execution of the remote operation
|
||||||
*/
|
*/
|
||||||
private OnRemoteOperationListener mListener = null;
|
protected OnRemoteOperationListener mListener = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler to the thread where mListener methods will be called
|
* Handler to the thread where mListener methods will be called
|
||||||
*/
|
*/
|
||||||
private Handler mListenerHandler = null;
|
protected Handler mListenerHandler = null;
|
||||||
|
|
||||||
/**
|
|
||||||
* Abstract method to implement the operation in derived classes.
|
|
||||||
*/
|
|
||||||
protected abstract RemoteOperationResult run(OwnCloudClient client);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Synchronously executes the remote operation on the received ownCloud account.
|
|
||||||
*
|
|
||||||
* Do not call this method from the main thread.
|
|
||||||
*
|
|
||||||
* This method should be used whenever an ownCloud account is available, instead of
|
|
||||||
* {@link #execute(OwnCloudClient)}.
|
|
||||||
*
|
|
||||||
* @param account ownCloud account in remote ownCloud server to reach during the
|
|
||||||
* execution of the operation.
|
|
||||||
* @param context Android context for the component calling the method.
|
|
||||||
* @return Result of the operation.
|
|
||||||
*/
|
|
||||||
public RemoteOperationResult execute(Account account, Context context) {
|
|
||||||
if (account == null)
|
|
||||||
throw new IllegalArgumentException("Trying to onExecute a remote operation with a NULL " +
|
|
||||||
"Account");
|
|
||||||
if (context == null)
|
|
||||||
throw new IllegalArgumentException("Trying to onExecute a remote operation with a NULL " +
|
|
||||||
"Context");
|
|
||||||
mAccount = account;
|
|
||||||
mContext = context.getApplicationContext();
|
|
||||||
|
|
||||||
return runOperation();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Synchronously executes the remote operation
|
|
||||||
*
|
|
||||||
* Do not call this method from the main thread.
|
|
||||||
*
|
|
||||||
* @param client Client object to reach an ownCloud server during the execution of
|
|
||||||
* the operation.
|
|
||||||
* @return Result of the operation.
|
|
||||||
*/
|
|
||||||
public RemoteOperationResult execute(OwnCloudClient client) {
|
|
||||||
if (client == null)
|
|
||||||
throw new IllegalArgumentException("Trying to onExecute a remote operation with a NULL " +
|
|
||||||
"OwnCloudClient");
|
|
||||||
mClient = client;
|
|
||||||
if (client.getAccount() != null) {
|
|
||||||
mAccount = client.getAccount().getSavedAccount();
|
|
||||||
}
|
|
||||||
mContext = client.getContext();
|
|
||||||
|
|
||||||
return runOperation();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Synchronously executes the remote operation
|
|
||||||
*
|
|
||||||
* Do not call this method from the main thread.
|
|
||||||
*
|
|
||||||
* @param client Client object to reach an ownCloud server during the execution of
|
|
||||||
* the operation.
|
|
||||||
* @return Result of the operation.
|
|
||||||
*/
|
|
||||||
public RemoteOperationResult execute(OkHttpClient client, Context context) {
|
|
||||||
if (client == null)
|
|
||||||
throw new IllegalArgumentException("Trying to onExecute a remote operation with a NULL " +
|
|
||||||
"OwnCloudClient");
|
|
||||||
mHttpClient = client;
|
|
||||||
mContext = context;
|
|
||||||
|
|
||||||
return runOperation();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -245,6 +138,127 @@ public abstract class RemoteOperation implements Runnable {
|
|||||||
return runnerThread;
|
return runnerThread;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void grantOwnCloudClient() throws
|
||||||
|
AccountUtils.AccountNotFoundException, OperationCanceledException, AuthenticatorException, IOException {
|
||||||
|
if (mClient == null) {
|
||||||
|
if (mAccount != null && mContext != null) {
|
||||||
|
OwnCloudAccount ocAccount = new OwnCloudAccount(mAccount, mContext);
|
||||||
|
mClient = OwnCloudClientManagerFactory.getDefaultSingleton().
|
||||||
|
getClientFor(ocAccount, mContext);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
throw new IllegalStateException("Trying to run a remote operation " +
|
||||||
|
"asynchronously with no client and no chance to create one (no account)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current client instance to access the remote server.
|
||||||
|
*
|
||||||
|
* @return Current client instance to access the remote server.
|
||||||
|
*/
|
||||||
|
public final OwnCloudClient getClient() {
|
||||||
|
return mClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract method to implement the operation in derived classes.
|
||||||
|
*/
|
||||||
|
protected abstract RemoteOperationResult<T> run(OwnCloudClient client);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Synchronously executes the remote operation on the received ownCloud account.
|
||||||
|
*
|
||||||
|
* Do not call this method from the main thread.
|
||||||
|
*
|
||||||
|
* This method should be used whenever an ownCloud account is available, instead of
|
||||||
|
* {@link #execute(OwnCloudClient)}.
|
||||||
|
*
|
||||||
|
* @param account ownCloud account in remote ownCloud server to reach during the
|
||||||
|
* execution of the operation.
|
||||||
|
* @param context Android context for the component calling the method.
|
||||||
|
* @return Result of the operation.
|
||||||
|
*/
|
||||||
|
public RemoteOperationResult<T> execute(Account account, Context context) {
|
||||||
|
if (account == null)
|
||||||
|
throw new IllegalArgumentException("Trying to onExecute a remote operation with a NULL " +
|
||||||
|
"Account");
|
||||||
|
if (context == null)
|
||||||
|
throw new IllegalArgumentException("Trying to onExecute a remote operation with a NULL " +
|
||||||
|
"Context");
|
||||||
|
mAccount = account;
|
||||||
|
mContext = context.getApplicationContext();
|
||||||
|
|
||||||
|
return runOperation();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Synchronously executes the remote operation
|
||||||
|
*
|
||||||
|
* Do not call this method from the main thread.
|
||||||
|
*
|
||||||
|
* @param client Client object to reach an ownCloud server during the execution of
|
||||||
|
* the operation.
|
||||||
|
* @return Result of the operation.
|
||||||
|
*/
|
||||||
|
public RemoteOperationResult<T> execute(OwnCloudClient client) {
|
||||||
|
if (client == null)
|
||||||
|
throw new IllegalArgumentException("Trying to onExecute a remote operation with a NULL " +
|
||||||
|
"OwnCloudClient");
|
||||||
|
mClient = client;
|
||||||
|
if (client.getAccount() != null) {
|
||||||
|
mAccount = client.getAccount().getSavedAccount();
|
||||||
|
}
|
||||||
|
mContext = client.getContext();
|
||||||
|
|
||||||
|
return runOperation();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Synchronously executes the remote operation
|
||||||
|
*
|
||||||
|
* Do not call this method from the main thread.
|
||||||
|
*
|
||||||
|
* @param client Client object to reach an ownCloud server during the execution of
|
||||||
|
* the operation.
|
||||||
|
* @return Result of the operation.
|
||||||
|
*/
|
||||||
|
public RemoteOperationResult<T> execute(OkHttpClient client, Context context) {
|
||||||
|
if (client == null)
|
||||||
|
throw new IllegalArgumentException("Trying to onExecute a remote operation with a NULL " +
|
||||||
|
"OwnCloudClient");
|
||||||
|
mHttpClient = client;
|
||||||
|
mContext = context;
|
||||||
|
|
||||||
|
return runOperation();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run operation for asynchronous or synchronous 'onExecute' method.
|
||||||
|
*
|
||||||
|
* Considers and performs silent refresh of account credentials if possible, and if
|
||||||
|
* {@link RemoteOperation#setSilentRefreshOfAccountCredentials(boolean)} was called with
|
||||||
|
* parameter 'true' before the execution.
|
||||||
|
*
|
||||||
|
* @return Remote operation result
|
||||||
|
*/
|
||||||
|
private RemoteOperationResult<T> runOperation() {
|
||||||
|
|
||||||
|
RemoteOperationResult<T> result;
|
||||||
|
|
||||||
|
try {
|
||||||
|
grantOwnCloudClient();
|
||||||
|
result = run(mClient);
|
||||||
|
|
||||||
|
} catch (AccountsException | IOException e) {
|
||||||
|
Log_OC.e(TAG, "Error while trying to access to " + mAccount.name, e);
|
||||||
|
result = new RemoteOperationResult<>(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asynchronous execution of the operation
|
* Asynchronous execution of the operation
|
||||||
@ -263,65 +277,11 @@ public abstract class RemoteOperation implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (mListenerHandler != null && mListener != null) {
|
if (mListenerHandler != null && mListener != null) {
|
||||||
mListenerHandler.post(new Runnable() {
|
mListenerHandler.post(() ->
|
||||||
@Override
|
mListener.onRemoteOperationFinish(RemoteOperation.this, resultToSend));
|
||||||
public void run() {
|
|
||||||
mListener.onRemoteOperationFinish(RemoteOperation.this, resultToSend);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else if (mListener != null) {
|
} else if (mListener != null) {
|
||||||
mListener.onRemoteOperationFinish(RemoteOperation.this, resultToSend);
|
mListener.onRemoteOperationFinish(RemoteOperation.this, resultToSend);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
}
|
||||||
* Run operation for asynchronous or synchronous 'onExecute' method.
|
|
||||||
*
|
|
||||||
* Considers and performs silent refresh of account credentials if possible, and if
|
|
||||||
* {@link RemoteOperation#setSilentRefreshOfAccountCredentials(boolean)} was called with
|
|
||||||
* parameter 'true' before the execution.
|
|
||||||
*
|
|
||||||
* @return Remote operation result
|
|
||||||
*/
|
|
||||||
private RemoteOperationResult runOperation() {
|
|
||||||
|
|
||||||
RemoteOperationResult result;
|
|
||||||
|
|
||||||
try {
|
|
||||||
grantOwnCloudClient();
|
|
||||||
result = run(mClient);
|
|
||||||
|
|
||||||
} catch (AccountsException | IOException e) {
|
|
||||||
Log_OC.e(TAG, "Error while trying to access to " + mAccount.name, e);
|
|
||||||
result = new RemoteOperationResult(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void grantOwnCloudClient() throws
|
|
||||||
AccountUtils.AccountNotFoundException, OperationCanceledException, AuthenticatorException, IOException {
|
|
||||||
if (mClient == null) {
|
|
||||||
if (mAccount != null && mContext != null) {
|
|
||||||
OwnCloudAccount ocAccount = new OwnCloudAccount(mAccount, mContext);
|
|
||||||
mClient = OwnCloudClientManagerFactory.getDefaultSingleton().
|
|
||||||
getClientFor(ocAccount, mContext);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
throw new IllegalStateException("Trying to run a remote operation " +
|
|
||||||
"asynchronously with no client and no chance to create one (no account)");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the current client instance to access the remote server.
|
|
||||||
*
|
|
||||||
* @return Current client instance to access the remote server.
|
|
||||||
*/
|
|
||||||
public final OwnCloudClient getClient() {
|
|
||||||
return mClient;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
@ -1,33 +1,9 @@
|
|||||||
/* ownCloud Android Library is available under MIT license
|
|
||||||
* Copyright (C) 2018 ownCloud GmbH.
|
|
||||||
*
|
|
||||||
* 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.common.operations;
|
package com.owncloud.android.lib.common.operations;
|
||||||
|
|
||||||
import android.accounts.Account;
|
import android.accounts.Account;
|
||||||
import android.accounts.AccountsException;
|
import android.accounts.AccountsException;
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException;
|
import com.owncloud.android.lib.common.accounts.AccountUtils;
|
||||||
import com.owncloud.android.lib.common.http.HttpConstants;
|
import com.owncloud.android.lib.common.http.HttpConstants;
|
||||||
import com.owncloud.android.lib.common.http.methods.HttpBaseMethod;
|
import com.owncloud.android.lib.common.http.methods.HttpBaseMethod;
|
||||||
import com.owncloud.android.lib.common.network.CertificateCombinedException;
|
import com.owncloud.android.lib.common.network.CertificateCombinedException;
|
||||||
@ -55,21 +31,8 @@ import at.bitfire.dav4android.exception.DavException;
|
|||||||
import at.bitfire.dav4android.exception.HttpException;
|
import at.bitfire.dav4android.exception.HttpException;
|
||||||
import okhttp3.Headers;
|
import okhttp3.Headers;
|
||||||
|
|
||||||
|
public class RemoteOperationResult<T extends Object>
|
||||||
|
implements Serializable {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The result of a remote operation required to an ownCloud server.
|
|
||||||
*
|
|
||||||
* Provides a common classification of remote operation results for all the
|
|
||||||
* application.
|
|
||||||
*
|
|
||||||
* @author David A. Velasco
|
|
||||||
* @author David González Verdugo
|
|
||||||
*/
|
|
||||||
public class RemoteOperationResult implements Serializable {
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generated - should be refreshed every time the class changes!!
|
* Generated - should be refreshed every time the class changes!!
|
||||||
@ -139,8 +102,7 @@ public class RemoteOperationResult implements Serializable {
|
|||||||
private String mRedirectedLocation;
|
private String mRedirectedLocation;
|
||||||
private ArrayList<String> mAuthenticate = new ArrayList<>();
|
private ArrayList<String> mAuthenticate = new ArrayList<>();
|
||||||
private String mLastPermanentLocation = null;
|
private String mLastPermanentLocation = null;
|
||||||
|
private T mData = null;
|
||||||
private ArrayList<Object> mData;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Public constructor from result code.
|
* Public constructor from result code.
|
||||||
@ -154,7 +116,6 @@ public class RemoteOperationResult implements Serializable {
|
|||||||
mSuccess = (code == ResultCode.OK || code == ResultCode.OK_SSL ||
|
mSuccess = (code == ResultCode.OK || code == ResultCode.OK_SSL ||
|
||||||
code == ResultCode.OK_NO_SSL ||
|
code == ResultCode.OK_NO_SSL ||
|
||||||
code == ResultCode.OK_REDIRECT_TO_NON_SECURE_CONNECTION);
|
code == ResultCode.OK_REDIRECT_TO_NON_SECURE_CONNECTION);
|
||||||
mData = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -184,7 +145,7 @@ public class RemoteOperationResult implements Serializable {
|
|||||||
} else if (e instanceof UnknownHostException) {
|
} else if (e instanceof UnknownHostException) {
|
||||||
mCode = ResultCode.HOST_NOT_AVAILABLE;
|
mCode = ResultCode.HOST_NOT_AVAILABLE;
|
||||||
|
|
||||||
} else if (e instanceof AccountNotFoundException) {
|
} else if (e instanceof AccountUtils.AccountNotFoundException) {
|
||||||
mCode = ResultCode.ACCOUNT_NOT_FOUND;
|
mCode = ResultCode.ACCOUNT_NOT_FOUND;
|
||||||
|
|
||||||
} else if (e instanceof AccountsException) {
|
} else if (e instanceof AccountsException) {
|
||||||
@ -332,7 +293,7 @@ public class RemoteOperationResult implements Serializable {
|
|||||||
}
|
}
|
||||||
if (isIdPRedirection()) {
|
if (isIdPRedirection()) {
|
||||||
// overrides default ResultCode.UNKNOWN
|
// overrides default ResultCode.UNKNOWN
|
||||||
mCode = com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.UNAUTHORIZED;
|
mCode = ResultCode.UNAUTHORIZED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -382,13 +343,6 @@ public class RemoteOperationResult implements Serializable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setData(ArrayList<Object> items) {
|
|
||||||
mData = items;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<Object> getData() {
|
|
||||||
return mData;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isSuccess() {
|
public boolean isSuccess() {
|
||||||
return mSuccess;
|
return mSuccess;
|
||||||
@ -476,9 +430,9 @@ public class RemoteOperationResult implements Serializable {
|
|||||||
} else if (mException instanceof IOException) {
|
} else if (mException instanceof IOException) {
|
||||||
return "Unrecovered transport exception";
|
return "Unrecovered transport exception";
|
||||||
|
|
||||||
} else if (mException instanceof AccountNotFoundException) {
|
} else if (mException instanceof AccountUtils.AccountNotFoundException) {
|
||||||
Account failedAccount =
|
Account failedAccount =
|
||||||
((AccountNotFoundException) mException).getFailedAccount();
|
((AccountUtils.AccountNotFoundException) mException).getFailedAccount();
|
||||||
return mException.getMessage() + " (" +
|
return mException.getMessage() + " (" +
|
||||||
(failedAccount != null ? failedAccount.name : "NULL") + ")";
|
(failedAccount != null ? failedAccount.name : "NULL") + ")";
|
||||||
|
|
||||||
@ -575,4 +529,12 @@ public class RemoteOperationResult implements Serializable {
|
|||||||
public void setSuccess(boolean success) {
|
public void setSuccess(boolean success) {
|
||||||
this.mSuccess = success;
|
this.mSuccess = success;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public void setData(T data) {
|
||||||
|
mData = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T getData() {
|
||||||
|
return mData;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -30,16 +30,14 @@ import com.owncloud.android.lib.common.OwnCloudClient;
|
|||||||
import com.owncloud.android.lib.common.http.HttpConstants;
|
import com.owncloud.android.lib.common.http.HttpConstants;
|
||||||
import com.owncloud.android.lib.common.http.methods.webdav.CopyMethod;
|
import com.owncloud.android.lib.common.http.methods.webdav.CopyMethod;
|
||||||
import com.owncloud.android.lib.common.network.WebdavUtils;
|
import com.owncloud.android.lib.common.network.WebdavUtils;
|
||||||
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
|
||||||
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.operations.RemoteOperationResult.ResultCode;
|
|
||||||
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
|
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import okhttp3.HttpUrl;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remote operation moving a remote file or folder in the ownCloud server to a different folder
|
* Remote operation moving a remote file or folder in the ownCloud server to a different folder
|
||||||
* in the same account.
|
* in the same account.
|
||||||
@ -89,16 +87,16 @@ public class CopyRemoteFileOperation extends RemoteOperation {
|
|||||||
|
|
||||||
/// check parameters
|
/// check parameters
|
||||||
if (!FileUtils.isValidPath(mTargetRemotePath, versionWithForbiddenChars)) {
|
if (!FileUtils.isValidPath(mTargetRemotePath, versionWithForbiddenChars)) {
|
||||||
return new RemoteOperationResult(ResultCode.INVALID_CHARACTER_IN_NAME);
|
return new RemoteOperationResult<>(ResultCode.INVALID_CHARACTER_IN_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mTargetRemotePath.equals(mSrcRemotePath)) {
|
if (mTargetRemotePath.equals(mSrcRemotePath)) {
|
||||||
// nothing to do!
|
// nothing to do!
|
||||||
return new RemoteOperationResult(ResultCode.OK);
|
return new RemoteOperationResult<>(ResultCode.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mTargetRemotePath.startsWith(mSrcRemotePath)) {
|
if (mTargetRemotePath.startsWith(mSrcRemotePath)) {
|
||||||
return new RemoteOperationResult(ResultCode.INVALID_COPY_INTO_DESCENDANT);
|
return new RemoteOperationResult<>(ResultCode.INVALID_COPY_INTO_DESCENDANT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// perform remote operation
|
/// perform remote operation
|
||||||
@ -114,10 +112,10 @@ public class CopyRemoteFileOperation extends RemoteOperation {
|
|||||||
final int status = client.executeHttpMethod(copyMethod);
|
final int status = client.executeHttpMethod(copyMethod);
|
||||||
|
|
||||||
if(status == HttpConstants.HTTP_CREATED || status == HttpConstants.HTTP_NO_CONTENT) {
|
if(status == HttpConstants.HTTP_CREATED || status == HttpConstants.HTTP_NO_CONTENT) {
|
||||||
result = new RemoteOperationResult(ResultCode.OK);
|
result = new RemoteOperationResult<>(ResultCode.OK);
|
||||||
} else if (status == HttpConstants.HTTP_PRECONDITION_FAILED && !mOverwrite) {
|
} else if (status == HttpConstants.HTTP_PRECONDITION_FAILED && !mOverwrite) {
|
||||||
|
|
||||||
result = new RemoteOperationResult(ResultCode.INVALID_OVERWRITE);
|
result = new RemoteOperationResult<>(ResultCode.INVALID_OVERWRITE);
|
||||||
client.exhaustResponse(copyMethod.getResponseAsStream());
|
client.exhaustResponse(copyMethod.getResponseAsStream());
|
||||||
|
|
||||||
|
|
||||||
@ -125,7 +123,7 @@ public class CopyRemoteFileOperation extends RemoteOperation {
|
|||||||
/// http://www.webdav.org/specs/rfc4918.html#rfc.section.9.9.4
|
/// http://www.webdav.org/specs/rfc4918.html#rfc.section.9.9.4
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
result = new RemoteOperationResult(copyMethod);
|
result = new RemoteOperationResult<>(copyMethod);
|
||||||
client.exhaustResponse(copyMethod.getResponseAsStream());
|
client.exhaustResponse(copyMethod.getResponseAsStream());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,7 +131,7 @@ public class CopyRemoteFileOperation extends RemoteOperation {
|
|||||||
result.getLogMessage());
|
result.getLogMessage());
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
result = new RemoteOperationResult(e);
|
result = new RemoteOperationResult<>(e);
|
||||||
Log.e(TAG, "Copy " + mSrcRemotePath + " to " + mTargetRemotePath + ": " +
|
Log.e(TAG, "Copy " + mSrcRemotePath + " to " + mTargetRemotePath + ": " +
|
||||||
result.getLogMessage(), e);
|
result.getLogMessage(), e);
|
||||||
}
|
}
|
||||||
|
@ -31,17 +31,15 @@ import com.owncloud.android.lib.common.OwnCloudClient;
|
|||||||
import com.owncloud.android.lib.common.http.HttpConstants;
|
import com.owncloud.android.lib.common.http.HttpConstants;
|
||||||
import com.owncloud.android.lib.common.http.methods.webdav.MkColMethod;
|
import com.owncloud.android.lib.common.http.methods.webdav.MkColMethod;
|
||||||
import com.owncloud.android.lib.common.network.WebdavUtils;
|
import com.owncloud.android.lib.common.network.WebdavUtils;
|
||||||
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
|
||||||
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.operations.RemoteOperationResult.ResultCode;
|
|
||||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
|
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import okhttp3.HttpUrl;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remote operation performing the creation of a new folder in the ownCloud server.
|
* Remote operation performing the creation of a new folder in the ownCloud server.
|
||||||
@ -94,7 +92,7 @@ public class CreateRemoteFolderOperation extends RemoteOperation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
result = new RemoteOperationResult(ResultCode.INVALID_CHARACTER_IN_NAME);
|
result = new RemoteOperationResult<>(ResultCode.INVALID_CHARACTER_IN_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@ -111,13 +109,13 @@ public class CreateRemoteFolderOperation extends RemoteOperation {
|
|||||||
final int status = client.executeHttpMethod(mkcol);
|
final int status = client.executeHttpMethod(mkcol);
|
||||||
|
|
||||||
result = (status == HttpConstants.HTTP_CREATED)
|
result = (status == HttpConstants.HTTP_CREATED)
|
||||||
? new RemoteOperationResult(ResultCode.OK)
|
? new RemoteOperationResult<>(ResultCode.OK)
|
||||||
: new RemoteOperationResult(mkcol);
|
: new RemoteOperationResult<>(mkcol);
|
||||||
Log_OC.d(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage());
|
Log_OC.d(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage());
|
||||||
client.exhaustResponse(mkcol.getResponseAsStream());
|
client.exhaustResponse(mkcol.getResponseAsStream());
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
result = new RemoteOperationResult(e);
|
result = new RemoteOperationResult<>(e);
|
||||||
Log_OC.e(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage(), e);
|
Log_OC.e(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,8 +44,6 @@ import java.util.Iterator;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
import okhttp3.HttpUrl;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remote operation performing the download of a remote file in the ownCloud server.
|
* Remote operation performing the download of a remote file in the ownCloud server.
|
||||||
*
|
*
|
||||||
@ -88,7 +86,7 @@ public class DownloadRemoteFileOperation extends RemoteOperation {
|
|||||||
result.getLogMessage());
|
result.getLogMessage());
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
result = new RemoteOperationResult(e);
|
result = new RemoteOperationResult<>(e);
|
||||||
Log_OC.e(TAG, "Download of " + mRemotePath + " to " + getTmpPath() + ": " +
|
Log_OC.e(TAG, "Download of " + mRemotePath + " to " + getTmpPath() + ": " +
|
||||||
result.getLogMessage(), e);
|
result.getLogMessage(), e);
|
||||||
}
|
}
|
||||||
@ -172,8 +170,8 @@ public class DownloadRemoteFileOperation extends RemoteOperation {
|
|||||||
} // else, body read by RemoteOperationResult constructor
|
} // else, body read by RemoteOperationResult constructor
|
||||||
|
|
||||||
result = isSuccess(status)
|
result = isSuccess(status)
|
||||||
? new RemoteOperationResult(RemoteOperationResult.ResultCode.OK)
|
? new RemoteOperationResult<>(RemoteOperationResult.ResultCode.OK)
|
||||||
: new RemoteOperationResult(mGet);
|
: new RemoteOperationResult<>(mGet);
|
||||||
} finally {
|
} finally {
|
||||||
if (fos != null) fos.close();
|
if (fos != null) fos.close();
|
||||||
if (bis != null) bis.close();
|
if (bis != null) bis.close();
|
||||||
|
@ -102,19 +102,17 @@ public class ExistenceCheckRemoteOperation extends RemoteOperation {
|
|||||||
"finished with HTTP status " + status + (!isSuccess(status) ? "(FAIL)" : ""));
|
"finished with HTTP status " + status + (!isSuccess(status) ? "(FAIL)" : ""));
|
||||||
|
|
||||||
return isSuccess(status)
|
return isSuccess(status)
|
||||||
? new RemoteOperationResult(OK)
|
? new RemoteOperationResult<>(OK)
|
||||||
: new RemoteOperationResult(propfindMethod);
|
: new RemoteOperationResult<>(propfindMethod);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
final RemoteOperationResult result = new RemoteOperationResult(e);
|
final RemoteOperationResult result = new RemoteOperationResult<>(e);
|
||||||
Log_OC.e(TAG, "Existence check for " + client.getNewFilesWebDavUri() +
|
Log_OC.e(TAG, "Existence check for " + client.getNewFilesWebDavUri() +
|
||||||
WebdavUtils.encodePath(mPath) + " targeting for " +
|
WebdavUtils.encodePath(mPath) + " targeting for " +
|
||||||
(mSuccessIfAbsent ? " absence " : " existence ") + ": " +
|
(mSuccessIfAbsent ? " absence " : " existence ") + ": " +
|
||||||
result.getLogMessage(), result.getException());
|
result.getLogMessage(), result.getException());
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,16 +31,14 @@ import com.owncloud.android.lib.common.OwnCloudClient;
|
|||||||
import com.owncloud.android.lib.common.http.HttpConstants;
|
import com.owncloud.android.lib.common.http.HttpConstants;
|
||||||
import com.owncloud.android.lib.common.http.methods.webdav.MoveMethod;
|
import com.owncloud.android.lib.common.http.methods.webdav.MoveMethod;
|
||||||
import com.owncloud.android.lib.common.network.WebdavUtils;
|
import com.owncloud.android.lib.common.network.WebdavUtils;
|
||||||
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
|
||||||
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.operations.RemoteOperationResult.ResultCode;
|
|
||||||
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
|
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import okhttp3.HttpUrl;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remote operation moving a remote file or folder in the ownCloud server to a different folder
|
* Remote operation moving a remote file or folder in the ownCloud server to a different folder
|
||||||
* in the same account.
|
* in the same account.
|
||||||
@ -96,16 +94,16 @@ public class MoveRemoteFileOperation extends RemoteOperation {
|
|||||||
|
|
||||||
/// check parameters
|
/// check parameters
|
||||||
if (!FileUtils.isValidPath(mTargetRemotePath, versionWithForbiddenChars)) {
|
if (!FileUtils.isValidPath(mTargetRemotePath, versionWithForbiddenChars)) {
|
||||||
return new RemoteOperationResult(ResultCode.INVALID_CHARACTER_IN_NAME);
|
return new RemoteOperationResult<>(ResultCode.INVALID_CHARACTER_IN_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mTargetRemotePath.equals(mSrcRemotePath)) {
|
if (mTargetRemotePath.equals(mSrcRemotePath)) {
|
||||||
// nothing to do!
|
// nothing to do!
|
||||||
return new RemoteOperationResult(ResultCode.OK);
|
return new RemoteOperationResult<>(ResultCode.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mTargetRemotePath.startsWith(mSrcRemotePath)) {
|
if (mTargetRemotePath.startsWith(mSrcRemotePath)) {
|
||||||
return new RemoteOperationResult(ResultCode.INVALID_MOVE_INTO_DESCENDANT);
|
return new RemoteOperationResult<>(ResultCode.INVALID_MOVE_INTO_DESCENDANT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// perform remote operation
|
/// perform remote operation
|
||||||
@ -132,17 +130,17 @@ public class MoveRemoteFileOperation extends RemoteOperation {
|
|||||||
final int status = client.executeHttpMethod(move);
|
final int status = client.executeHttpMethod(move);
|
||||||
/// process response
|
/// process response
|
||||||
if(isSuccess(status)) {
|
if(isSuccess(status)) {
|
||||||
result = new RemoteOperationResult(ResultCode.OK);
|
result = new RemoteOperationResult<>(ResultCode.OK);
|
||||||
} else if (status == HttpConstants.HTTP_PRECONDITION_FAILED && !mOverwrite) {
|
} else if (status == HttpConstants.HTTP_PRECONDITION_FAILED && !mOverwrite) {
|
||||||
|
|
||||||
result = new RemoteOperationResult(ResultCode.INVALID_OVERWRITE);
|
result = new RemoteOperationResult<>(ResultCode.INVALID_OVERWRITE);
|
||||||
client.exhaustResponse(move.getResponseAsStream());
|
client.exhaustResponse(move.getResponseAsStream());
|
||||||
|
|
||||||
/// for other errors that could be explicitly handled, check first:
|
/// for other errors that could be explicitly handled, check first:
|
||||||
/// http://www.webdav.org/specs/rfc4918.html#rfc.section.9.9.4
|
/// http://www.webdav.org/specs/rfc4918.html#rfc.section.9.9.4
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
result = new RemoteOperationResult(move);
|
result = new RemoteOperationResult<>(move);
|
||||||
client.exhaustResponse(move.getResponseAsStream());
|
client.exhaustResponse(move.getResponseAsStream());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,7 +148,7 @@ public class MoveRemoteFileOperation extends RemoteOperation {
|
|||||||
result.getLogMessage());
|
result.getLogMessage());
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
result = new RemoteOperationResult(e);
|
result = new RemoteOperationResult<>(e);
|
||||||
Log.e(TAG, "Move " + mSrcRemotePath + " to " + mTargetRemotePath + ": " +
|
Log.e(TAG, "Move " + mSrcRemotePath + " to " + mTargetRemotePath + ": " +
|
||||||
result.getLogMessage(), e);
|
result.getLogMessage(), e);
|
||||||
}
|
}
|
||||||
|
@ -33,11 +33,9 @@ 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 java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import at.bitfire.dav4android.DavResource;
|
import at.bitfire.dav4android.DavResource;
|
||||||
import okhttp3.HttpUrl;
|
|
||||||
|
|
||||||
import static com.owncloud.android.lib.common.http.methods.webdav.DavConstants.DEPTH_0;
|
import static com.owncloud.android.lib.common.http.methods.webdav.DavConstants.DEPTH_0;
|
||||||
import static com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.OK;
|
import static com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.OK;
|
||||||
@ -49,7 +47,7 @@ import static com.owncloud.android.lib.common.operations.RemoteOperationResult.R
|
|||||||
* @author masensio
|
* @author masensio
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class ReadRemoteFileOperation extends RemoteOperation {
|
public class ReadRemoteFileOperation extends RemoteOperation<RemoteFile> {
|
||||||
|
|
||||||
private static final String TAG = ReadRemoteFileOperation.class.getSimpleName();
|
private static final String TAG = ReadRemoteFileOperation.class.getSimpleName();
|
||||||
private static final int SYNC_READ_TIMEOUT = 40000;
|
private static final int SYNC_READ_TIMEOUT = 40000;
|
||||||
@ -72,9 +70,9 @@ public class ReadRemoteFileOperation extends RemoteOperation {
|
|||||||
* @param client Client object to communicate with the remote ownCloud server.
|
* @param client Client object to communicate with the remote ownCloud server.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected RemoteOperationResult run(OwnCloudClient client) {
|
protected RemoteOperationResult<RemoteFile> run(OwnCloudClient client) {
|
||||||
PropfindMethod propfind;
|
PropfindMethod propfind;
|
||||||
RemoteOperationResult result;
|
RemoteOperationResult<RemoteFile> result;
|
||||||
|
|
||||||
/// take the duty of check the server for the current state of the file there
|
/// take the duty of check the server for the current state of the file there
|
||||||
try {
|
try {
|
||||||
@ -94,19 +92,16 @@ public class ReadRemoteFileOperation extends RemoteOperation {
|
|||||||
|
|
||||||
final RemoteFile file = new RemoteFile(resource, client.getAccount().getDisplayName());
|
final RemoteFile file = new RemoteFile(resource, client.getAccount().getDisplayName());
|
||||||
|
|
||||||
ArrayList<Object> files = new ArrayList<>();
|
result = new RemoteOperationResult<>(OK);
|
||||||
files.add(file);
|
result.setData(file);
|
||||||
|
|
||||||
result = new RemoteOperationResult(OK);
|
|
||||||
result.setData(files);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
result = new RemoteOperationResult(propfind);
|
result = new RemoteOperationResult<>(propfind);
|
||||||
client.exhaustResponse(propfind.getResponseAsStream());
|
client.exhaustResponse(propfind.getResponseAsStream());
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
result = new RemoteOperationResult(e);
|
result = new RemoteOperationResult<>(e);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Log_OC.e(TAG, "Synchronizing file " + mRemotePath + ": " + result.getLogMessage(),
|
Log_OC.e(TAG, "Synchronizing file " + mRemotePath + ": " + result.getLogMessage(),
|
||||||
result.getException());
|
result.getException());
|
||||||
|
@ -49,7 +49,7 @@ import static com.owncloud.android.lib.common.operations.RemoteOperationResult.R
|
|||||||
* @author David González Verdugo
|
* @author David González Verdugo
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class ReadRemoteFolderOperation extends RemoteOperation {
|
public class ReadRemoteFolderOperation extends RemoteOperation<ArrayList<RemoteFile>> {
|
||||||
|
|
||||||
private static final String TAG = ReadRemoteFolderOperation.class.getSimpleName();
|
private static final String TAG = ReadRemoteFolderOperation.class.getSimpleName();
|
||||||
|
|
||||||
@ -70,8 +70,8 @@ public class ReadRemoteFolderOperation extends RemoteOperation {
|
|||||||
* @param client Client object to communicate with the remote ownCloud server.
|
* @param client Client object to communicate with the remote ownCloud server.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected RemoteOperationResult run(OwnCloudClient client) {
|
protected RemoteOperationResult<ArrayList<RemoteFile>> run(OwnCloudClient client) {
|
||||||
RemoteOperationResult result = null;
|
RemoteOperationResult<ArrayList<RemoteFile>> result = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
PropfindMethod propfindMethod = new PropfindMethod(
|
PropfindMethod propfindMethod = new PropfindMethod(
|
||||||
@ -84,7 +84,7 @@ public class ReadRemoteFolderOperation extends RemoteOperation {
|
|||||||
int status = client.executeHttpMethod(propfindMethod);
|
int status = client.executeHttpMethod(propfindMethod);
|
||||||
|
|
||||||
if (isSuccess(status)) {
|
if (isSuccess(status)) {
|
||||||
ArrayList<Object> mFolderAndFiles = new ArrayList<>();
|
ArrayList<RemoteFile> mFolderAndFiles = new ArrayList<>();
|
||||||
|
|
||||||
// parse data from remote folder
|
// parse data from remote folder
|
||||||
mFolderAndFiles.add(
|
mFolderAndFiles.add(
|
||||||
@ -98,15 +98,15 @@ public class ReadRemoteFolderOperation extends RemoteOperation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Result of the operation
|
// Result of the operation
|
||||||
result = new RemoteOperationResult(OK);
|
result = new RemoteOperationResult<>(OK);
|
||||||
result.setData(mFolderAndFiles);
|
result.setData(mFolderAndFiles);
|
||||||
|
|
||||||
} else { // synchronization failed
|
} else { // synchronization failed
|
||||||
result = new RemoteOperationResult(propfindMethod);
|
result = new RemoteOperationResult<> (propfindMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
result = new RemoteOperationResult(e);
|
result = new RemoteOperationResult<>(e);
|
||||||
} finally {
|
} finally {
|
||||||
if (result.isSuccess()) {
|
if (result.isSuccess()) {
|
||||||
Log_OC.i(TAG, "Synchronized " + mRemotePath + ": " + result.getLogMessage());
|
Log_OC.i(TAG, "Synchronized " + mRemotePath + ": " + result.getLogMessage());
|
||||||
|
@ -78,13 +78,13 @@ public class RemoveRemoteFileOperation extends RemoteOperation {
|
|||||||
int status = client.executeHttpMethod(deleteMethod);
|
int status = client.executeHttpMethod(deleteMethod);
|
||||||
|
|
||||||
result = isSuccess(status) ?
|
result = isSuccess(status) ?
|
||||||
new RemoteOperationResult(OK) :
|
new RemoteOperationResult<>(OK) :
|
||||||
new RemoteOperationResult(deleteMethod);
|
new RemoteOperationResult<>(deleteMethod);
|
||||||
|
|
||||||
Log_OC.i(TAG, "Remove " + mRemotePath + ": " + result.getLogMessage());
|
Log_OC.i(TAG, "Remove " + mRemotePath + ": " + result.getLogMessage());
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
result = new RemoteOperationResult(e);
|
result = new RemoteOperationResult<>(e);
|
||||||
Log_OC.e(TAG, "Remove " + mRemotePath + ": " + result.getLogMessage(), e);
|
Log_OC.e(TAG, "Remove " + mRemotePath + ": " + result.getLogMessage(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,14 +32,12 @@ import com.owncloud.android.lib.common.OwnCloudClient;
|
|||||||
import com.owncloud.android.lib.common.http.HttpConstants;
|
import com.owncloud.android.lib.common.http.HttpConstants;
|
||||||
import com.owncloud.android.lib.common.http.methods.webdav.MoveMethod;
|
import com.owncloud.android.lib.common.http.methods.webdav.MoveMethod;
|
||||||
import com.owncloud.android.lib.common.network.WebdavUtils;
|
import com.owncloud.android.lib.common.network.WebdavUtils;
|
||||||
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
|
||||||
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.operations.RemoteOperationResult.ResultCode;
|
|
||||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
|
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
|
||||||
|
|
||||||
import okhttp3.HttpUrl;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remote operation performing the rename of a remote file or folder in the ownCloud server.
|
* Remote operation performing the rename of a remote file or folder in the ownCloud server.
|
||||||
@ -96,15 +94,15 @@ public class RenameRemoteFileOperation extends RemoteOperation {
|
|||||||
(version != null && version.isVersionWithForbiddenCharacters());
|
(version != null && version.isVersionWithForbiddenCharacters());
|
||||||
|
|
||||||
if(!FileUtils.isValidPath(mNewRemotePath, versionWithForbiddenChars))
|
if(!FileUtils.isValidPath(mNewRemotePath, versionWithForbiddenChars))
|
||||||
return new RemoteOperationResult(ResultCode.INVALID_CHARACTER_IN_NAME);
|
return new RemoteOperationResult<>(ResultCode.INVALID_CHARACTER_IN_NAME);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (mNewName.equals(mOldName)) {
|
if (mNewName.equals(mOldName)) {
|
||||||
return new RemoteOperationResult(ResultCode.OK);
|
return new RemoteOperationResult<>(ResultCode.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (targetPathIsUsed(client)) {
|
if (targetPathIsUsed(client)) {
|
||||||
return new RemoteOperationResult(ResultCode.INVALID_OVERWRITE);
|
return new RemoteOperationResult<>(ResultCode.INVALID_OVERWRITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
final MoveMethod move = new MoveMethod(new URL(client.getNewFilesWebDavUri() +
|
final MoveMethod move = new MoveMethod(new URL(client.getNewFilesWebDavUri() +
|
||||||
@ -117,8 +115,8 @@ public class RenameRemoteFileOperation extends RemoteOperation {
|
|||||||
final int status = client.executeHttpMethod(move);
|
final int status = client.executeHttpMethod(move);
|
||||||
final RemoteOperationResult result =
|
final RemoteOperationResult result =
|
||||||
(status == HttpConstants.HTTP_CREATED || status == HttpConstants.HTTP_NO_CONTENT)
|
(status == HttpConstants.HTTP_CREATED || status == HttpConstants.HTTP_NO_CONTENT)
|
||||||
? new RemoteOperationResult(ResultCode.OK)
|
? new RemoteOperationResult<>(ResultCode.OK)
|
||||||
: new RemoteOperationResult(move);
|
: new RemoteOperationResult<>(move);
|
||||||
|
|
||||||
Log_OC.i(TAG, "Rename " + mOldRemotePath + " to " + mNewRemotePath + ": " +
|
Log_OC.i(TAG, "Rename " + mOldRemotePath + " to " + mNewRemotePath + ": " +
|
||||||
result.getLogMessage()
|
result.getLogMessage()
|
||||||
@ -126,7 +124,7 @@ public class RenameRemoteFileOperation extends RemoteOperation {
|
|||||||
client.exhaustResponse(move.getResponseAsStream());
|
client.exhaustResponse(move.getResponseAsStream());
|
||||||
return result;
|
return result;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
final RemoteOperationResult result = new RemoteOperationResult(e);
|
final RemoteOperationResult result = new RemoteOperationResult<>(e);
|
||||||
Log_OC.e(TAG, "Rename " + mOldRemotePath + " to " +
|
Log_OC.e(TAG, "Rename " + mOldRemotePath + " to " +
|
||||||
((mNewRemotePath == null) ? mNewName : mNewRemotePath) + ": " +
|
((mNewRemotePath == null) ? mNewName : mNewRemotePath) + ": " +
|
||||||
result.getLogMessage(), e);
|
result.getLogMessage(), e);
|
||||||
|
@ -95,7 +95,7 @@ public class UploadRemoteFileOperation extends RemoteOperation {
|
|||||||
|
|
||||||
if (mCancellationRequested.get()) {
|
if (mCancellationRequested.get()) {
|
||||||
// the operation was cancelled before getting it's turn to be executed in the queue of uploads
|
// the operation was cancelled before getting it's turn to be executed in the queue of uploads
|
||||||
result = new RemoteOperationResult(new OperationCancelledException());
|
result = new RemoteOperationResult<>(new OperationCancelledException());
|
||||||
} else {
|
} else {
|
||||||
// perform the upload
|
// perform the upload
|
||||||
result = uploadFile(client);
|
result = uploadFile(client);
|
||||||
@ -106,11 +106,11 @@ public class UploadRemoteFileOperation extends RemoteOperation {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
||||||
if (mPutMethod != null && mPutMethod.isAborted()) {
|
if (mPutMethod != null && mPutMethod.isAborted()) {
|
||||||
result = new RemoteOperationResult(new OperationCancelledException());
|
result = new RemoteOperationResult<>(new OperationCancelledException());
|
||||||
Log_OC.e(TAG, "Upload of " + mLocalPath + " to " + mRemotePath + ": " +
|
Log_OC.e(TAG, "Upload of " + mLocalPath + " to " + mRemotePath + ": " +
|
||||||
result.getLogMessage(), new OperationCancelledException());
|
result.getLogMessage(), new OperationCancelledException());
|
||||||
} else {
|
} else {
|
||||||
result = new RemoteOperationResult(e);
|
result = new RemoteOperationResult<>(e);
|
||||||
Log_OC.e(TAG, "Upload of " + mLocalPath + " to " + mRemotePath + ": " +
|
Log_OC.e(TAG, "Upload of " + mLocalPath + " to " + mRemotePath + ": " +
|
||||||
result.getLogMessage(), e);
|
result.getLogMessage(), e);
|
||||||
}
|
}
|
||||||
@ -119,7 +119,7 @@ public class UploadRemoteFileOperation extends RemoteOperation {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected RemoteOperationResult uploadFile(OwnCloudClient client) throws Exception {
|
protected RemoteOperationResult<? extends Object> uploadFile(OwnCloudClient client) throws Exception {
|
||||||
|
|
||||||
File fileToUpload = new File(mLocalPath);
|
File fileToUpload = new File(mLocalPath);
|
||||||
|
|
||||||
@ -144,10 +144,10 @@ public class UploadRemoteFileOperation extends RemoteOperation {
|
|||||||
int status = client.executeHttpMethod(mPutMethod);
|
int status = client.executeHttpMethod(mPutMethod);
|
||||||
|
|
||||||
if (isSuccess(status)) {
|
if (isSuccess(status)) {
|
||||||
return new RemoteOperationResult(OK);
|
return new RemoteOperationResult<>(OK);
|
||||||
|
|
||||||
} else { // synchronization failed
|
} else { // synchronization failed
|
||||||
return new RemoteOperationResult(mPutMethod);
|
return new RemoteOperationResult<>(mPutMethod);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,6 +43,7 @@ import okhttp3.MediaType;
|
|||||||
|
|
||||||
import static com.owncloud.android.lib.common.http.HttpConstants.IF_MATCH_HEADER;
|
import static com.owncloud.android.lib.common.http.HttpConstants.IF_MATCH_HEADER;
|
||||||
import static com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.OK;
|
import static com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.OK;
|
||||||
|
import static com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.OK;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remote operation performing the chunked upload of a remote file to the ownCloud server.
|
* Remote operation performing the chunked upload of a remote file to the ownCloud server.
|
||||||
@ -100,7 +101,7 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation
|
|||||||
((ChunkFromFileRequestBody) mFileRequestBody).setOffset(offset);
|
((ChunkFromFileRequestBody) mFileRequestBody).setOffset(offset);
|
||||||
|
|
||||||
if (mCancellationRequested.get()) {
|
if (mCancellationRequested.get()) {
|
||||||
result = new RemoteOperationResult(new OperationCancelledException());
|
result = new RemoteOperationResult<>(new OperationCancelledException());
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
if (chunkIndex == chunkCount - 1) {
|
if (chunkIndex == chunkCount - 1) {
|
||||||
@ -119,9 +120,9 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation
|
|||||||
", HTTP result status " + status);
|
", HTTP result status " + status);
|
||||||
|
|
||||||
if (isSuccess(status)) {
|
if (isSuccess(status)) {
|
||||||
result = new RemoteOperationResult(OK);
|
result = new RemoteOperationResult<>(OK);
|
||||||
} else {
|
} else {
|
||||||
result = new RemoteOperationResult(mPutMethod);
|
result = new RemoteOperationResult<>(mPutMethod);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -186,17 +186,13 @@ public class CreateRemoteShareOperation extends RemoteOperation {
|
|||||||
mPublicUpload = publicUpload;
|
mPublicUpload = publicUpload;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isGettingShareDetails() {
|
|
||||||
return mGetShareDetails;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGetShareDetails(boolean set) {
|
public void setGetShareDetails(boolean set) {
|
||||||
mGetShareDetails = set;
|
mGetShareDetails = set;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected RemoteOperationResult run(OwnCloudClient client) {
|
protected RemoteOperationResult<ShareParserResult> run(OwnCloudClient client) {
|
||||||
RemoteOperationResult result;
|
RemoteOperationResult<ShareParserResult> result;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
FormBody.Builder formBodyBuilder = new FormBody.Builder()
|
FormBody.Builder formBodyBuilder = new FormBody.Builder()
|
||||||
@ -253,7 +249,7 @@ public class CreateRemoteShareOperation extends RemoteOperation {
|
|||||||
|
|
||||||
// TODO Use executeHttpMethod
|
// TODO Use executeHttpMethod
|
||||||
// retrieve more info - POST only returns the index of the new share
|
// retrieve more info - POST only returns the index of the new share
|
||||||
OCShare emptyShare = (OCShare) result.getData().get(0);
|
OCShare emptyShare = result.getData().getShares().get(0);
|
||||||
GetRemoteShareOperation getInfo = new GetRemoteShareOperation(
|
GetRemoteShareOperation getInfo = new GetRemoteShareOperation(
|
||||||
emptyShare.getRemoteId()
|
emptyShare.getRemoteId()
|
||||||
);
|
);
|
||||||
@ -261,11 +257,11 @@ public class CreateRemoteShareOperation extends RemoteOperation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
result = new RemoteOperationResult(postMethod);
|
result = new RemoteOperationResult<>(postMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
result = new RemoteOperationResult(e);
|
result = new RemoteOperationResult<>(e);
|
||||||
Log_OC.e(TAG, "Exception while Creating New Share", e);
|
Log_OC.e(TAG, "Exception while Creating New Share", e);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -44,7 +44,7 @@ import java.net.URL;
|
|||||||
* @author David González Verdugo
|
* @author David González Verdugo
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class GetRemoteShareOperation extends RemoteOperation {
|
public class GetRemoteShareOperation extends RemoteOperation<ShareParserResult> {
|
||||||
|
|
||||||
private static final String TAG = GetRemoteShareOperation.class.getSimpleName();
|
private static final String TAG = GetRemoteShareOperation.class.getSimpleName();
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ public class GetRemoteShareOperation extends RemoteOperation {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected RemoteOperationResult run(OwnCloudClient client) {
|
protected RemoteOperationResult run(OwnCloudClient client) {
|
||||||
RemoteOperationResult result;
|
RemoteOperationResult<ShareParserResult> result;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Uri requestUri = client.getBaseUri();
|
Uri requestUri = client.getBaseUri();
|
||||||
@ -83,11 +83,11 @@ public class GetRemoteShareOperation extends RemoteOperation {
|
|||||||
result = parser.parse(getMethod.getResponseBodyAsString());
|
result = parser.parse(getMethod.getResponseBodyAsString());
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
result = new RemoteOperationResult(getMethod);
|
result = new RemoteOperationResult<>(getMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
result = new RemoteOperationResult(e);
|
result = new RemoteOperationResult<>(e);
|
||||||
Log_OC.e(TAG, "Exception while getting remote shares ", e);
|
Log_OC.e(TAG, "Exception while getting remote shares ", e);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -70,7 +70,7 @@ import static com.owncloud.android.lib.common.operations.RemoteOperationResult.R
|
|||||||
* @author David A. Velasco
|
* @author David A. Velasco
|
||||||
* @author David González Verdugo
|
* @author David González Verdugo
|
||||||
*/
|
*/
|
||||||
public class GetRemoteShareesOperation extends RemoteOperation{
|
public class GetRemoteShareesOperation extends RemoteOperation<ArrayList<JSONObject>> {
|
||||||
|
|
||||||
private static final String TAG = GetRemoteShareesOperation.class.getSimpleName();
|
private static final String TAG = GetRemoteShareesOperation.class.getSimpleName();
|
||||||
|
|
||||||
@ -118,8 +118,8 @@ public class GetRemoteShareesOperation extends RemoteOperation{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected RemoteOperationResult run(OwnCloudClient client) {
|
protected RemoteOperationResult<ArrayList<JSONObject>> run(OwnCloudClient client) {
|
||||||
RemoteOperationResult result;
|
RemoteOperationResult<ArrayList<JSONObject>> result;
|
||||||
|
|
||||||
try{
|
try{
|
||||||
Uri requestUri = client.getBaseUri();
|
Uri requestUri = client.getBaseUri();
|
||||||
@ -161,7 +161,7 @@ public class GetRemoteShareesOperation extends RemoteOperation{
|
|||||||
respPartialRemotes
|
respPartialRemotes
|
||||||
};
|
};
|
||||||
|
|
||||||
ArrayList<Object> data = new ArrayList<Object>(); // For result data
|
ArrayList<JSONObject> data = new ArrayList<>(); // For result data
|
||||||
for (int i=0; i<6; i++) {
|
for (int i=0; i<6; i++) {
|
||||||
for(int j=0; j< jsonResults[i].length(); j++){
|
for(int j=0; j< jsonResults[i].length(); j++){
|
||||||
JSONObject jsonResult = jsonResults[i].getJSONObject(j);
|
JSONObject jsonResult = jsonResults[i].getJSONObject(j);
|
||||||
@ -170,13 +170,13 @@ public class GetRemoteShareesOperation extends RemoteOperation{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result = new RemoteOperationResult(OK);
|
result = new RemoteOperationResult<>(OK);
|
||||||
result.setData(data);
|
result.setData(data);
|
||||||
|
|
||||||
Log_OC.d(TAG, "*** Get Users or groups completed " );
|
Log_OC.d(TAG, "*** Get Users or groups completed " );
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
result = new RemoteOperationResult(getMethod);
|
result = new RemoteOperationResult<>(getMethod);
|
||||||
Log_OC.e(TAG, "Failed response while getting users/groups 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);
|
||||||
@ -185,7 +185,7 @@ public class GetRemoteShareesOperation extends RemoteOperation{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
result = new RemoteOperationResult(e);
|
result = new RemoteOperationResult<>(e);
|
||||||
Log_OC.e(TAG, "Exception while getting users/groups", e);
|
Log_OC.e(TAG, "Exception while getting users/groups", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,8 +38,6 @@ import com.owncloud.android.lib.common.utils.Log_OC;
|
|||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
import okhttp3.HttpUrl;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provide a list shares for a specific file.
|
* Provide a list shares for a specific file.
|
||||||
* The input is the full path of the desired file.
|
* The input is the full path of the desired file.
|
||||||
@ -49,7 +47,7 @@ import okhttp3.HttpUrl;
|
|||||||
* @author David A. Velasco
|
* @author David A. Velasco
|
||||||
* @author David González Verdugo
|
* @author David González Verdugo
|
||||||
*/
|
*/
|
||||||
public class GetRemoteSharesForFileOperation extends RemoteOperation {
|
public class GetRemoteSharesForFileOperation extends RemoteOperation<ShareParserResult> {
|
||||||
|
|
||||||
private static final String TAG = GetRemoteSharesForFileOperation.class.getSimpleName();
|
private static final String TAG = GetRemoteSharesForFileOperation.class.getSimpleName();
|
||||||
|
|
||||||
@ -79,8 +77,8 @@ public class GetRemoteSharesForFileOperation extends RemoteOperation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected RemoteOperationResult run(OwnCloudClient client) {
|
protected RemoteOperationResult<ShareParserResult> run(OwnCloudClient client) {
|
||||||
RemoteOperationResult result;
|
RemoteOperationResult<ShareParserResult> result;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
@ -107,13 +105,13 @@ public class GetRemoteSharesForFileOperation extends RemoteOperation {
|
|||||||
result = parser.parse(getMethod.getResponseBodyAsString());
|
result = parser.parse(getMethod.getResponseBodyAsString());
|
||||||
|
|
||||||
if (result.isSuccess()) {
|
if (result.isSuccess()) {
|
||||||
Log_OC.d(TAG, "Got " + result.getData().size() + " shares");
|
Log_OC.d(TAG, "Got " + result.getData().getShares().size() + " shares");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
result = new RemoteOperationResult(getMethod);
|
result = new RemoteOperationResult<>(getMethod);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
result = new RemoteOperationResult(e);
|
result = new RemoteOperationResult<>(e);
|
||||||
Log_OC.e(TAG, "Exception while getting shares", e);
|
Log_OC.e(TAG, "Exception while getting shares", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,10 +75,10 @@ public class GetRemoteSharesOperation extends RemoteOperation {
|
|||||||
parser.setServerBaseUri(client.getBaseUri());
|
parser.setServerBaseUri(client.getBaseUri());
|
||||||
result = parser.parse(getMethod.getResponseBodyAsString());
|
result = parser.parse(getMethod.getResponseBodyAsString());
|
||||||
} else {
|
} else {
|
||||||
result = new RemoteOperationResult(getMethod);
|
result = new RemoteOperationResult<>(getMethod);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
result = new RemoteOperationResult(e);
|
result = new RemoteOperationResult<>(e);
|
||||||
Log_OC.e(TAG, "Exception while getting remote shares ", e);
|
Log_OC.e(TAG, "Exception while getting remote shares ", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,11 +91,11 @@ public class RemoveRemoteShareOperation extends RemoteOperation {
|
|||||||
Log_OC.d(TAG, "Unshare " + mRemoteShareId + ": " + result.getLogMessage());
|
Log_OC.d(TAG, "Unshare " + mRemoteShareId + ": " + result.getLogMessage());
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
result = new RemoteOperationResult(deleteMethod);
|
result = new RemoteOperationResult<>(deleteMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
result = new RemoteOperationResult(e);
|
result = new RemoteOperationResult<>(e);
|
||||||
Log_OC.e(TAG, "Unshare Link Exception " + result.getLogMessage(), e);
|
Log_OC.e(TAG, "Unshare Link Exception " + result.getLogMessage(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
package com.owncloud.android.lib.resources.shares;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class ShareParserResult {
|
||||||
|
private ArrayList<OCShare> shares;
|
||||||
|
private String parserMessage;
|
||||||
|
|
||||||
|
public ShareParserResult(ArrayList<OCShare> shares, String parserMessage) {
|
||||||
|
this.shares = shares;
|
||||||
|
this.parserMessage = parserMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<OCShare> getShares() {
|
||||||
|
return shares;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getParserMessage() {
|
||||||
|
return parserMessage;
|
||||||
|
}
|
||||||
|
}
|
@ -66,13 +66,13 @@ public class ShareToRemoteOperationResultParser {
|
|||||||
mServerBaseUri = serverBaseURi;
|
mServerBaseUri = serverBaseURi;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RemoteOperationResult parse(String serverResponse) {
|
public RemoteOperationResult<ShareParserResult> parse(String serverResponse) {
|
||||||
if (serverResponse == null || serverResponse.length() == 0) {
|
if (serverResponse == null || serverResponse.length() == 0) {
|
||||||
return new RemoteOperationResult(RemoteOperationResult.ResultCode.WRONG_SERVER_RESPONSE);
|
return new RemoteOperationResult<>(RemoteOperationResult.ResultCode.WRONG_SERVER_RESPONSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
RemoteOperationResult result;
|
RemoteOperationResult<ShareParserResult> result;
|
||||||
ArrayList<Object> resultData = new ArrayList<Object>();
|
final ArrayList<OCShare> resultData = new ArrayList<>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Parse xml response and obtain the list of shares
|
// Parse xml response and obtain the list of shares
|
||||||
@ -85,17 +85,16 @@ public class ShareToRemoteOperationResultParser {
|
|||||||
|
|
||||||
if (mShareXmlParser.isSuccess()) {
|
if (mShareXmlParser.isSuccess()) {
|
||||||
if ((shares != null && shares.size() > 0) || !mOneOrMoreSharesRequired) {
|
if ((shares != null && shares.size() > 0) || !mOneOrMoreSharesRequired) {
|
||||||
result = new RemoteOperationResult(RemoteOperationResult.ResultCode.OK);
|
result = new RemoteOperationResult<>(RemoteOperationResult.ResultCode.OK);
|
||||||
if (shares != null) {
|
if (shares != null) {
|
||||||
for (OCShare share : shares) {
|
for (OCShare share : shares) {
|
||||||
resultData.add(share);
|
resultData.add(share);
|
||||||
// build the share link if not in the response
|
// build the share link if not in the response
|
||||||
// (needed for OC servers < 9.0.0, see ShareXMLParser.java#line256)
|
// (needed for OC servers < 9.0.0, see ShareXMLParser.java#line256)
|
||||||
if (share.getShareType() == ShareType.PUBLIC_LINK &&
|
if (share.getShareType() == ShareType.PUBLIC_LINK
|
||||||
(share.getShareLink() == null ||
|
&& (share.getShareLink() == null
|
||||||
share.getShareLink().length() <= 0) &&
|
|| share.getShareLink().length() <= 0)
|
||||||
share.getToken().length() > 0
|
&& share.getToken().length() > 0) {
|
||||||
) {
|
|
||||||
if (mServerBaseUri != null) {
|
if (mServerBaseUri != null) {
|
||||||
String sharingLinkPath = ShareUtils.getSharingLinkPath(mOwnCloudVersion);
|
String sharingLinkPath = ShareUtils.getSharingLinkPath(mOwnCloudVersion);
|
||||||
share.setShareLink(mServerBaseUri + sharingLinkPath + share.getToken());
|
share.setShareLink(mServerBaseUri + sharingLinkPath + share.getToken());
|
||||||
@ -105,40 +104,36 @@ public class ShareToRemoteOperationResultParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result.setData(resultData);
|
result.setData(new ShareParserResult(resultData, ""));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
result = new RemoteOperationResult(RemoteOperationResult.ResultCode.WRONG_SERVER_RESPONSE);
|
result = new RemoteOperationResult<>(RemoteOperationResult.ResultCode.WRONG_SERVER_RESPONSE);
|
||||||
Log_OC.e(TAG, "Successful status with no share in the response");
|
Log_OC.e(TAG, "Successful status with no share in the response");
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (mShareXmlParser.isWrongParameter()){
|
} else if (mShareXmlParser.isWrongParameter()){
|
||||||
result = new RemoteOperationResult(RemoteOperationResult.ResultCode.SHARE_WRONG_PARAMETER);
|
result = new RemoteOperationResult<>(RemoteOperationResult.ResultCode.SHARE_WRONG_PARAMETER);
|
||||||
resultData.add(mShareXmlParser.getMessage());
|
result.setData(new ShareParserResult(null, mShareXmlParser.getMessage()));
|
||||||
result.setData(resultData);
|
|
||||||
|
|
||||||
} else if (mShareXmlParser.isNotFound()){
|
} else if (mShareXmlParser.isNotFound()){
|
||||||
result = new RemoteOperationResult(RemoteOperationResult.ResultCode.SHARE_NOT_FOUND);
|
result = new RemoteOperationResult<>(RemoteOperationResult.ResultCode.SHARE_NOT_FOUND);
|
||||||
resultData.add(mShareXmlParser.getMessage());
|
result.setData(new ShareParserResult(null, mShareXmlParser.getMessage()));
|
||||||
result.setData(resultData);
|
|
||||||
|
|
||||||
} else if (mShareXmlParser.isForbidden()) {
|
} else if (mShareXmlParser.isForbidden()) {
|
||||||
result = new RemoteOperationResult(RemoteOperationResult.ResultCode.SHARE_FORBIDDEN);
|
result = new RemoteOperationResult<>(RemoteOperationResult.ResultCode.SHARE_FORBIDDEN);
|
||||||
resultData.add(mShareXmlParser.getMessage());
|
result.setData(new ShareParserResult(null, mShareXmlParser.getMessage()));
|
||||||
result.setData(resultData);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
result = new RemoteOperationResult(RemoteOperationResult.ResultCode.WRONG_SERVER_RESPONSE);
|
result = new RemoteOperationResult<>(RemoteOperationResult.ResultCode.WRONG_SERVER_RESPONSE);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (XmlPullParserException e) {
|
} catch (XmlPullParserException e) {
|
||||||
Log_OC.e(TAG, "Error parsing response from server ", e);
|
Log_OC.e(TAG, "Error parsing response from server ", e);
|
||||||
result = new RemoteOperationResult(RemoteOperationResult.ResultCode.WRONG_SERVER_RESPONSE);
|
result = new RemoteOperationResult<>(RemoteOperationResult.ResultCode.WRONG_SERVER_RESPONSE);
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log_OC.e(TAG, "Error reading response from server ", e);
|
Log_OC.e(TAG, "Error reading response from server ", e);
|
||||||
result = new RemoteOperationResult(RemoteOperationResult.ResultCode.WRONG_SERVER_RESPONSE);
|
result = new RemoteOperationResult<>(RemoteOperationResult.ResultCode.WRONG_SERVER_RESPONSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -51,7 +51,7 @@ import okhttp3.FormBody;
|
|||||||
* @author David González Verdugo
|
* @author David González Verdugo
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class UpdateRemoteShareOperation extends RemoteOperation {
|
public class UpdateRemoteShareOperation extends RemoteOperation<ShareParserResult> {
|
||||||
|
|
||||||
private static final String TAG = GetRemoteShareOperation.class.getSimpleName();
|
private static final String TAG = GetRemoteShareOperation.class.getSimpleName();
|
||||||
|
|
||||||
@ -163,8 +163,8 @@ public class UpdateRemoteShareOperation extends RemoteOperation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected RemoteOperationResult run(OwnCloudClient client) {
|
protected RemoteOperationResult<ShareParserResult> run(OwnCloudClient client) {
|
||||||
RemoteOperationResult result;
|
RemoteOperationResult<ShareParserResult> result;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
FormBody.Builder formBodyBuilder = new FormBody.Builder();
|
FormBody.Builder formBodyBuilder = new FormBody.Builder();
|
||||||
@ -222,11 +222,11 @@ public class UpdateRemoteShareOperation extends RemoteOperation {
|
|||||||
result = parser.parse(putMethod.getResponseBodyAsString());
|
result = parser.parse(putMethod.getResponseBodyAsString());
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
result = new RemoteOperationResult(putMethod);
|
result = new RemoteOperationResult<>(putMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
result = new RemoteOperationResult(e);
|
result = new RemoteOperationResult<>(e);
|
||||||
Log_OC.e(TAG, "Exception while Creating New Share", e);
|
Log_OC.e(TAG, "Exception while Creating New Share", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +39,6 @@ import com.owncloud.android.lib.common.utils.Log_OC;
|
|||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import static com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.OK;
|
import static com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.OK;
|
||||||
|
|
||||||
@ -50,7 +49,7 @@ import static com.owncloud.android.lib.common.operations.RemoteOperationResult.R
|
|||||||
* @author masensio
|
* @author masensio
|
||||||
* @author David González Verdugo
|
* @author David González Verdugo
|
||||||
*/
|
*/
|
||||||
public class GetRemoteCapabilitiesOperation extends RemoteOperation {
|
public class GetRemoteCapabilitiesOperation extends RemoteOperation<OCCapability> {
|
||||||
|
|
||||||
private static final String TAG = GetRemoteCapabilitiesOperation.class.getSimpleName();
|
private static final String TAG = GetRemoteCapabilitiesOperation.class.getSimpleName();
|
||||||
|
|
||||||
@ -120,8 +119,8 @@ public class GetRemoteCapabilitiesOperation extends RemoteOperation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected RemoteOperationResult run(OwnCloudClient client) {
|
protected RemoteOperationResult<OCCapability> run(OwnCloudClient client) {
|
||||||
RemoteOperationResult result;
|
RemoteOperationResult<OCCapability> result;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Uri requestUri = client.getBaseUri();
|
Uri requestUri = client.getBaseUri();
|
||||||
@ -151,7 +150,6 @@ public class GetRemoteCapabilitiesOperation extends RemoteOperation {
|
|||||||
String message = respMeta.getString(PROPERTY_MESSAGE);
|
String message = respMeta.getString(PROPERTY_MESSAGE);
|
||||||
|
|
||||||
if (statusProp) {
|
if (statusProp) {
|
||||||
ArrayList<Object> data = new ArrayList<Object>(); // For result data
|
|
||||||
OCCapability capability = new OCCapability();
|
OCCapability capability = new OCCapability();
|
||||||
// Add Version
|
// Add Version
|
||||||
if (respData.has(NODE_VERSION)) {
|
if (respData.has(NODE_VERSION)) {
|
||||||
@ -257,19 +255,18 @@ public class GetRemoteCapabilitiesOperation extends RemoteOperation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Result
|
// Result
|
||||||
data.add(capability);
|
result = new RemoteOperationResult<>(OK);
|
||||||
result = new RemoteOperationResult(OK);
|
result.setData(capability);
|
||||||
result.setData(data);
|
|
||||||
|
|
||||||
Log_OC.d(TAG, "*** Get Capabilities completed ");
|
Log_OC.d(TAG, "*** Get Capabilities completed ");
|
||||||
} else {
|
} else {
|
||||||
result = new RemoteOperationResult(statuscode, message, null);
|
result = new RemoteOperationResult<>(statuscode, message, null);
|
||||||
Log_OC.e(TAG, "Failed response while getting capabilities from the server ");
|
Log_OC.e(TAG, "Failed response while getting capabilities from the server ");
|
||||||
Log_OC.e(TAG, "*** status: " + statusProp + "; message: " + message);
|
Log_OC.e(TAG, "*** status: " + statusProp + "; message: " + message);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
result = new RemoteOperationResult(getMethod);
|
result = new RemoteOperationResult<>(getMethod);
|
||||||
Log_OC.e(TAG, "Failed response while getting capabilities from the server ");
|
Log_OC.e(TAG, "Failed response while getting capabilities 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);
|
||||||
@ -279,7 +276,7 @@ public class GetRemoteCapabilitiesOperation extends RemoteOperation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
result = new RemoteOperationResult(e);
|
result = new RemoteOperationResult<>(e);
|
||||||
Log_OC.e(TAG, "Exception while getting capabilities", e);
|
Log_OC.e(TAG, "Exception while getting capabilities", e);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -39,7 +39,6 @@ import org.json.JSONException;
|
|||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import javax.net.ssl.SSLPeerUnverifiedException;
|
import javax.net.ssl.SSLPeerUnverifiedException;
|
||||||
@ -54,7 +53,7 @@ import static com.owncloud.android.lib.common.operations.RemoteOperationResult.R
|
|||||||
* @author David González Verdugo
|
* @author David González Verdugo
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class GetRemoteStatusOperation extends RemoteOperation {
|
public class GetRemoteStatusOperation extends RemoteOperation<OwnCloudVersion> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maximum time to wait for a response from the server when the connection is being tested,
|
* Maximum time to wait for a response from the server when the connection is being tested,
|
||||||
@ -69,7 +68,7 @@ public class GetRemoteStatusOperation extends RemoteOperation {
|
|||||||
private static final String HTTPS_PREFIX = "https://";
|
private static final String HTTPS_PREFIX = "https://";
|
||||||
private static final String HTTP_PREFIX = "http://";
|
private static final String HTTP_PREFIX = "http://";
|
||||||
|
|
||||||
private RemoteOperationResult mLatestResult;
|
private RemoteOperationResult<OwnCloudVersion> mLatestResult;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
|
||||||
public GetRemoteStatusOperation(Context context) {
|
public GetRemoteStatusOperation(Context context) {
|
||||||
@ -110,7 +109,7 @@ public class GetRemoteStatusOperation extends RemoteOperation {
|
|||||||
getMethod.setConnectionTimeout(TRY_CONNECTION_TIMEOUT, TimeUnit.SECONDS);
|
getMethod.setConnectionTimeout(TRY_CONNECTION_TIMEOUT, TimeUnit.SECONDS);
|
||||||
|
|
||||||
status = client.executeHttpMethod(getMethod);
|
status = client.executeHttpMethod(getMethod);
|
||||||
mLatestResult = new RemoteOperationResult(getMethod);
|
mLatestResult = new RemoteOperationResult<>(getMethod);
|
||||||
redirectedLocation = mLatestResult.getRedirectedLocation();
|
redirectedLocation = mLatestResult.getRedirectedLocation();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,7 +118,7 @@ public class GetRemoteStatusOperation extends RemoteOperation {
|
|||||||
JSONObject respJSON = new JSONObject(getMethod.getResponseBodyAsString());
|
JSONObject respJSON = new JSONObject(getMethod.getResponseBodyAsString());
|
||||||
if (!respJSON.getBoolean(NODE_INSTALLED)) {
|
if (!respJSON.getBoolean(NODE_INSTALLED)) {
|
||||||
mLatestResult = new RemoteOperationResult(
|
mLatestResult = new RemoteOperationResult(
|
||||||
RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED);
|
RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED);
|
||||||
} else {
|
} else {
|
||||||
String version = respJSON.getString(NODE_VERSION);
|
String version = respJSON.getString(NODE_VERSION);
|
||||||
OwnCloudVersion ocVersion = new OwnCloudVersion(version);
|
OwnCloudVersion ocVersion = new OwnCloudVersion(version);
|
||||||
@ -127,34 +126,30 @@ public class GetRemoteStatusOperation extends RemoteOperation {
|
|||||||
/// every app will decide how to act if (ocVersion.isVersionValid() == false)
|
/// every app will decide how to act if (ocVersion.isVersionValid() == false)
|
||||||
|
|
||||||
if (isRedirectToNonSecureConnection) {
|
if (isRedirectToNonSecureConnection) {
|
||||||
mLatestResult = new RemoteOperationResult(
|
mLatestResult = new RemoteOperationResult<>(
|
||||||
RemoteOperationResult.ResultCode.
|
RemoteOperationResult.ResultCode.
|
||||||
OK_REDIRECT_TO_NON_SECURE_CONNECTION
|
OK_REDIRECT_TO_NON_SECURE_CONNECTION);
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
mLatestResult = new RemoteOperationResult(
|
mLatestResult = new RemoteOperationResult<>(
|
||||||
baseUrlSt.startsWith(HTTPS_PREFIX) ?
|
baseUrlSt.startsWith(HTTPS_PREFIX) ?
|
||||||
RemoteOperationResult.ResultCode.OK_SSL :
|
RemoteOperationResult.ResultCode.OK_SSL :
|
||||||
RemoteOperationResult.ResultCode.OK_NO_SSL
|
RemoteOperationResult.ResultCode.OK_NO_SSL);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<Object> data = new ArrayList<>();
|
mLatestResult.setData(ocVersion);
|
||||||
data.add(ocVersion);
|
|
||||||
mLatestResult.setData(data);
|
|
||||||
retval = true;
|
retval = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
mLatestResult = new RemoteOperationResult(getMethod);
|
mLatestResult = new RemoteOperationResult<>(getMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
mLatestResult = new RemoteOperationResult(
|
mLatestResult = new RemoteOperationResult<>(
|
||||||
RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED);
|
RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
mLatestResult = new RemoteOperationResult(e);
|
mLatestResult = new RemoteOperationResult<>(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mLatestResult.isSuccess()) {
|
if (mLatestResult.isSuccess()) {
|
||||||
@ -179,9 +174,9 @@ public class GetRemoteStatusOperation extends RemoteOperation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected RemoteOperationResult run(OwnCloudClient client) {
|
protected RemoteOperationResult<OwnCloudVersion> run(OwnCloudClient client) {
|
||||||
if (!isOnline()) {
|
if (!isOnline()) {
|
||||||
return new RemoteOperationResult(RemoteOperationResult.ResultCode.NO_NETWORK_CONNECTION);
|
return new RemoteOperationResult<>(RemoteOperationResult.ResultCode.NO_NETWORK_CONNECTION);
|
||||||
}
|
}
|
||||||
String baseUriStr = client.getBaseUri().toString();
|
String baseUriStr = client.getBaseUri().toString();
|
||||||
if (baseUriStr.startsWith(HTTP_PREFIX) || baseUriStr.startsWith(HTTPS_PREFIX)) {
|
if (baseUriStr.startsWith(HTTP_PREFIX) || baseUriStr.startsWith(HTTPS_PREFIX)) {
|
||||||
|
@ -39,7 +39,6 @@ import java.io.ByteArrayOutputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import static com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.OK;
|
import static com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.OK;
|
||||||
|
|
||||||
@ -50,7 +49,7 @@ import static com.owncloud.android.lib.common.operations.RemoteOperationResult.R
|
|||||||
* @author David González Verdugo
|
* @author David González Verdugo
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class GetRemoteUserAvatarOperation extends RemoteOperation {
|
public class GetRemoteUserAvatarOperation extends RemoteOperation<GetRemoteUserAvatarOperation.ResultData> {
|
||||||
|
|
||||||
private static final String TAG = GetRemoteUserAvatarOperation.class.getSimpleName();
|
private static final String TAG = GetRemoteUserAvatarOperation.class.getSimpleName();
|
||||||
|
|
||||||
@ -73,9 +72,9 @@ public class GetRemoteUserAvatarOperation extends RemoteOperation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected RemoteOperationResult run(OwnCloudClient client) {
|
protected RemoteOperationResult<ResultData> run(OwnCloudClient client) {
|
||||||
GetMethod getMethod = null;
|
GetMethod getMethod = null;
|
||||||
RemoteOperationResult result;
|
RemoteOperationResult<ResultData> result;
|
||||||
InputStream inputStream = null;
|
InputStream inputStream = null;
|
||||||
BufferedInputStream bis = null;
|
BufferedInputStream bis = null;
|
||||||
ByteArrayOutputStream bos = null;
|
ByteArrayOutputStream bos = null;
|
||||||
@ -107,9 +106,7 @@ public class GetRemoteUserAvatarOperation extends RemoteOperation {
|
|||||||
Log_OC.e(
|
Log_OC.e(
|
||||||
TAG, "Not an image, failing with no avatar"
|
TAG, "Not an image, failing with no avatar"
|
||||||
);
|
);
|
||||||
result = new RemoteOperationResult(
|
result = new RemoteOperationResult<>(RemoteOperationResult.ResultCode.FILE_NOT_FOUND);
|
||||||
RemoteOperationResult.ResultCode.FILE_NOT_FOUND
|
|
||||||
);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,19 +133,16 @@ public class GetRemoteUserAvatarOperation extends RemoteOperation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Result
|
// Result
|
||||||
result = new RemoteOperationResult(OK);
|
result = new RemoteOperationResult<>(OK);
|
||||||
ResultData resultData = new ResultData(bos.toByteArray(), mimeType, etag);
|
result.setData(new ResultData(bos.toByteArray(), mimeType, etag));
|
||||||
ArrayList<Object> data = new ArrayList<Object>();
|
|
||||||
data.add(resultData);
|
|
||||||
result.setData(data);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
result = new RemoteOperationResult(getMethod);
|
result = new RemoteOperationResult<>(getMethod);
|
||||||
client.exhaustResponse(getMethod.getResponseAsStream());
|
client.exhaustResponse(getMethod.getResponseAsStream());
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
result = new RemoteOperationResult(e);
|
result = new RemoteOperationResult<>(e);
|
||||||
Log_OC.e(TAG, "Exception while getting OC user avatar", e);
|
Log_OC.e(TAG, "Exception while getting OC user avatar", e);
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -34,7 +34,6 @@ import com.owncloud.android.lib.common.utils.Log_OC;
|
|||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
|
|
||||||
@ -67,8 +66,8 @@ public class GetRemoteUserInfoOperation extends RemoteOperation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected RemoteOperationResult run(OwnCloudClient client) {
|
protected RemoteOperationResult<UserInfo> run(OwnCloudClient client) {
|
||||||
RemoteOperationResult result;
|
RemoteOperationResult<UserInfo> result;
|
||||||
|
|
||||||
//Get the user
|
//Get the user
|
||||||
try {
|
try {
|
||||||
@ -93,14 +92,12 @@ public class GetRemoteUserInfoOperation extends RemoteOperation {
|
|||||||
userInfo.mDisplayName = respData.getString(NODE_DISPLAY_NAME);
|
userInfo.mDisplayName = respData.getString(NODE_DISPLAY_NAME);
|
||||||
userInfo.mEmail = respData.getString(NODE_EMAIL);
|
userInfo.mEmail = respData.getString(NODE_EMAIL);
|
||||||
|
|
||||||
result = new RemoteOperationResult(OK);
|
result = new RemoteOperationResult<>(OK);
|
||||||
|
|
||||||
ArrayList<Object> data = new ArrayList<>();
|
result.setData(userInfo);
|
||||||
data.add(userInfo);
|
|
||||||
result.setData(data);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
result = new RemoteOperationResult(getMethod);
|
result = new RemoteOperationResult<>(getMethod);
|
||||||
String response = getMethod.getResponseBodyAsString();
|
String response = getMethod.getResponseBodyAsString();
|
||||||
Log_OC.e(TAG, "Failed response while getting user information ");
|
Log_OC.e(TAG, "Failed response while getting user information ");
|
||||||
if (getMethod != null) {
|
if (getMethod != null) {
|
||||||
@ -110,7 +107,7 @@ public class GetRemoteUserInfoOperation extends RemoteOperation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
result = new RemoteOperationResult(e);
|
result = new RemoteOperationResult<>(e);
|
||||||
Log_OC.e(TAG, "Exception while getting OC user information", e);
|
Log_OC.e(TAG, "Exception while getting OC user information", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,6 @@ 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 java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import at.bitfire.dav4android.PropertyCollection;
|
import at.bitfire.dav4android.PropertyCollection;
|
||||||
import at.bitfire.dav4android.property.QuotaAvailableBytes;
|
import at.bitfire.dav4android.property.QuotaAvailableBytes;
|
||||||
@ -50,7 +49,7 @@ import static com.owncloud.android.lib.common.operations.RemoteOperationResult.R
|
|||||||
* @author marcello
|
* @author marcello
|
||||||
* @author David González Verdugo
|
* @author David González Verdugo
|
||||||
*/
|
*/
|
||||||
public class GetRemoteUserQuotaOperation extends RemoteOperation {
|
public class GetRemoteUserQuotaOperation extends RemoteOperation<GetRemoteUserQuotaOperation.RemoteQuota> {
|
||||||
|
|
||||||
static public class RemoteQuota {
|
static public class RemoteQuota {
|
||||||
|
|
||||||
@ -84,8 +83,8 @@ public class GetRemoteUserQuotaOperation extends RemoteOperation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected RemoteOperationResult run(OwnCloudClient client) {
|
protected RemoteOperationResult<RemoteQuota> run(OwnCloudClient client) {
|
||||||
RemoteOperationResult result = null;
|
RemoteOperationResult<RemoteQuota> result = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
PropfindMethod propfindMethod = new PropfindMethod(
|
PropfindMethod propfindMethod = new PropfindMethod(
|
||||||
@ -99,22 +98,19 @@ public class GetRemoteUserQuotaOperation extends RemoteOperation {
|
|||||||
if (isSuccess(status)) {
|
if (isSuccess(status)) {
|
||||||
RemoteQuota remoteQuota = readData(propfindMethod.getDavResource().getProperties());
|
RemoteQuota remoteQuota = readData(propfindMethod.getDavResource().getProperties());
|
||||||
|
|
||||||
result = new RemoteOperationResult(OK);
|
result = new RemoteOperationResult<>(OK);
|
||||||
|
|
||||||
ArrayList<Object> data = new ArrayList<>();
|
|
||||||
data.add(remoteQuota);
|
|
||||||
|
|
||||||
// Add data to the result
|
// Add data to the result
|
||||||
if (result.isSuccess()) {
|
if (result.isSuccess()) {
|
||||||
result.setData(data);
|
result.setData(remoteQuota);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else { // synchronization failed
|
} else { // synchronization failed
|
||||||
result = new RemoteOperationResult(propfindMethod);
|
result = new RemoteOperationResult<>(propfindMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
result = new RemoteOperationResult(e);
|
result = new RemoteOperationResult<>(e);
|
||||||
|
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user