mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-10-31 10:27:45 +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.authentication.OwnCloudCredentials; | ||||
| 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.RemoteOperationResult; | ||||
| import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; | ||||
| 
 | ||||
| import org.json.JSONObject; | ||||
| 
 | ||||
| import java.net.URL; | ||||
| import java.util.ArrayList; | ||||
| import java.util.Map; | ||||
| 
 | ||||
| import okhttp3.HttpUrl; | ||||
| import okhttp3.MultipartBody; | ||||
| import okhttp3.RequestBody; | ||||
| 
 | ||||
| 
 | ||||
| public class OAuth2GetAccessTokenOperation extends RemoteOperation { | ||||
| public class OAuth2GetAccessTokenOperation extends RemoteOperation<Map<String, String>> { | ||||
|      | ||||
|     private String mGrantType; | ||||
|     private String mCode; | ||||
| @ -84,7 +82,7 @@ public class OAuth2GetAccessTokenOperation extends RemoteOperation { | ||||
| 
 | ||||
|     @Override | ||||
|     protected RemoteOperationResult run(OwnCloudClient client) { | ||||
|         RemoteOperationResult result = null; | ||||
|         RemoteOperationResult<Map<String, String>> result = null; | ||||
|          | ||||
|         try { | ||||
| 
 | ||||
| @ -122,22 +120,20 @@ public class OAuth2GetAccessTokenOperation extends RemoteOperation { | ||||
|                     mResponseParser.parseAccessTokenResult(tokenJson); | ||||
|                 if (accessTokenResult.get(OAuth2Constants.KEY_ERROR) != null || | ||||
|                         accessTokenResult.get(OAuth2Constants.KEY_ACCESS_TOKEN) == null) { | ||||
|                     result = new RemoteOperationResult(ResultCode.OAUTH2_ERROR); | ||||
|                     result = new RemoteOperationResult<>(ResultCode.OAUTH2_ERROR); | ||||
| 
 | ||||
|                 } else { | ||||
|                     result = new RemoteOperationResult(ResultCode.OK); | ||||
|                     ArrayList<Object> data = new ArrayList<>(); | ||||
|                     data.add(accessTokenResult); | ||||
|                     result.setData(data); | ||||
|                     result = new RemoteOperationResult<>(ResultCode.OK); | ||||
|                     result.setData(accessTokenResult); | ||||
|                 } | ||||
| 
 | ||||
|             } else { | ||||
|                 result = new RemoteOperationResult(ResultCode.OK); | ||||
|                 result = new RemoteOperationResult<>(ResultCode.OK); | ||||
|                 client.exhaustResponse(postMethod.getResponseAsStream()); | ||||
|             } | ||||
| 
 | ||||
|         } catch (Exception e) { | ||||
|             result = new RemoteOperationResult(e); | ||||
|             result = new RemoteOperationResult<>(e); | ||||
|              | ||||
|         } | ||||
|         return result; | ||||
|  | ||||
| @ -26,24 +26,22 @@ import android.net.Uri; | ||||
| import com.owncloud.android.lib.common.authentication.OwnCloudBasicCredentials; | ||||
| import com.owncloud.android.lib.common.OwnCloudClient; | ||||
| 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.RemoteOperationResult; | ||||
| import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; | ||||
| import com.owncloud.android.lib.common.utils.Log_OC; | ||||
| 
 | ||||
| import org.json.JSONObject; | ||||
| 
 | ||||
| import java.net.URL; | ||||
| import java.util.ArrayList; | ||||
| import java.util.Map; | ||||
| 
 | ||||
| import com.owncloud.android.lib.common.http.methods.nonwebdav.PostMethod; | ||||
| 
 | ||||
| import okhttp3.HttpUrl; | ||||
| import okhttp3.MultipartBody; | ||||
| import okhttp3.RequestBody; | ||||
| 
 | ||||
| public class OAuth2RefreshAccessTokenOperation extends RemoteOperation { | ||||
| public class OAuth2RefreshAccessTokenOperation extends RemoteOperation<Map<String, String>> { | ||||
| 
 | ||||
|     private static final String TAG = OAuth2RefreshAccessTokenOperation.class.getSimpleName(); | ||||
| 
 | ||||
| @ -76,7 +74,7 @@ public class OAuth2RefreshAccessTokenOperation extends RemoteOperation { | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     protected RemoteOperationResult run(OwnCloudClient client) { | ||||
|     protected RemoteOperationResult<Map<String, String>> run(OwnCloudClient client) { | ||||
| 
 | ||||
|         try { | ||||
| 
 | ||||
| @ -115,21 +113,20 @@ public class OAuth2RefreshAccessTokenOperation extends RemoteOperation { | ||||
| 
 | ||||
|                 final Map<String, String> accessTokenResult = | ||||
|                         mResponseParser.parseAccessTokenResult(tokenJson); | ||||
|                 final ArrayList<Object> resultData = new ArrayList<>(1); | ||||
|                 resultData.add(accessTokenResult); | ||||
|                 final RemoteOperationResult result = new RemoteOperationResult(ResultCode.OK); | ||||
|                 result.setData(resultData); | ||||
| 
 | ||||
|                 final RemoteOperationResult<Map<String, String>> result = new RemoteOperationResult<>(ResultCode.OK); | ||||
|                 result.setData(accessTokenResult); | ||||
|                 return (accessTokenResult.get(OAuth2Constants.KEY_ERROR) != null || | ||||
|                         accessTokenResult.get(OAuth2Constants.KEY_ACCESS_TOKEN) == null) | ||||
|                         ? new RemoteOperationResult(ResultCode.OAUTH2_ERROR) | ||||
|                         ? new RemoteOperationResult<>(ResultCode.OAUTH2_ERROR) | ||||
|                         : result; | ||||
| 
 | ||||
|             } else { | ||||
|                 return new RemoteOperationResult(postMethod); | ||||
|                 return new RemoteOperationResult<>(postMethod); | ||||
|             } | ||||
| 
 | ||||
|         } 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 | ||||
|  * {@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. | ||||
|  * | ||||
|  * 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; | ||||
| 
 | ||||
| import android.accounts.Account; | ||||
| @ -41,16 +17,7 @@ import java.io.IOException; | ||||
| 
 | ||||
| import okhttp3.OkHttpClient; | ||||
| 
 | ||||
| 
 | ||||
| /** | ||||
|  * 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 { | ||||
| public abstract class RemoteOperation<T extends Object> implements Runnable { | ||||
| 
 | ||||
|     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 | ||||
|      */ | ||||
|     private Account mAccount = null; | ||||
|     protected Account mAccount = null; | ||||
| 
 | ||||
|     /** | ||||
|      * Android Application context | ||||
|      */ | ||||
|     private Context mContext = null; | ||||
|     protected Context mContext = null; | ||||
| 
 | ||||
|     /** | ||||
|      * Object to interact with the remote server | ||||
|      */ | ||||
|     private OwnCloudClient mClient = null; | ||||
|     protected OwnCloudClient mClient = null; | ||||
| 
 | ||||
|     /** | ||||
|      * 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 | ||||
|      */ | ||||
|     private OnRemoteOperationListener mListener = null; | ||||
|     protected OnRemoteOperationListener mListener = null; | ||||
| 
 | ||||
|     /** | ||||
|      * Handler to the thread where mListener methods will be called | ||||
|      */ | ||||
|     private 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(); | ||||
|     } | ||||
|     protected Handler mListenerHandler = null; | ||||
| 
 | ||||
| 
 | ||||
|     /** | ||||
| @ -245,62 +138,7 @@ public abstract class RemoteOperation implements Runnable { | ||||
|         return runnerThread; | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     /** | ||||
|      * Asynchronous execution of the operation | ||||
|      * started by {@link RemoteOperation#execute(OwnCloudClient, | ||||
|      * OnRemoteOperationListener, Handler)}, | ||||
|      * and result posting. | ||||
|      */ | ||||
|     @Override | ||||
|     public final void run() { | ||||
| 
 | ||||
|         final RemoteOperationResult resultToSend = runOperation(); | ||||
| 
 | ||||
|         if (mAccount != null && mContext != null) { | ||||
|             // Save Client Cookies | ||||
|             AccountUtils.saveClient(mClient, mAccount, mContext); | ||||
|         } | ||||
| 
 | ||||
|         if (mListenerHandler != null && mListener != null) { | ||||
|             mListenerHandler.post(new Runnable() { | ||||
|                 @Override | ||||
|                 public void run() { | ||||
|                     mListener.onRemoteOperationFinish(RemoteOperation.this, resultToSend); | ||||
|                 } | ||||
|             }); | ||||
|         } else if (mListener != null) { | ||||
|             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 | ||||
|     protected void grantOwnCloudClient() throws | ||||
|             AccountUtils.AccountNotFoundException, OperationCanceledException, AuthenticatorException, IOException { | ||||
|         if (mClient == null) { | ||||
|             if (mAccount != null && mContext != null) { | ||||
| @ -324,4 +162,126 @@ public abstract class RemoteOperation implements Runnable { | ||||
|         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 | ||||
|      * started by {@link RemoteOperation#execute(OwnCloudClient, | ||||
|      * OnRemoteOperationListener, Handler)}, | ||||
|      * and result posting. | ||||
|      */ | ||||
|     @Override | ||||
|     public final void run() { | ||||
| 
 | ||||
|         final RemoteOperationResult resultToSend = runOperation(); | ||||
| 
 | ||||
|         if (mAccount != null && mContext != null) { | ||||
|             // Save Client Cookies | ||||
|             AccountUtils.saveClient(mClient, mAccount, mContext); | ||||
|         } | ||||
| 
 | ||||
|         if (mListenerHandler != null && mListener != null) { | ||||
|             mListenerHandler.post(() -> | ||||
|                     mListener.onRemoteOperationFinish(RemoteOperation.this, resultToSend)); | ||||
|         } else if (mListener != null) { | ||||
|             mListener.onRemoteOperationFinish(RemoteOperation.this, resultToSend); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
| } | ||||
| @ -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; | ||||
| 
 | ||||
| import android.accounts.Account; | ||||
| 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.methods.HttpBaseMethod; | ||||
| 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 okhttp3.Headers; | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| /** | ||||
|  * 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 { | ||||
| public class RemoteOperationResult<T extends Object> | ||||
|         implements Serializable { | ||||
| 
 | ||||
|     /** | ||||
|      * Generated - should be refreshed every time the class changes!! | ||||
| @ -139,8 +102,7 @@ public class RemoteOperationResult implements Serializable { | ||||
|     private String mRedirectedLocation; | ||||
|     private ArrayList<String> mAuthenticate = new ArrayList<>(); | ||||
|     private String mLastPermanentLocation = null; | ||||
| 
 | ||||
|     private ArrayList<Object> mData; | ||||
|     private T mData = null; | ||||
| 
 | ||||
|     /** | ||||
|      * Public constructor from result code. | ||||
| @ -154,7 +116,6 @@ public class RemoteOperationResult implements Serializable { | ||||
|         mSuccess = (code == ResultCode.OK || code == ResultCode.OK_SSL || | ||||
|                 code == ResultCode.OK_NO_SSL || | ||||
|                 code == ResultCode.OK_REDIRECT_TO_NON_SECURE_CONNECTION); | ||||
|         mData = null; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
| @ -184,7 +145,7 @@ public class RemoteOperationResult implements Serializable { | ||||
|         } else if (e instanceof UnknownHostException) { | ||||
|             mCode = ResultCode.HOST_NOT_AVAILABLE; | ||||
| 
 | ||||
|         } else if (e instanceof AccountNotFoundException) { | ||||
|         } else if (e instanceof AccountUtils.AccountNotFoundException) { | ||||
|             mCode = ResultCode.ACCOUNT_NOT_FOUND; | ||||
| 
 | ||||
|         } else if (e instanceof AccountsException) { | ||||
| @ -332,7 +293,7 @@ public class RemoteOperationResult implements Serializable { | ||||
|         } | ||||
|         if (isIdPRedirection()) { | ||||
|             // 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() { | ||||
|         return mSuccess; | ||||
| @ -476,9 +430,9 @@ public class RemoteOperationResult implements Serializable { | ||||
|             } else if (mException instanceof IOException) { | ||||
|                 return "Unrecovered transport exception"; | ||||
| 
 | ||||
|             } else if (mException instanceof AccountNotFoundException) { | ||||
|             } else if (mException instanceof AccountUtils.AccountNotFoundException) { | ||||
|                 Account failedAccount = | ||||
|                         ((AccountNotFoundException) mException).getFailedAccount(); | ||||
|                         ((AccountUtils.AccountNotFoundException) mException).getFailedAccount(); | ||||
|                 return mException.getMessage() + " (" + | ||||
|                         (failedAccount != null ? failedAccount.name : "NULL") + ")"; | ||||
| 
 | ||||
| @ -575,4 +529,12 @@ public class RemoteOperationResult implements Serializable { | ||||
|     public void setSuccess(boolean 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.methods.webdav.CopyMethod; | ||||
| 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.RemoteOperationResult; | ||||
| import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; | ||||
| import com.owncloud.android.lib.resources.status.OwnCloudVersion; | ||||
| 
 | ||||
| import java.net.URL; | ||||
| import java.util.concurrent.TimeUnit; | ||||
| 
 | ||||
| import okhttp3.HttpUrl; | ||||
| 
 | ||||
| /** | ||||
|  * Remote operation moving a remote file or folder in the ownCloud server to a different folder | ||||
|  * in the same account. | ||||
| @ -89,16 +87,16 @@ public class CopyRemoteFileOperation extends RemoteOperation { | ||||
| 
 | ||||
|         /// check parameters | ||||
|         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)) { | ||||
|             // nothing to do! | ||||
|             return new RemoteOperationResult(ResultCode.OK); | ||||
|             return new RemoteOperationResult<>(ResultCode.OK); | ||||
|         } | ||||
| 
 | ||||
|         if (mTargetRemotePath.startsWith(mSrcRemotePath)) { | ||||
|             return new RemoteOperationResult(ResultCode.INVALID_COPY_INTO_DESCENDANT); | ||||
|             return new RemoteOperationResult<>(ResultCode.INVALID_COPY_INTO_DESCENDANT); | ||||
|         } | ||||
| 
 | ||||
|         /// perform remote operation | ||||
| @ -114,10 +112,10 @@ public class CopyRemoteFileOperation extends RemoteOperation { | ||||
|             final int status = client.executeHttpMethod(copyMethod); | ||||
| 
 | ||||
|             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) { | ||||
| 
 | ||||
|                 result = new RemoteOperationResult(ResultCode.INVALID_OVERWRITE); | ||||
|                 result = new RemoteOperationResult<>(ResultCode.INVALID_OVERWRITE); | ||||
|                 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 | ||||
| 
 | ||||
|             } else { | ||||
|                 result = new RemoteOperationResult(copyMethod); | ||||
|                 result = new RemoteOperationResult<>(copyMethod); | ||||
|                 client.exhaustResponse(copyMethod.getResponseAsStream()); | ||||
|             } | ||||
| 
 | ||||
| @ -133,7 +131,7 @@ public class CopyRemoteFileOperation extends RemoteOperation { | ||||
|                     result.getLogMessage()); | ||||
| 
 | ||||
|         } catch (Exception e) { | ||||
|             result = new RemoteOperationResult(e); | ||||
|             result = new RemoteOperationResult<>(e); | ||||
|             Log.e(TAG, "Copy " + mSrcRemotePath + " to " + mTargetRemotePath + ": " + | ||||
|                     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.methods.webdav.MkColMethod; | ||||
| 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.RemoteOperationResult; | ||||
| import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; | ||||
| import com.owncloud.android.lib.common.utils.Log_OC; | ||||
| import com.owncloud.android.lib.resources.status.OwnCloudVersion; | ||||
| 
 | ||||
| import java.net.URL; | ||||
| import java.util.concurrent.TimeUnit; | ||||
| 
 | ||||
| import okhttp3.HttpUrl; | ||||
| 
 | ||||
| 
 | ||||
| /** | ||||
|  * Remote operation performing the creation of a new folder in the ownCloud server. | ||||
| @ -94,7 +92,7 @@ public class CreateRemoteFolderOperation extends RemoteOperation { | ||||
|             } | ||||
| 
 | ||||
|         } else { | ||||
|             result = new RemoteOperationResult(ResultCode.INVALID_CHARACTER_IN_NAME); | ||||
|             result = new RemoteOperationResult<>(ResultCode.INVALID_CHARACTER_IN_NAME); | ||||
|         } | ||||
| 
 | ||||
|         return result; | ||||
| @ -111,13 +109,13 @@ public class CreateRemoteFolderOperation extends RemoteOperation { | ||||
|             final int status = client.executeHttpMethod(mkcol); | ||||
| 
 | ||||
|             result = (status == HttpConstants.HTTP_CREATED) | ||||
|                     ? new RemoteOperationResult(ResultCode.OK) | ||||
|                     : new RemoteOperationResult(mkcol); | ||||
|                     ? new RemoteOperationResult<>(ResultCode.OK) | ||||
|                     : new RemoteOperationResult<>(mkcol); | ||||
|             Log_OC.d(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage()); | ||||
|             client.exhaustResponse(mkcol.getResponseAsStream()); | ||||
| 
 | ||||
|         } catch (Exception e) { | ||||
|             result = new RemoteOperationResult(e); | ||||
|             result = new RemoteOperationResult<>(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.concurrent.atomic.AtomicBoolean; | ||||
| 
 | ||||
| import okhttp3.HttpUrl; | ||||
| 
 | ||||
| /** | ||||
|  * Remote operation performing the download of a remote file in the ownCloud server. | ||||
|  * | ||||
| @ -88,7 +86,7 @@ public class DownloadRemoteFileOperation extends RemoteOperation { | ||||
|                 result.getLogMessage()); | ||||
| 
 | ||||
|         } catch (Exception e) { | ||||
|             result = new RemoteOperationResult(e); | ||||
|             result = new RemoteOperationResult<>(e); | ||||
|             Log_OC.e(TAG, "Download of " + mRemotePath + " to " + getTmpPath() + ": " + | ||||
|                 result.getLogMessage(), e); | ||||
|         } | ||||
| @ -172,8 +170,8 @@ public class DownloadRemoteFileOperation extends RemoteOperation { | ||||
|             } // else, body read by RemoteOperationResult constructor | ||||
| 
 | ||||
|             result = isSuccess(status) | ||||
|                     ? new RemoteOperationResult(RemoteOperationResult.ResultCode.OK) | ||||
|                     : new RemoteOperationResult(mGet); | ||||
|                     ? new RemoteOperationResult<>(RemoteOperationResult.ResultCode.OK) | ||||
|                     : new RemoteOperationResult<>(mGet); | ||||
|         } finally { | ||||
|             if (fos != null) fos.close(); | ||||
|             if (bis != null) bis.close(); | ||||
|  | ||||
| @ -102,19 +102,17 @@ public class ExistenceCheckRemoteOperation extends RemoteOperation { | ||||
|                     "finished with HTTP status " + status + (!isSuccess(status) ? "(FAIL)" : "")); | ||||
| 
 | ||||
|             return isSuccess(status) | ||||
|                     ? new RemoteOperationResult(OK) | ||||
|                     : new RemoteOperationResult(propfindMethod); | ||||
|                     ? new RemoteOperationResult<>(OK) | ||||
|                     : new RemoteOperationResult<>(propfindMethod); | ||||
| 
 | ||||
|         } catch (Exception e) { | ||||
|             final RemoteOperationResult result = new RemoteOperationResult(e); | ||||
|             final RemoteOperationResult result = new RemoteOperationResult<>(e); | ||||
|             Log_OC.e(TAG, "Existence check for " + client.getNewFilesWebDavUri() + | ||||
|                     WebdavUtils.encodePath(mPath) + " targeting for " + | ||||
|                     (mSuccessIfAbsent ? " absence " : " existence ") + ": " + | ||||
|                     result.getLogMessage(), result.getException()); | ||||
|             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.methods.webdav.MoveMethod; | ||||
| 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.RemoteOperationResult; | ||||
| import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; | ||||
| import com.owncloud.android.lib.resources.status.OwnCloudVersion; | ||||
| 
 | ||||
| import java.net.URL; | ||||
| import java.util.concurrent.TimeUnit; | ||||
| 
 | ||||
| import okhttp3.HttpUrl; | ||||
| 
 | ||||
| /** | ||||
|  * Remote operation moving a remote file or folder in the ownCloud server to a different folder | ||||
|  * in the same account. | ||||
| @ -96,16 +94,16 @@ public class MoveRemoteFileOperation extends RemoteOperation { | ||||
| 
 | ||||
|         /// check parameters | ||||
|         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)) { | ||||
|             // nothing to do! | ||||
|             return new RemoteOperationResult(ResultCode.OK); | ||||
|             return new RemoteOperationResult<>(ResultCode.OK); | ||||
|         } | ||||
| 
 | ||||
|         if (mTargetRemotePath.startsWith(mSrcRemotePath)) { | ||||
|             return new RemoteOperationResult(ResultCode.INVALID_MOVE_INTO_DESCENDANT); | ||||
|             return new RemoteOperationResult<>(ResultCode.INVALID_MOVE_INTO_DESCENDANT); | ||||
|         } | ||||
| 
 | ||||
|         /// perform remote operation | ||||
| @ -132,17 +130,17 @@ public class MoveRemoteFileOperation extends RemoteOperation { | ||||
|             final int status = client.executeHttpMethod(move); | ||||
|             /// process response | ||||
|             if(isSuccess(status)) { | ||||
|                 result = new RemoteOperationResult(ResultCode.OK); | ||||
|                 result = new RemoteOperationResult<>(ResultCode.OK); | ||||
|             } else if (status == HttpConstants.HTTP_PRECONDITION_FAILED && !mOverwrite) { | ||||
| 
 | ||||
|                 result = new RemoteOperationResult(ResultCode.INVALID_OVERWRITE); | ||||
|                 result = new RemoteOperationResult<>(ResultCode.INVALID_OVERWRITE); | ||||
|                 client.exhaustResponse(move.getResponseAsStream()); | ||||
| 
 | ||||
|                 /// for other errors that could be explicitly handled, check first: | ||||
|                 /// http://www.webdav.org/specs/rfc4918.html#rfc.section.9.9.4 | ||||
| 
 | ||||
|             } else { | ||||
|                 result = new RemoteOperationResult(move); | ||||
|                 result = new RemoteOperationResult<>(move); | ||||
|                 client.exhaustResponse(move.getResponseAsStream()); | ||||
|             } | ||||
| 
 | ||||
| @ -150,7 +148,7 @@ public class MoveRemoteFileOperation extends RemoteOperation { | ||||
|                 result.getLogMessage()); | ||||
| 
 | ||||
|         } catch (Exception e) { | ||||
|             result = new RemoteOperationResult(e); | ||||
|             result = new RemoteOperationResult<>(e); | ||||
|             Log.e(TAG, "Move " + mSrcRemotePath + " to " + mTargetRemotePath + ": " + | ||||
|                 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 java.net.URL; | ||||
| import java.util.ArrayList; | ||||
| import java.util.concurrent.TimeUnit; | ||||
| 
 | ||||
| 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.operations.RemoteOperationResult.ResultCode.OK; | ||||
| @ -49,7 +47,7 @@ import static com.owncloud.android.lib.common.operations.RemoteOperationResult.R | ||||
|  * @author masensio | ||||
|  */ | ||||
| 
 | ||||
| public class ReadRemoteFileOperation extends RemoteOperation { | ||||
| public class ReadRemoteFileOperation extends RemoteOperation<RemoteFile> { | ||||
| 
 | ||||
|     private static final String TAG = ReadRemoteFileOperation.class.getSimpleName(); | ||||
|     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. | ||||
|      */ | ||||
|     @Override | ||||
|     protected RemoteOperationResult run(OwnCloudClient client) { | ||||
|     protected RemoteOperationResult<RemoteFile> run(OwnCloudClient client) { | ||||
|         PropfindMethod propfind; | ||||
|         RemoteOperationResult result; | ||||
|         RemoteOperationResult<RemoteFile> result; | ||||
| 
 | ||||
|         /// take the duty of check the server for the current state of the file there | ||||
|         try { | ||||
| @ -94,19 +92,16 @@ public class ReadRemoteFileOperation extends RemoteOperation { | ||||
| 
 | ||||
|                 final RemoteFile file = new RemoteFile(resource, client.getAccount().getDisplayName()); | ||||
| 
 | ||||
|                 ArrayList<Object> files = new ArrayList<>(); | ||||
|                 files.add(file); | ||||
| 
 | ||||
|                 result = new RemoteOperationResult(OK); | ||||
|                 result.setData(files); | ||||
|                 result = new RemoteOperationResult<>(OK); | ||||
|                 result.setData(file); | ||||
| 
 | ||||
|             } else { | ||||
|                 result = new RemoteOperationResult(propfind); | ||||
|                 result = new RemoteOperationResult<>(propfind); | ||||
|                 client.exhaustResponse(propfind.getResponseAsStream()); | ||||
|             } | ||||
| 
 | ||||
|         } catch (Exception e) { | ||||
|             result = new RemoteOperationResult(e); | ||||
|             result = new RemoteOperationResult<>(e); | ||||
|             e.printStackTrace(); | ||||
|             Log_OC.e(TAG, "Synchronizing  file " + mRemotePath + ": " + result.getLogMessage(), | ||||
|                 result.getException()); | ||||
|  | ||||
| @ -49,7 +49,7 @@ import static com.owncloud.android.lib.common.operations.RemoteOperationResult.R | ||||
|  * @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(); | ||||
| 
 | ||||
| @ -70,8 +70,8 @@ public class ReadRemoteFolderOperation extends RemoteOperation { | ||||
|      * @param client Client object to communicate with the remote ownCloud server. | ||||
|      */ | ||||
|     @Override | ||||
|     protected RemoteOperationResult run(OwnCloudClient client) { | ||||
|         RemoteOperationResult result = null; | ||||
|     protected RemoteOperationResult<ArrayList<RemoteFile>> run(OwnCloudClient client) { | ||||
|         RemoteOperationResult<ArrayList<RemoteFile>> result = null; | ||||
| 
 | ||||
|         try { | ||||
|             PropfindMethod propfindMethod = new PropfindMethod( | ||||
| @ -84,7 +84,7 @@ public class ReadRemoteFolderOperation extends RemoteOperation { | ||||
|             int status = client.executeHttpMethod(propfindMethod); | ||||
| 
 | ||||
|             if (isSuccess(status)) { | ||||
|                 ArrayList<Object> mFolderAndFiles = new ArrayList<>(); | ||||
|                 ArrayList<RemoteFile> mFolderAndFiles = new ArrayList<>(); | ||||
| 
 | ||||
|                 // parse data from remote folder | ||||
|                 mFolderAndFiles.add( | ||||
| @ -98,15 +98,15 @@ public class ReadRemoteFolderOperation extends RemoteOperation { | ||||
|                 } | ||||
| 
 | ||||
|                 // Result of the operation | ||||
|                 result = new RemoteOperationResult(OK); | ||||
|                 result = new RemoteOperationResult<>(OK); | ||||
|                 result.setData(mFolderAndFiles); | ||||
| 
 | ||||
|             } else { // synchronization failed | ||||
|                 result = new RemoteOperationResult(propfindMethod); | ||||
|                 result = new RemoteOperationResult<> (propfindMethod); | ||||
|             } | ||||
| 
 | ||||
|         } catch (Exception e) { | ||||
|             result = new RemoteOperationResult(e); | ||||
|             result = new RemoteOperationResult<>(e); | ||||
|         } finally { | ||||
|             if (result.isSuccess()) { | ||||
|                 Log_OC.i(TAG, "Synchronized " + mRemotePath + ": " + result.getLogMessage()); | ||||
|  | ||||
| @ -78,13 +78,13 @@ public class RemoveRemoteFileOperation extends RemoteOperation { | ||||
|             int status = client.executeHttpMethod(deleteMethod); | ||||
| 
 | ||||
|             result = isSuccess(status) ? | ||||
|                     new RemoteOperationResult(OK) : | ||||
|                     new RemoteOperationResult(deleteMethod); | ||||
|                     new RemoteOperationResult<>(OK) : | ||||
|                     new RemoteOperationResult<>(deleteMethod); | ||||
| 
 | ||||
|             Log_OC.i(TAG, "Remove " + mRemotePath + ": " + result.getLogMessage()); | ||||
| 
 | ||||
|         } catch (Exception e) { | ||||
|             result = new RemoteOperationResult(e); | ||||
|             result = new RemoteOperationResult<>(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.methods.webdav.MoveMethod; | ||||
| 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.RemoteOperationResult; | ||||
| import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; | ||||
| import com.owncloud.android.lib.common.utils.Log_OC; | ||||
| 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. | ||||
| @ -96,15 +94,15 @@ public class RenameRemoteFileOperation extends RemoteOperation { | ||||
|             (version != null && version.isVersionWithForbiddenCharacters()); | ||||
| 
 | ||||
|         if(!FileUtils.isValidPath(mNewRemotePath, versionWithForbiddenChars)) | ||||
|             return new RemoteOperationResult(ResultCode.INVALID_CHARACTER_IN_NAME); | ||||
|             return new RemoteOperationResult<>(ResultCode.INVALID_CHARACTER_IN_NAME); | ||||
| 
 | ||||
|         try { | ||||
|             if (mNewName.equals(mOldName)) { | ||||
|                 return new RemoteOperationResult(ResultCode.OK); | ||||
|                 return new RemoteOperationResult<>(ResultCode.OK); | ||||
|             } | ||||
| 
 | ||||
|             if (targetPathIsUsed(client)) { | ||||
|                 return new RemoteOperationResult(ResultCode.INVALID_OVERWRITE); | ||||
|                 return new RemoteOperationResult<>(ResultCode.INVALID_OVERWRITE); | ||||
|             } | ||||
| 
 | ||||
|             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 RemoteOperationResult result = | ||||
|                     (status == HttpConstants.HTTP_CREATED || status == HttpConstants.HTTP_NO_CONTENT) | ||||
|                             ? new RemoteOperationResult(ResultCode.OK) | ||||
|                             : new RemoteOperationResult(move); | ||||
|                             ? new RemoteOperationResult<>(ResultCode.OK) | ||||
|                             : new RemoteOperationResult<>(move); | ||||
| 
 | ||||
|             Log_OC.i(TAG, "Rename " + mOldRemotePath + " to " + mNewRemotePath + ": " + | ||||
|                     result.getLogMessage() | ||||
| @ -126,7 +124,7 @@ public class RenameRemoteFileOperation extends RemoteOperation { | ||||
|             client.exhaustResponse(move.getResponseAsStream()); | ||||
|             return result; | ||||
|         } catch (Exception e) { | ||||
|             final RemoteOperationResult result = new RemoteOperationResult(e); | ||||
|             final RemoteOperationResult result = new RemoteOperationResult<>(e); | ||||
|             Log_OC.e(TAG, "Rename " + mOldRemotePath + " to " + | ||||
|                     ((mNewRemotePath == null) ? mNewName : mNewRemotePath) + ": " + | ||||
|                     result.getLogMessage(), e); | ||||
|  | ||||
| @ -95,7 +95,7 @@ public class UploadRemoteFileOperation extends RemoteOperation { | ||||
| 
 | ||||
|             if (mCancellationRequested.get()) { | ||||
|                 // 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 { | ||||
|                 // perform the upload | ||||
|                 result = uploadFile(client); | ||||
| @ -106,11 +106,11 @@ public class UploadRemoteFileOperation extends RemoteOperation { | ||||
|         } catch (Exception e) { | ||||
| 
 | ||||
|             if (mPutMethod != null && mPutMethod.isAborted()) { | ||||
|                 result = new RemoteOperationResult(new OperationCancelledException()); | ||||
|                 result = new RemoteOperationResult<>(new OperationCancelledException()); | ||||
|                 Log_OC.e(TAG, "Upload of " + mLocalPath + " to " + mRemotePath + ": " + | ||||
|                         result.getLogMessage(), new OperationCancelledException()); | ||||
|             } else { | ||||
|                 result = new RemoteOperationResult(e); | ||||
|                 result = new RemoteOperationResult<>(e); | ||||
|                 Log_OC.e(TAG, "Upload of " + mLocalPath + " to " + mRemotePath + ": " + | ||||
|                         result.getLogMessage(), e); | ||||
|             } | ||||
| @ -119,7 +119,7 @@ public class UploadRemoteFileOperation extends RemoteOperation { | ||||
|         return result; | ||||
|     } | ||||
| 
 | ||||
|     protected RemoteOperationResult uploadFile(OwnCloudClient client) throws Exception { | ||||
|     protected RemoteOperationResult<? extends Object> uploadFile(OwnCloudClient client) throws Exception { | ||||
| 
 | ||||
|         File fileToUpload = new File(mLocalPath); | ||||
| 
 | ||||
| @ -144,10 +144,10 @@ public class UploadRemoteFileOperation extends RemoteOperation { | ||||
|         int status = client.executeHttpMethod(mPutMethod); | ||||
| 
 | ||||
|         if (isSuccess(status)) { | ||||
|             return new RemoteOperationResult(OK); | ||||
|             return new RemoteOperationResult<>(OK); | ||||
| 
 | ||||
|         } 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.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. | ||||
| @ -100,7 +101,7 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation | ||||
|             ((ChunkFromFileRequestBody) mFileRequestBody).setOffset(offset); | ||||
| 
 | ||||
|             if (mCancellationRequested.get()) { | ||||
|                 result = new RemoteOperationResult(new OperationCancelledException()); | ||||
|                 result = new RemoteOperationResult<>(new OperationCancelledException()); | ||||
|                 break; | ||||
|             } else { | ||||
|                 if (chunkIndex == chunkCount - 1) { | ||||
| @ -119,9 +120,9 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation | ||||
|                         ", HTTP result status " + status); | ||||
| 
 | ||||
|                 if (isSuccess(status)) { | ||||
|                     result = new RemoteOperationResult(OK); | ||||
|                     result = new RemoteOperationResult<>(OK); | ||||
|                 } else { | ||||
|                     result = new RemoteOperationResult(mPutMethod); | ||||
|                     result = new RemoteOperationResult<>(mPutMethod); | ||||
|                     break; | ||||
|                 } | ||||
|             } | ||||
|  | ||||
| @ -186,17 +186,13 @@ public class CreateRemoteShareOperation extends RemoteOperation { | ||||
|         mPublicUpload = publicUpload; | ||||
|     } | ||||
| 
 | ||||
|     public boolean isGettingShareDetails() { | ||||
|         return mGetShareDetails; | ||||
|     } | ||||
| 
 | ||||
|     public void setGetShareDetails(boolean set) { | ||||
|         mGetShareDetails = set; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     protected RemoteOperationResult run(OwnCloudClient client) { | ||||
|         RemoteOperationResult result; | ||||
|     protected RemoteOperationResult<ShareParserResult> run(OwnCloudClient client) { | ||||
|         RemoteOperationResult<ShareParserResult> result; | ||||
| 
 | ||||
|         try { | ||||
|             FormBody.Builder formBodyBuilder = new FormBody.Builder() | ||||
| @ -253,7 +249,7 @@ public class CreateRemoteShareOperation extends RemoteOperation { | ||||
| 
 | ||||
|                     // TODO Use executeHttpMethod | ||||
|                     // 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( | ||||
|                             emptyShare.getRemoteId() | ||||
|                     ); | ||||
| @ -261,11 +257,11 @@ public class CreateRemoteShareOperation extends RemoteOperation { | ||||
|                 } | ||||
| 
 | ||||
|             } else { | ||||
|                 result = new RemoteOperationResult(postMethod); | ||||
|                 result = new RemoteOperationResult<>(postMethod); | ||||
|             } | ||||
| 
 | ||||
|         } catch (Exception e) { | ||||
|             result = new RemoteOperationResult(e); | ||||
|             result = new RemoteOperationResult<>(e); | ||||
|             Log_OC.e(TAG, "Exception while Creating New Share", e); | ||||
|         } | ||||
|         return result; | ||||
|  | ||||
| @ -44,7 +44,7 @@ import java.net.URL; | ||||
|  * @author David González Verdugo | ||||
|  */ | ||||
| 
 | ||||
| public class GetRemoteShareOperation extends RemoteOperation { | ||||
| public class GetRemoteShareOperation extends RemoteOperation<ShareParserResult> { | ||||
| 
 | ||||
|     private static final String TAG = GetRemoteShareOperation.class.getSimpleName(); | ||||
| 
 | ||||
| @ -57,7 +57,7 @@ public class GetRemoteShareOperation extends RemoteOperation { | ||||
| 
 | ||||
|     @Override | ||||
|     protected RemoteOperationResult run(OwnCloudClient client) { | ||||
|         RemoteOperationResult result; | ||||
|         RemoteOperationResult<ShareParserResult> result; | ||||
| 
 | ||||
|         try { | ||||
|             Uri requestUri = client.getBaseUri(); | ||||
| @ -83,11 +83,11 @@ public class GetRemoteShareOperation extends RemoteOperation { | ||||
|                 result = parser.parse(getMethod.getResponseBodyAsString()); | ||||
| 
 | ||||
|             } else { | ||||
|                 result = new RemoteOperationResult(getMethod); | ||||
|                 result = new RemoteOperationResult<>(getMethod); | ||||
|             } | ||||
| 
 | ||||
|         } catch (Exception e) { | ||||
|             result = new RemoteOperationResult(e); | ||||
|             result = new RemoteOperationResult<>(e); | ||||
|             Log_OC.e(TAG, "Exception while getting remote shares ", e); | ||||
|         } | ||||
|         return result; | ||||
|  | ||||
| @ -70,7 +70,7 @@ import static com.owncloud.android.lib.common.operations.RemoteOperationResult.R | ||||
|  * @author David A. Velasco | ||||
|  * @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(); | ||||
| 
 | ||||
| @ -118,8 +118,8 @@ public class GetRemoteShareesOperation extends RemoteOperation{ | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     protected RemoteOperationResult run(OwnCloudClient client) { | ||||
|         RemoteOperationResult result; | ||||
|     protected RemoteOperationResult<ArrayList<JSONObject>> run(OwnCloudClient client) { | ||||
|         RemoteOperationResult<ArrayList<JSONObject>> result; | ||||
| 
 | ||||
|         try{ | ||||
|             Uri requestUri = client.getBaseUri(); | ||||
| @ -161,7 +161,7 @@ public class GetRemoteShareesOperation extends RemoteOperation{ | ||||
|                         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 j=0; j< jsonResults[i].length(); 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); | ||||
| 
 | ||||
|                 Log_OC.d(TAG, "*** Get Users or groups completed " ); | ||||
| 
 | ||||
|             } else { | ||||
|                 result = new RemoteOperationResult(getMethod); | ||||
|                 result = new RemoteOperationResult<>(getMethod); | ||||
|                 Log_OC.e(TAG, "Failed response while getting users/groups from the server "); | ||||
|                 if (response != null) { | ||||
|                     Log_OC.e(TAG, "*** status code: " + status + "; response message: " + response); | ||||
| @ -185,7 +185,7 @@ public class GetRemoteShareesOperation extends RemoteOperation{ | ||||
|                 } | ||||
|             } | ||||
|         } catch (Exception e) { | ||||
|             result = new RemoteOperationResult(e); | ||||
|             result = new RemoteOperationResult<>(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 okhttp3.HttpUrl; | ||||
| 
 | ||||
| /** | ||||
|  * Provide a list shares for a specific file. | ||||
|  * The input is the full path of the desired file. | ||||
| @ -49,7 +47,7 @@ import okhttp3.HttpUrl; | ||||
|  * @author David A. Velasco | ||||
|  * @author David González Verdugo | ||||
|  */ | ||||
| public class GetRemoteSharesForFileOperation extends RemoteOperation { | ||||
| public class GetRemoteSharesForFileOperation extends RemoteOperation<ShareParserResult> { | ||||
| 
 | ||||
|     private static final String TAG = GetRemoteSharesForFileOperation.class.getSimpleName(); | ||||
| 
 | ||||
| @ -79,8 +77,8 @@ public class GetRemoteSharesForFileOperation extends RemoteOperation { | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     protected RemoteOperationResult run(OwnCloudClient client) { | ||||
|         RemoteOperationResult result; | ||||
|     protected RemoteOperationResult<ShareParserResult> run(OwnCloudClient client) { | ||||
|         RemoteOperationResult<ShareParserResult> result; | ||||
| 
 | ||||
|         try { | ||||
| 
 | ||||
| @ -107,13 +105,13 @@ public class GetRemoteSharesForFileOperation extends RemoteOperation { | ||||
|                 result = parser.parse(getMethod.getResponseBodyAsString()); | ||||
| 
 | ||||
|                 if (result.isSuccess()) { | ||||
|                     Log_OC.d(TAG, "Got " + result.getData().size() + " shares"); | ||||
|                     Log_OC.d(TAG, "Got " + result.getData().getShares().size() + " shares"); | ||||
|                 } | ||||
|             } else { | ||||
|                 result = new RemoteOperationResult(getMethod); | ||||
|                 result = new RemoteOperationResult<>(getMethod); | ||||
|             } | ||||
|         } catch (Exception e) { | ||||
|             result = new RemoteOperationResult(e); | ||||
|             result = new RemoteOperationResult<>(e); | ||||
|             Log_OC.e(TAG, "Exception while getting shares", e); | ||||
|         } | ||||
| 
 | ||||
|  | ||||
| @ -75,10 +75,10 @@ public class GetRemoteSharesOperation extends RemoteOperation { | ||||
|                 parser.setServerBaseUri(client.getBaseUri()); | ||||
|                 result = parser.parse(getMethod.getResponseBodyAsString()); | ||||
|             } else { | ||||
|                 result = new RemoteOperationResult(getMethod); | ||||
|                 result = new RemoteOperationResult<>(getMethod); | ||||
|             } | ||||
|         } catch (Exception e) { | ||||
|             result = new RemoteOperationResult(e); | ||||
|             result = new RemoteOperationResult<>(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()); | ||||
| 
 | ||||
|             } else { | ||||
|                 result = new RemoteOperationResult(deleteMethod); | ||||
|                 result = new RemoteOperationResult<>(deleteMethod); | ||||
|             } | ||||
| 
 | ||||
|         } catch (Exception e) { | ||||
|             result = new RemoteOperationResult(e); | ||||
|             result = new RemoteOperationResult<>(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; | ||||
|     } | ||||
| 
 | ||||
|     public RemoteOperationResult parse(String serverResponse) { | ||||
|     public RemoteOperationResult<ShareParserResult> parse(String serverResponse) { | ||||
|         if (serverResponse == null || serverResponse.length() == 0) { | ||||
|             return new RemoteOperationResult(RemoteOperationResult.ResultCode.WRONG_SERVER_RESPONSE); | ||||
|             return new RemoteOperationResult<>(RemoteOperationResult.ResultCode.WRONG_SERVER_RESPONSE); | ||||
|         } | ||||
| 
 | ||||
|         RemoteOperationResult result; | ||||
|         ArrayList<Object> resultData = new ArrayList<Object>(); | ||||
|         RemoteOperationResult<ShareParserResult> result; | ||||
|         final ArrayList<OCShare> resultData = new ArrayList<>(); | ||||
| 
 | ||||
|         try { | ||||
|             // Parse xml response and obtain the list of shares | ||||
| @ -85,17 +85,16 @@ public class ShareToRemoteOperationResultParser { | ||||
| 
 | ||||
|             if (mShareXmlParser.isSuccess()) { | ||||
|                 if ((shares != null && shares.size() > 0) || !mOneOrMoreSharesRequired) { | ||||
|                     result = new RemoteOperationResult(RemoteOperationResult.ResultCode.OK); | ||||
|                     result = new RemoteOperationResult<>(RemoteOperationResult.ResultCode.OK); | ||||
|                     if (shares != null) { | ||||
|                         for (OCShare share : shares) { | ||||
|                             resultData.add(share); | ||||
|                             // build the share link if not in the response | ||||
|                             // (needed for OC servers < 9.0.0, see ShareXMLParser.java#line256) | ||||
|                             if (share.getShareType() == ShareType.PUBLIC_LINK && | ||||
|                                     (share.getShareLink() == null || | ||||
|                                             share.getShareLink().length() <= 0) && | ||||
|                                     share.getToken().length() > 0 | ||||
|                                     ) { | ||||
|                             if (share.getShareType() == ShareType.PUBLIC_LINK | ||||
|                                     && (share.getShareLink() == null | ||||
|                                         || share.getShareLink().length() <= 0) | ||||
|                                     && share.getToken().length() > 0) { | ||||
|                                 if (mServerBaseUri != null) { | ||||
|                                     String sharingLinkPath = ShareUtils.getSharingLinkPath(mOwnCloudVersion); | ||||
|                                     share.setShareLink(mServerBaseUri + sharingLinkPath + share.getToken()); | ||||
| @ -105,40 +104,36 @@ public class ShareToRemoteOperationResultParser { | ||||
|                             } | ||||
|                         } | ||||
|                     } | ||||
|                     result.setData(resultData); | ||||
|                     result.setData(new ShareParserResult(resultData, "")); | ||||
| 
 | ||||
|                 } 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"); | ||||
|                 } | ||||
| 
 | ||||
|             } else if (mShareXmlParser.isWrongParameter()){ | ||||
|                 result = new RemoteOperationResult(RemoteOperationResult.ResultCode.SHARE_WRONG_PARAMETER); | ||||
|                 resultData.add(mShareXmlParser.getMessage()); | ||||
|                 result.setData(resultData); | ||||
|                 result = new RemoteOperationResult<>(RemoteOperationResult.ResultCode.SHARE_WRONG_PARAMETER); | ||||
|                 result.setData(new ShareParserResult(null, mShareXmlParser.getMessage())); | ||||
| 
 | ||||
|             } else if (mShareXmlParser.isNotFound()){ | ||||
|                 result = new RemoteOperationResult(RemoteOperationResult.ResultCode.SHARE_NOT_FOUND); | ||||
|                 resultData.add(mShareXmlParser.getMessage()); | ||||
|                 result.setData(resultData); | ||||
|                 result = new RemoteOperationResult<>(RemoteOperationResult.ResultCode.SHARE_NOT_FOUND); | ||||
|                 result.setData(new ShareParserResult(null, mShareXmlParser.getMessage())); | ||||
| 
 | ||||
|             } else if (mShareXmlParser.isForbidden()) { | ||||
|                 result = new RemoteOperationResult(RemoteOperationResult.ResultCode.SHARE_FORBIDDEN); | ||||
|                 resultData.add(mShareXmlParser.getMessage()); | ||||
|                 result.setData(resultData); | ||||
|                 result = new RemoteOperationResult<>(RemoteOperationResult.ResultCode.SHARE_FORBIDDEN); | ||||
|                 result.setData(new ShareParserResult(null, mShareXmlParser.getMessage())); | ||||
| 
 | ||||
|             } else { | ||||
|                 result = new RemoteOperationResult(RemoteOperationResult.ResultCode.WRONG_SERVER_RESPONSE); | ||||
| 
 | ||||
|                 result = new RemoteOperationResult<>(RemoteOperationResult.ResultCode.WRONG_SERVER_RESPONSE); | ||||
|             } | ||||
| 
 | ||||
|         } catch (XmlPullParserException 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) { | ||||
|             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; | ||||
|  | ||||
| @ -51,7 +51,7 @@ import okhttp3.FormBody; | ||||
|  * @author David González Verdugo | ||||
|  */ | ||||
| 
 | ||||
| public class UpdateRemoteShareOperation extends RemoteOperation { | ||||
| public class UpdateRemoteShareOperation extends RemoteOperation<ShareParserResult> { | ||||
| 
 | ||||
|     private static final String TAG = GetRemoteShareOperation.class.getSimpleName(); | ||||
| 
 | ||||
| @ -163,8 +163,8 @@ public class UpdateRemoteShareOperation extends RemoteOperation { | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     protected RemoteOperationResult run(OwnCloudClient client) { | ||||
|         RemoteOperationResult result; | ||||
|     protected RemoteOperationResult<ShareParserResult> run(OwnCloudClient client) { | ||||
|         RemoteOperationResult<ShareParserResult> result; | ||||
| 
 | ||||
|         try { | ||||
|             FormBody.Builder formBodyBuilder = new FormBody.Builder(); | ||||
| @ -222,11 +222,11 @@ public class UpdateRemoteShareOperation extends RemoteOperation { | ||||
|                 result = parser.parse(putMethod.getResponseBodyAsString()); | ||||
| 
 | ||||
|             } else { | ||||
|                 result = new RemoteOperationResult(putMethod); | ||||
|                 result = new RemoteOperationResult<>(putMethod); | ||||
|             } | ||||
| 
 | ||||
|         } catch (Exception e) { | ||||
|             result = new RemoteOperationResult(e); | ||||
|             result = new RemoteOperationResult<>(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 java.net.URL; | ||||
| import java.util.ArrayList; | ||||
| 
 | ||||
| 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 David González Verdugo | ||||
|  */ | ||||
| public class GetRemoteCapabilitiesOperation extends RemoteOperation { | ||||
| public class GetRemoteCapabilitiesOperation extends RemoteOperation<OCCapability> { | ||||
| 
 | ||||
|     private static final String TAG = GetRemoteCapabilitiesOperation.class.getSimpleName(); | ||||
| 
 | ||||
| @ -120,8 +119,8 @@ public class GetRemoteCapabilitiesOperation extends RemoteOperation { | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     protected RemoteOperationResult run(OwnCloudClient client) { | ||||
|         RemoteOperationResult result; | ||||
|     protected RemoteOperationResult<OCCapability> run(OwnCloudClient client) { | ||||
|         RemoteOperationResult<OCCapability> result; | ||||
| 
 | ||||
|         try { | ||||
|             Uri requestUri = client.getBaseUri(); | ||||
| @ -151,7 +150,6 @@ public class GetRemoteCapabilitiesOperation extends RemoteOperation { | ||||
|                 String message = respMeta.getString(PROPERTY_MESSAGE); | ||||
| 
 | ||||
|                 if (statusProp) { | ||||
|                     ArrayList<Object> data = new ArrayList<Object>(); // For result data | ||||
|                     OCCapability capability = new OCCapability(); | ||||
|                     // Add Version | ||||
|                     if (respData.has(NODE_VERSION)) { | ||||
| @ -257,19 +255,18 @@ public class GetRemoteCapabilitiesOperation extends RemoteOperation { | ||||
|                         } | ||||
|                     } | ||||
|                     // Result | ||||
|                     data.add(capability); | ||||
|                     result = new RemoteOperationResult(OK); | ||||
|                     result.setData(data); | ||||
|                     result = new RemoteOperationResult<>(OK); | ||||
|                     result.setData(capability); | ||||
| 
 | ||||
|                     Log_OC.d(TAG, "*** Get Capabilities completed "); | ||||
|                 } 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, "*** status: " + statusProp + "; message: " + message); | ||||
|                 } | ||||
| 
 | ||||
|             } else { | ||||
|                 result = new RemoteOperationResult(getMethod); | ||||
|                 result = new RemoteOperationResult<>(getMethod); | ||||
|                 Log_OC.e(TAG, "Failed response while getting capabilities from the server "); | ||||
|                 if (response != null) { | ||||
|                     Log_OC.e(TAG, "*** status code: " + status + "; response message: " + response); | ||||
| @ -279,7 +276,7 @@ public class GetRemoteCapabilitiesOperation extends RemoteOperation { | ||||
|             } | ||||
| 
 | ||||
|         } catch (Exception e) { | ||||
|             result = new RemoteOperationResult(e); | ||||
|             result = new RemoteOperationResult<>(e); | ||||
|             Log_OC.e(TAG, "Exception while getting capabilities", e); | ||||
|         } | ||||
|         return result; | ||||
|  | ||||
| @ -39,7 +39,6 @@ import org.json.JSONException; | ||||
| import org.json.JSONObject; | ||||
| 
 | ||||
| import java.net.URL; | ||||
| import java.util.ArrayList; | ||||
| import java.util.concurrent.TimeUnit; | ||||
| 
 | ||||
| import javax.net.ssl.SSLPeerUnverifiedException; | ||||
| @ -54,7 +53,7 @@ import static com.owncloud.android.lib.common.operations.RemoteOperationResult.R | ||||
|  * @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, | ||||
| @ -69,7 +68,7 @@ public class GetRemoteStatusOperation extends RemoteOperation { | ||||
|     private static final String HTTPS_PREFIX = "https://"; | ||||
|     private static final String HTTP_PREFIX = "http://"; | ||||
| 
 | ||||
|     private RemoteOperationResult mLatestResult; | ||||
|     private RemoteOperationResult<OwnCloudVersion> mLatestResult; | ||||
|     private Context mContext; | ||||
| 
 | ||||
|     public GetRemoteStatusOperation(Context context) { | ||||
| @ -110,7 +109,7 @@ public class GetRemoteStatusOperation extends RemoteOperation { | ||||
|                 getMethod.setConnectionTimeout(TRY_CONNECTION_TIMEOUT, TimeUnit.SECONDS); | ||||
| 
 | ||||
|                 status = client.executeHttpMethod(getMethod); | ||||
|                 mLatestResult = new RemoteOperationResult(getMethod); | ||||
|                 mLatestResult = new RemoteOperationResult<>(getMethod); | ||||
|                 redirectedLocation = mLatestResult.getRedirectedLocation(); | ||||
|             } | ||||
| 
 | ||||
| @ -127,34 +126,30 @@ public class GetRemoteStatusOperation extends RemoteOperation { | ||||
|                     /// every app will decide how to act if (ocVersion.isVersionValid() == false) | ||||
| 
 | ||||
|                     if (isRedirectToNonSecureConnection) { | ||||
|                         mLatestResult = new RemoteOperationResult( | ||||
|                         mLatestResult = new RemoteOperationResult<>( | ||||
|                             RemoteOperationResult.ResultCode. | ||||
|                                 OK_REDIRECT_TO_NON_SECURE_CONNECTION | ||||
|                         ); | ||||
|                                 OK_REDIRECT_TO_NON_SECURE_CONNECTION); | ||||
|                     } else { | ||||
|                         mLatestResult = new RemoteOperationResult( | ||||
|                         mLatestResult = new RemoteOperationResult<>( | ||||
|                             baseUrlSt.startsWith(HTTPS_PREFIX) ? | ||||
|                                 RemoteOperationResult.ResultCode.OK_SSL : | ||||
|                                 RemoteOperationResult.ResultCode.OK_NO_SSL | ||||
|                         ); | ||||
|                                 RemoteOperationResult.ResultCode.OK_NO_SSL); | ||||
|                     } | ||||
| 
 | ||||
|                     ArrayList<Object> data = new ArrayList<>(); | ||||
|                     data.add(ocVersion); | ||||
|                     mLatestResult.setData(data); | ||||
|                     mLatestResult.setData(ocVersion); | ||||
|                     retval = true; | ||||
|                 } | ||||
| 
 | ||||
|             } else { | ||||
|                 mLatestResult = new RemoteOperationResult(getMethod); | ||||
|                 mLatestResult = new RemoteOperationResult<>(getMethod); | ||||
|             } | ||||
| 
 | ||||
|         } catch (JSONException e) { | ||||
|             mLatestResult = new RemoteOperationResult( | ||||
|             mLatestResult = new RemoteOperationResult<>( | ||||
|                 RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED); | ||||
| 
 | ||||
|         } catch (Exception e) { | ||||
|             mLatestResult = new RemoteOperationResult(e); | ||||
|             mLatestResult = new RemoteOperationResult<>(e); | ||||
|         } | ||||
| 
 | ||||
|         if (mLatestResult.isSuccess()) { | ||||
| @ -179,9 +174,9 @@ public class GetRemoteStatusOperation extends RemoteOperation { | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     protected RemoteOperationResult run(OwnCloudClient client) { | ||||
|     protected RemoteOperationResult<OwnCloudVersion> run(OwnCloudClient client) { | ||||
|         if (!isOnline()) { | ||||
|             return new RemoteOperationResult(RemoteOperationResult.ResultCode.NO_NETWORK_CONNECTION); | ||||
|             return new RemoteOperationResult<>(RemoteOperationResult.ResultCode.NO_NETWORK_CONNECTION); | ||||
|         } | ||||
|         String baseUriStr = client.getBaseUri().toString(); | ||||
|         if (baseUriStr.startsWith(HTTP_PREFIX) || baseUriStr.startsWith(HTTPS_PREFIX)) { | ||||
|  | ||||
| @ -39,7 +39,6 @@ import java.io.ByteArrayOutputStream; | ||||
| import java.io.IOException; | ||||
| import java.io.InputStream; | ||||
| import java.net.URL; | ||||
| import java.util.ArrayList; | ||||
| 
 | ||||
| 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 | ||||
|  */ | ||||
| 
 | ||||
| public class GetRemoteUserAvatarOperation extends RemoteOperation { | ||||
| public class GetRemoteUserAvatarOperation extends RemoteOperation<GetRemoteUserAvatarOperation.ResultData> { | ||||
| 
 | ||||
|     private static final String TAG = GetRemoteUserAvatarOperation.class.getSimpleName(); | ||||
| 
 | ||||
| @ -73,9 +72,9 @@ public class GetRemoteUserAvatarOperation extends RemoteOperation { | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     protected RemoteOperationResult run(OwnCloudClient client) { | ||||
|     protected RemoteOperationResult<ResultData> run(OwnCloudClient client) { | ||||
|         GetMethod getMethod = null; | ||||
|         RemoteOperationResult result; | ||||
|         RemoteOperationResult<ResultData> result; | ||||
|         InputStream inputStream = null; | ||||
|         BufferedInputStream bis = null; | ||||
|         ByteArrayOutputStream bos = null; | ||||
| @ -107,9 +106,7 @@ public class GetRemoteUserAvatarOperation extends RemoteOperation { | ||||
|                     Log_OC.e( | ||||
|                         TAG, "Not an image, failing with no avatar" | ||||
|                     ); | ||||
|                     result = new RemoteOperationResult( | ||||
|                         RemoteOperationResult.ResultCode.FILE_NOT_FOUND | ||||
|                     ); | ||||
|                     result = new RemoteOperationResult<>(RemoteOperationResult.ResultCode.FILE_NOT_FOUND); | ||||
|                     return result; | ||||
|                 } | ||||
| 
 | ||||
| @ -136,19 +133,16 @@ public class GetRemoteUserAvatarOperation extends RemoteOperation { | ||||
|                 } | ||||
| 
 | ||||
|                 // Result | ||||
|                 result = new RemoteOperationResult(OK); | ||||
|                 ResultData resultData = new ResultData(bos.toByteArray(), mimeType, etag); | ||||
|                 ArrayList<Object> data = new ArrayList<Object>(); | ||||
|                 data.add(resultData); | ||||
|                 result.setData(data); | ||||
|                 result = new RemoteOperationResult<>(OK); | ||||
|                 result.setData(new ResultData(bos.toByteArray(), mimeType, etag)); | ||||
| 
 | ||||
|             } else { | ||||
|                 result = new RemoteOperationResult(getMethod); | ||||
|                 result = new RemoteOperationResult<>(getMethod); | ||||
|                 client.exhaustResponse(getMethod.getResponseAsStream()); | ||||
|             } | ||||
| 
 | ||||
|         } catch (Exception e) { | ||||
|             result = new RemoteOperationResult(e); | ||||
|             result = new RemoteOperationResult<>(e); | ||||
|             Log_OC.e(TAG, "Exception while getting OC user avatar", e); | ||||
| 
 | ||||
|         } finally { | ||||
|  | ||||
| @ -34,7 +34,6 @@ import com.owncloud.android.lib.common.utils.Log_OC; | ||||
| import org.json.JSONObject; | ||||
| 
 | ||||
| import java.net.URL; | ||||
| import java.util.ArrayList; | ||||
| 
 | ||||
| import okhttp3.Request; | ||||
| 
 | ||||
| @ -67,8 +66,8 @@ public class GetRemoteUserInfoOperation extends RemoteOperation { | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     protected RemoteOperationResult run(OwnCloudClient client) { | ||||
|         RemoteOperationResult result; | ||||
|     protected RemoteOperationResult<UserInfo> run(OwnCloudClient client) { | ||||
|         RemoteOperationResult<UserInfo> result; | ||||
| 
 | ||||
|         //Get the user | ||||
|         try { | ||||
| @ -93,14 +92,12 @@ public class GetRemoteUserInfoOperation extends RemoteOperation { | ||||
|                 userInfo.mDisplayName = respData.getString(NODE_DISPLAY_NAME); | ||||
|                 userInfo.mEmail = respData.getString(NODE_EMAIL); | ||||
| 
 | ||||
|                 result = new RemoteOperationResult(OK); | ||||
|                 result = new RemoteOperationResult<>(OK); | ||||
| 
 | ||||
|                 ArrayList<Object> data = new ArrayList<>(); | ||||
|                 data.add(userInfo); | ||||
|                 result.setData(data); | ||||
|                 result.setData(userInfo); | ||||
| 
 | ||||
|             } else { | ||||
|                 result = new RemoteOperationResult(getMethod); | ||||
|                 result = new RemoteOperationResult<>(getMethod); | ||||
|                 String response = getMethod.getResponseBodyAsString(); | ||||
|                 Log_OC.e(TAG, "Failed response while getting user information "); | ||||
|                 if (getMethod != null) { | ||||
| @ -110,7 +107,7 @@ public class GetRemoteUserInfoOperation extends RemoteOperation { | ||||
|                 } | ||||
|             } | ||||
|         } catch (Exception e) { | ||||
|             result = new RemoteOperationResult(e); | ||||
|             result = new RemoteOperationResult<>(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 java.net.URL; | ||||
| import java.util.ArrayList; | ||||
| 
 | ||||
| import at.bitfire.dav4android.PropertyCollection; | ||||
| import at.bitfire.dav4android.property.QuotaAvailableBytes; | ||||
| @ -50,7 +49,7 @@ import static com.owncloud.android.lib.common.operations.RemoteOperationResult.R | ||||
|  * @author marcello | ||||
|  * @author David González Verdugo | ||||
|  */ | ||||
| public class GetRemoteUserQuotaOperation extends RemoteOperation { | ||||
| public class GetRemoteUserQuotaOperation extends RemoteOperation<GetRemoteUserQuotaOperation.RemoteQuota> { | ||||
| 
 | ||||
|     static public class RemoteQuota { | ||||
| 
 | ||||
| @ -84,8 +83,8 @@ public class GetRemoteUserQuotaOperation extends RemoteOperation { | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     protected RemoteOperationResult run(OwnCloudClient client) { | ||||
|         RemoteOperationResult result = null; | ||||
|     protected RemoteOperationResult<RemoteQuota> run(OwnCloudClient client) { | ||||
|         RemoteOperationResult<RemoteQuota> result = null; | ||||
| 
 | ||||
|         try { | ||||
|             PropfindMethod propfindMethod = new PropfindMethod( | ||||
| @ -99,22 +98,19 @@ public class GetRemoteUserQuotaOperation extends RemoteOperation { | ||||
|             if (isSuccess(status)) { | ||||
|                 RemoteQuota remoteQuota = readData(propfindMethod.getDavResource().getProperties()); | ||||
| 
 | ||||
|                 result = new RemoteOperationResult(OK); | ||||
| 
 | ||||
|                 ArrayList<Object> data = new ArrayList<>(); | ||||
|                 data.add(remoteQuota); | ||||
|                 result = new RemoteOperationResult<>(OK); | ||||
| 
 | ||||
|                 // Add data to the result | ||||
|                 if (result.isSuccess()) { | ||||
|                     result.setData(data); | ||||
|                     result.setData(remoteQuota); | ||||
|                 } | ||||
| 
 | ||||
|             } else { // synchronization failed | ||||
|                 result = new RemoteOperationResult(propfindMethod); | ||||
|                 result = new RemoteOperationResult<>(propfindMethod); | ||||
|             } | ||||
| 
 | ||||
|         } catch (Exception e) { | ||||
|             result = new RemoteOperationResult(e); | ||||
|             result = new RemoteOperationResult<>(e); | ||||
| 
 | ||||
| 
 | ||||
|         } finally { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user