From 99ced8bf412ee439a598253695a674daaec89944 Mon Sep 17 00:00:00 2001 From: abelgardep Date: Fri, 24 Jan 2020 21:51:39 +0100 Subject: [PATCH 01/15] Refactor GetRemoteUserInfoOperation Start using Moshi to parse json responses. Create RemoteUserInfo and UserInfoResponse. Create UserService. Migrate GetRemoteUserInfoOperation to kotlin. --- build.gradle | 1 + owncloudComLibrary/build.gradle | 6 + .../lib/resources/CommonOcsResponse.kt | 44 +++++++ .../users/GetRemoteUserInfoOperation.java | 111 ------------------ .../users/GetRemoteUserInfoOperation.kt | 81 +++++++++++++ .../lib/resources/users/RemoteUserInfo.kt | 30 +++++ .../lib/resources/users/UserInfoResponse.kt | 42 +++++++ .../lib/resources/users/UserService.kt | 32 +++++ 8 files changed, 236 insertions(+), 111 deletions(-) create mode 100644 owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/CommonOcsResponse.kt delete mode 100644 owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/GetRemoteUserInfoOperation.java create mode 100644 owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/GetRemoteUserInfoOperation.kt create mode 100644 owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/RemoteUserInfo.kt create mode 100644 owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/UserInfoResponse.kt create mode 100644 owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/UserService.kt diff --git a/build.gradle b/build.gradle index c0052708..c22d1831 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,7 @@ buildscript { ext { kotlinVersion = '1.3.71' + moshiVersion = "1.9.2" } repositories { diff --git a/owncloudComLibrary/build.gradle b/owncloudComLibrary/build.gradle index 82949174..d18e80ea 100644 --- a/owncloudComLibrary/build.gradle +++ b/owncloudComLibrary/build.gradle @@ -9,6 +9,12 @@ dependencies { api 'com.gitlab.ownclouders:dav4android:oc_support_1.0.1' api 'com.github.hannesa2:Logcat:1.6.0' api 'net.openid:appauth:0.7.1' + + // Moshi + implementation ("com.squareup.moshi:moshi-kotlin:$moshiVersion") { + exclude module: "kotlin-reflect" + } + kapt "com.squareup.moshi:moshi-kotlin-codegen:$moshiVersion" } allOpen { diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/CommonOcsResponse.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/CommonOcsResponse.kt new file mode 100644 index 00000000..f0bb805e --- /dev/null +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/CommonOcsResponse.kt @@ -0,0 +1,44 @@ +/* ownCloud Android Library is available under MIT license + * + * Copyright (C) 2020 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.resources + +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +data class CommonOcsResponse( + val ocs: OCSResponse +) + +@JsonClass(generateAdapter = true) +data class OCSResponse( + val meta: MetaData, + val data: T +) + +@JsonClass(generateAdapter = true) +data class MetaData( + val status: String, + val statuscode: Int, + val message: String? +) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/GetRemoteUserInfoOperation.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/GetRemoteUserInfoOperation.java deleted file mode 100644 index dce2096a..00000000 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/GetRemoteUserInfoOperation.java +++ /dev/null @@ -1,111 +0,0 @@ -/* ownCloud Android Library is available under MIT license - * Copyright (C) 2020 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.resources.users; - -import com.owncloud.android.lib.common.OwnCloudClient; -import com.owncloud.android.lib.common.http.HttpConstants; -import com.owncloud.android.lib.common.http.methods.nonwebdav.GetMethod; -import com.owncloud.android.lib.common.operations.RemoteOperation; -import com.owncloud.android.lib.common.operations.RemoteOperationResult; -import org.json.JSONObject; -import timber.log.Timber; - -import java.net.URL; - -import static com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.OK; - -/** - * Gets information (id, display name, and e-mail address) about the user logged in. - * - * @author masensio - * @author David A. Velasco - * @author David González Verdugo - */ - -public class GetRemoteUserInfoOperation extends RemoteOperation { - - // OCS Route - private static final String OCS_ROUTE = "/ocs/v2.php/cloud/user?format=json"; - - // JSON Node names - private static final String NODE_OCS = "ocs"; - private static final String NODE_DATA = "data"; - private static final String NODE_ID = "id"; - private static final String NODE_DISPLAY_NAME = "display-name"; - private static final String NODE_EMAIL = "email"; - - public GetRemoteUserInfoOperation() { - } - - @Override - protected RemoteOperationResult run(OwnCloudClient client) { - RemoteOperationResult result; - - //Get the user - try { - GetMethod getMethod = new GetMethod(new URL(client.getBaseUri() + OCS_ROUTE)); - - int status = client.executeHttpMethod(getMethod); - - if (isSuccess(status)) { - Timber.d("Successful response"); - - JSONObject respJSON = new JSONObject(getMethod.getResponseBodyAsString()); - JSONObject respOCS = respJSON.getJSONObject(NODE_OCS); - JSONObject respData = respOCS.getJSONObject(NODE_DATA); - - UserInfo userInfo = new UserInfo(); - userInfo.mId = respData.getString(NODE_ID); - userInfo.mDisplayName = respData.getString(NODE_DISPLAY_NAME); - userInfo.mEmail = respData.getString(NODE_EMAIL); - - result = new RemoteOperationResult<>(OK); - - result.setData(userInfo); - - } else { - result = new RemoteOperationResult<>(getMethod); - String response = getMethod.getResponseBodyAsString(); - Timber.e("Failed response while getting user information "); - Timber.e("*** status code: " + status + " ; response message: " + response); - } - } catch (Exception e) { - result = new RemoteOperationResult<>(e); - Timber.e(e, "Exception while getting OC user information"); - } - - return result; - } - - private boolean isSuccess(int status) { - return (status == HttpConstants.HTTP_OK); - } - - public static class UserInfo { - public String mId = ""; - public String mDisplayName = ""; - public String mEmail = ""; - } -} \ No newline at end of file diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/GetRemoteUserInfoOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/GetRemoteUserInfoOperation.kt new file mode 100644 index 00000000..a406e6cb --- /dev/null +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/GetRemoteUserInfoOperation.kt @@ -0,0 +1,81 @@ +/* ownCloud Android Library is available under MIT license + * Copyright (C) 2020 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.resources.users + +import com.owncloud.android.lib.common.OwnCloudClient +import com.owncloud.android.lib.common.http.HttpConstants +import com.owncloud.android.lib.common.http.methods.nonwebdav.GetMethod +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.CommonOcsResponse +import com.squareup.moshi.JsonAdapter +import com.squareup.moshi.Moshi +import com.squareup.moshi.Types +import timber.log.Timber +import java.lang.reflect.Type +import java.net.URL + +/** + * Gets information (id, display name, and e-mail address) about the user logged in. + * + * @author masensio + * @author David A. Velasco + * @author David González Verdugo + * @author Abel García de Prada + */ +class GetRemoteUserInfoOperation : RemoteOperation() { + override fun run(client: OwnCloudClient): RemoteOperationResult { + var result: RemoteOperationResult + //Get the user + try { + val getMethod = GetMethod(URL(client.baseUri.toString() + OCS_ROUTE)) + val status = client.executeHttpMethod(getMethod) + val response = getMethod.responseBodyAsString + if (status == HttpConstants.HTTP_OK) { + Timber.d("Successful response $response") + + val moshi: Moshi = Moshi.Builder().build() + val type: Type = Types.newParameterizedType(CommonOcsResponse::class.java, UserInfoResponse::class.java) + val adapter: JsonAdapter> = moshi.adapter(type) + val commonResponse: CommonOcsResponse? = adapter.fromJson(response) + + result = RemoteOperationResult(ResultCode.OK) + result.setData(commonResponse?.ocs?.data?.toRemoteUserInfo()) + } else { + result = RemoteOperationResult(getMethod) + Timber.e("Failed response while getting user information status code: $status, response: $response") + } + } catch (e: Exception) { + result = RemoteOperationResult(e) + Timber.e(e, "Exception while getting OC user information") + } + return result + } + + companion object { + // OCS Route + private const val OCS_ROUTE = "/ocs/v2.php/cloud/user?format=json" + } +} diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/RemoteUserInfo.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/RemoteUserInfo.kt new file mode 100644 index 00000000..b66572de --- /dev/null +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/RemoteUserInfo.kt @@ -0,0 +1,30 @@ +/* ownCloud Android Library is available under MIT license + * + * Copyright (C) 2020 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.resources.users + +data class RemoteUserInfo( + val id: String, + val displayName: String, + val email: String? +) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/UserInfoResponse.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/UserInfoResponse.kt new file mode 100644 index 00000000..d0fdcf82 --- /dev/null +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/UserInfoResponse.kt @@ -0,0 +1,42 @@ +/* ownCloud Android Library is available under MIT license + * + * Copyright (C) 2020 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.resources.users + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +data class UserInfoResponse( + val id: String, + @Json(name = "display-name") + val displayName: String, + val email: String? +) + +fun UserInfoResponse.toRemoteUserInfo() = + RemoteUserInfo( + id = id, + displayName = displayName, + email = email + ) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/UserService.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/UserService.kt new file mode 100644 index 00000000..b3a33d79 --- /dev/null +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/UserService.kt @@ -0,0 +1,32 @@ +/* ownCloud Android Library is available under MIT license + * Copyright (C) 2020 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.resources.users + +import com.owncloud.android.lib.common.operations.RemoteOperationResult +import com.owncloud.android.lib.resources.Service + +interface UserService: Service { + fun getUserInfo() : RemoteOperationResult +} From 921983c16ea734c4aa58f24786e1025853a15c15 Mon Sep 17 00:00:00 2001 From: abelgardep Date: Sun, 26 Jan 2020 20:21:34 +0100 Subject: [PATCH 02/15] Migrate ExistenceCheckRemoteOperation to Kotlin --- .../files/ExistenceCheckRemoteOperation.java | 150 ------------------ .../files/RenameRemoteFileOperation.java | 6 +- .../server/CheckPathExistenceOperation.kt | 117 ++++++++++++++ .../lib/resources/server/ServerService.kt | 33 ++++ 4 files changed, 153 insertions(+), 153 deletions(-) delete mode 100644 owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/ExistenceCheckRemoteOperation.java create mode 100644 owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/CheckPathExistenceOperation.kt create mode 100644 owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/ServerService.kt diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/ExistenceCheckRemoteOperation.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/ExistenceCheckRemoteOperation.java deleted file mode 100644 index 1a21fbf1..00000000 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/ExistenceCheckRemoteOperation.java +++ /dev/null @@ -1,150 +0,0 @@ -/* ownCloud Android Library is available under MIT license - * Copyright (C) 2020 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.resources.files; - -import com.owncloud.android.lib.common.OwnCloudClient; -import com.owncloud.android.lib.common.http.HttpConstants; -import com.owncloud.android.lib.common.http.methods.webdav.DavUtils; -import com.owncloud.android.lib.common.http.methods.webdav.PropfindMethod; -import com.owncloud.android.lib.common.network.RedirectionPath; -import com.owncloud.android.lib.common.network.WebdavUtils; -import com.owncloud.android.lib.common.operations.RemoteOperation; -import com.owncloud.android.lib.common.operations.RemoteOperationResult; -import timber.log.Timber; - -import java.net.URL; -import java.util.concurrent.TimeUnit; - -import static com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.OK; - -/** - * Operation to check the existence or absence of a path in a remote server. - * - * @author David A. Velasco - * @author David González Verdugo - */ -public class ExistenceCheckRemoteOperation extends RemoteOperation { - - /** - * Maximum time to wait for a response from the server in MILLISECONDs. - */ - public static final int TIMEOUT = 10000; - - private String mPath; - private boolean mSuccessIfAbsent; - private boolean mIsLogin; - - /** - * Sequence of redirections followed. Available only after executing the operation - */ - private RedirectionPath mRedirectionPath = null; - - /** - * Full constructor. Success of the operation will depend upon the value of successIfAbsent. - * - * @param remotePath Path to append to the URL owned by the client instance. - * @param successIfAbsent When 'true', the operation finishes in success if the path does - * NOT exist in the remote server (HTTP 404). - * @param isLogin When `true`, the username won't be added at the end of the PROPFIND url since is not - * needed to check user credentials - */ - public ExistenceCheckRemoteOperation(String remotePath, boolean successIfAbsent, boolean isLogin) { - mPath = (remotePath != null) ? remotePath : ""; - mSuccessIfAbsent = successIfAbsent; - mIsLogin = isLogin; - } - - @Override - protected RemoteOperationResult run(OwnCloudClient client) { - - boolean previousFollowRedirects = client.followRedirects(); - - try { - String stringUrl = mIsLogin ? - client.getBaseFilesWebDavUri().toString() : - client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mPath); - PropfindMethod propfindMethod = new PropfindMethod( - new URL(stringUrl), - 0, - DavUtils.getAllPropset() - ); - propfindMethod.setReadTimeout(TIMEOUT, TimeUnit.SECONDS); - propfindMethod.setConnectionTimeout(TIMEOUT, TimeUnit.SECONDS); - - client.setFollowRedirects(false); - int status = client.executeHttpMethod(propfindMethod); - - if (previousFollowRedirects) { - mRedirectionPath = client.followRedirection(propfindMethod); - status = mRedirectionPath.getLastStatus(); - } - - /* - * PROPFIND method - * 404 NOT FOUND: path doesn't exist, - * 207 MULTI_STATUS: path exists. - */ - - Timber.d("Existence check for " + stringUrl + WebdavUtils.encodePath(mPath) + - " targeting for " + (mSuccessIfAbsent ? " absence " : " existence ") + - "finished with HTTP status " + status + (!isSuccess(status) ? "(FAIL)" : "")); - - return isSuccess(status) - ? new RemoteOperationResult<>(OK) - : new RemoteOperationResult<>(propfindMethod); - - } catch (Exception e) { - final RemoteOperationResult result = new RemoteOperationResult<>(e); - Timber.e(result.getException(), - "Existence check for " + client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mPath) + " " + - "targeting for " + (mSuccessIfAbsent ? " absence " : " existence ") + ": " + result.getLogMessage()); - return result; - } finally { - client.setFollowRedirects(previousFollowRedirects); - } - } - - /** - * Gets the sequence of redirections followed during the execution of the operation. - * - * @return Sequence of redirections followed, if any, or NULL if the operation was not executed. - */ - public RedirectionPath getRedirectionPath() { - return mRedirectionPath; - } - - /** - * @return 'True' if the operation was executed and at least one redirection was followed. - */ - public boolean wasRedirected() { - return (mRedirectionPath != null && mRedirectionPath.getRedirectionsCount() > 0); - } - - private boolean isSuccess(int status) { - return ((status == HttpConstants.HTTP_OK || status == HttpConstants.HTTP_MULTI_STATUS) && !mSuccessIfAbsent) - || (status == HttpConstants.HTTP_MULTI_STATUS && !mSuccessIfAbsent) - || (status == HttpConstants.HTTP_NOT_FOUND && mSuccessIfAbsent); - } -} \ No newline at end of file diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RenameRemoteFileOperation.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RenameRemoteFileOperation.java index 221a133c..4c87ef3e 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RenameRemoteFileOperation.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RenameRemoteFileOperation.java @@ -31,6 +31,7 @@ import com.owncloud.android.lib.common.network.WebdavUtils; 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.server.CheckPathExistenceOperation; import timber.log.Timber; import java.io.File; @@ -123,9 +124,8 @@ public class RenameRemoteFileOperation extends RemoteOperation { * @return 'True' if the target path is already used by an existing file. */ private boolean targetPathIsUsed(OwnCloudClient client) { - ExistenceCheckRemoteOperation existenceCheckRemoteOperation = - new ExistenceCheckRemoteOperation(mNewRemotePath, false, false); - RemoteOperationResult exists = existenceCheckRemoteOperation.run(client); + CheckPathExistenceOperation checkPathExistenceOperation = new CheckPathExistenceOperation(mNewRemotePath, false); + RemoteOperationResult exists = checkPathExistenceOperation.execute(client); return exists.isSuccess(); } } \ No newline at end of file diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/CheckPathExistenceOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/CheckPathExistenceOperation.kt new file mode 100644 index 00000000..e6f1e638 --- /dev/null +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/CheckPathExistenceOperation.kt @@ -0,0 +1,117 @@ +/* ownCloud Android Library is available under MIT license +* Copyright (C) 2020 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.resources.server + +import com.owncloud.android.lib.common.OwnCloudClient +import com.owncloud.android.lib.common.http.HttpConstants +import com.owncloud.android.lib.common.http.methods.webdav.DavUtils +import com.owncloud.android.lib.common.http.methods.webdav.PropfindMethod +import com.owncloud.android.lib.common.network.RedirectionPath +import com.owncloud.android.lib.common.network.WebdavUtils +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 timber.log.Timber +import java.net.URL +import java.util.concurrent.TimeUnit + +/** + * Operation to check the existence of a path in a remote server. + * + * @author David A. Velasco + * @author David González Verdugo + * @author Abel García de Prada + * + * @param remotePath Path to append to the URL owned by the client instance. + * @param isUserLogged When `true`, the username won't be added at the end of the PROPFIND url since is not + * needed to check user credentials + */ +class CheckPathExistenceOperation( + val remotePath: String? = "", + val isUserLogged: Boolean +) : RemoteOperation() { + /** + * Gets the sequence of redirections followed during the execution of the operation. + * + * @return Sequence of redirections followed, if any, or NULL if the operation was not executed. + */ + var redirectionPath: RedirectionPath? = null + private set + + override fun run(client: OwnCloudClient): RemoteOperationResult { + val previousFollowRedirects = client.followRedirects() + return try { + val stringUrl = + if (isUserLogged) client.baseFilesWebDavUri.toString() + else client.userFilesWebDavUri.toString() + WebdavUtils.encodePath(remotePath) + + val propFindMethod = PropfindMethod(URL(stringUrl), 0, DavUtils.getAllPropset()).apply { + setReadTimeout(TIMEOUT.toLong(), TimeUnit.SECONDS) + setConnectionTimeout(TIMEOUT.toLong(), TimeUnit.SECONDS) + } + + client.setFollowRedirects(false) + var status = client.executeHttpMethod(propFindMethod) + if (previousFollowRedirects) { + redirectionPath = client.followRedirection(propFindMethod) + status = redirectionPath?.lastStatus!! + } + /* PROPFIND method + * 404 NOT FOUND: path doesn't exist, + * 207 MULTI_STATUS: path exists. + */ + Timber.d( + "Existence check for $stringUrl${WebdavUtils.encodePath(remotePath)} finished with HTTP status $status${if (!isSuccess( + status + ) + ) "(FAIL)" else ""}" + ) + if (isSuccess(status)) RemoteOperationResult(ResultCode.OK) else RemoteOperationResult(propFindMethod) + } catch (e: Exception) { + val result = RemoteOperationResult(e) + Timber.e( + e, + "Existence check for ${client.userFilesWebDavUri}${WebdavUtils.encodePath(remotePath)} : ${result.logMessage}" + ) + result + } finally { + client.setFollowRedirects(previousFollowRedirects) + } + } + + /** + * @return 'True' if the operation was executed and at least one redirection was followed. + */ + fun wasRedirected() = redirectionPath != null && redirectionPath!!.redirectionsCount > 0 + + private fun isSuccess(status: Int) = + status == HttpConstants.HTTP_OK || status == HttpConstants.HTTP_MULTI_STATUS || status == HttpConstants.HTTP_MULTI_STATUS + + companion object { + /** + * Maximum time to wait for a response from the server in milliseconds. + */ + private const val TIMEOUT = 10000 + } +} diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/ServerService.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/ServerService.kt new file mode 100644 index 00000000..b9112209 --- /dev/null +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/ServerService.kt @@ -0,0 +1,33 @@ +/* ownCloud Android Library is available under MIT license + * Copyright (C) 2020 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.resources.server + +import com.owncloud.android.lib.common.operations.RemoteOperationResult +import com.owncloud.android.lib.resources.Service + +interface ServerService: Service { + fun checkPathExistence(path: String, isUserLogged: Boolean): RemoteOperationResult + +} From ad533c83074cb376dfa61d0ed841df4202b39fd5 Mon Sep 17 00:00:00 2001 From: abelgardep Date: Mon, 27 Jan 2020 18:33:55 +0100 Subject: [PATCH 03/15] Migrate GetRemoteStatusOperation to Kotlin --- .../server/CheckPathExistenceOperation.kt | 2 +- .../server/GetRemoteStatusOperation.kt | 170 +++++++++++++++ .../status/GetRemoteStatusOperation.java | 196 ------------------ 3 files changed, 171 insertions(+), 197 deletions(-) create mode 100644 owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/GetRemoteStatusOperation.kt delete mode 100644 owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteStatusOperation.java diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/CheckPathExistenceOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/CheckPathExistenceOperation.kt index e6f1e638..0e900dde 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/CheckPathExistenceOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/CheckPathExistenceOperation.kt @@ -44,7 +44,7 @@ import java.util.concurrent.TimeUnit * @author Abel García de Prada * * @param remotePath Path to append to the URL owned by the client instance. - * @param isUserLogged When `true`, the username won't be added at the end of the PROPFIND url since is not + * @param isUserLogged When `true`, the username won't be added at the end of the PROPFIND url since is not * needed to check user credentials */ class CheckPathExistenceOperation( diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/GetRemoteStatusOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/GetRemoteStatusOperation.kt new file mode 100644 index 00000000..6b903e33 --- /dev/null +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/GetRemoteStatusOperation.kt @@ -0,0 +1,170 @@ +/* ownCloud Android Library is available under MIT license +* Copyright (C) 2020 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.resources.server + +import android.content.Context +import android.net.ConnectivityManager +import android.net.NetworkInfo +import android.net.Uri +import com.owncloud.android.lib.common.OwnCloudClient +import com.owncloud.android.lib.common.http.HttpConstants +import com.owncloud.android.lib.common.http.methods.nonwebdav.GetMethod +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 org.json.JSONException +import org.json.JSONObject +import timber.log.Timber +import java.net.URL +import java.util.concurrent.TimeUnit +import javax.net.ssl.SSLException + +/** + * Checks if the server is valid and if the server supports the Share API + * + * @author David A. Velasco + * @author masensio + * @author David González Verdugo + */ +class GetRemoteStatusOperation(private var context: Context) : RemoteOperation() { + private lateinit var latestResult: RemoteOperationResult + + override fun run(client: OwnCloudClient): RemoteOperationResult { + + if (!isOnline) { + return RemoteOperationResult(ResultCode.NO_NETWORK_CONNECTION) + } + + val baseUriStr = client.baseUri.toString() + if (baseUriStr.startsWith(HTTP_PREFIX) || baseUriStr.startsWith(HTTPS_PREFIX)) { + tryConnection(client) + } else { + client.baseUri = Uri.parse(HTTPS_PREFIX + baseUriStr) + val httpsSuccess = tryConnection(client) + if (!httpsSuccess && !latestResult.isSslRecoverableException) { + Timber.d("Establishing secure connection failed, trying non secure connection") + client.baseUri = Uri.parse(HTTP_PREFIX + baseUriStr) + tryConnection(client) + } + } + return latestResult + } + + private fun tryConnection(client: OwnCloudClient): Boolean { + var retval = false + val baseUrlSt = client.baseUri.toString() + try { + var getMethod = GetMethod(URL(baseUrlSt + OwnCloudClient.STATUS_PATH)).apply { + setReadTimeout(TRY_CONNECTION_TIMEOUT, TimeUnit.SECONDS) + setConnectionTimeout(TRY_CONNECTION_TIMEOUT, TimeUnit.SECONDS) + } + client.setFollowRedirects(false) + var isRedirectToNonSecureConnection = false + var status: Int + try { + status = client.executeHttpMethod(getMethod) + latestResult = + if (isSuccess(status)) RemoteOperationResult(ResultCode.OK) + else RemoteOperationResult(getMethod) + } catch (sslE: SSLException) { + latestResult = RemoteOperationResult(sslE) + return false + } + var redirectedLocation = latestResult.redirectedLocation + while (redirectedLocation != null && redirectedLocation.isNotEmpty() && !latestResult.isSuccess) { + isRedirectToNonSecureConnection = + isRedirectToNonSecureConnection or + (baseUrlSt.startsWith(HTTPS_PREFIX) && redirectedLocation.startsWith(HTTP_PREFIX)) + + getMethod = GetMethod(URL(redirectedLocation)).apply { + setReadTimeout(TRY_CONNECTION_TIMEOUT, TimeUnit.SECONDS) + setConnectionTimeout(TRY_CONNECTION_TIMEOUT, TimeUnit.SECONDS) + } + status = client.executeHttpMethod(getMethod) + latestResult = RemoteOperationResult(getMethod) + redirectedLocation = latestResult.redirectedLocation + } + + if (isSuccess(status)) { + Timber.d(getMethod.responseBodyAsString) + val respJSON = JSONObject(getMethod.responseBodyAsString) + if (!respJSON.getBoolean(NODE_INSTALLED)) { + latestResult = RemoteOperationResult(ResultCode.INSTANCE_NOT_CONFIGURED) + } else { + val version = respJSON.getString(NODE_VERSION) + val ocVersion = OwnCloudVersion(version) + // the version object will be returned even if the version is invalid, no error code; + // every app will decide how to act if (ocVersion.isVersionValid() == false) + latestResult = if (isRedirectToNonSecureConnection) { + RemoteOperationResult(ResultCode.OK_REDIRECT_TO_NON_SECURE_CONNECTION) + } else { + RemoteOperationResult(if (baseUrlSt.startsWith(HTTPS_PREFIX)) ResultCode.OK_SSL else ResultCode.OK_NO_SSL) + } + latestResult.data = ocVersion + retval = true + } + } else { + latestResult = RemoteOperationResult(getMethod) + } + } catch (e: JSONException) { + latestResult = RemoteOperationResult(ResultCode.INSTANCE_NOT_CONFIGURED) + } catch (e: Exception) { + latestResult = RemoteOperationResult(e) + } + when { + latestResult.isSuccess -> { + Timber.i("Connection check at $baseUrlSt: ${latestResult.logMessage}") + } + latestResult.exception != null -> { + Timber.e(latestResult.exception, "Connection check at $baseUrlSt: ${latestResult.logMessage}") + } + else -> { + Timber.e("Connection check at $baseUrlSt: ${latestResult.logMessage}") + } + } + return retval + } + + private val isOnline: Boolean + get() { + val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager + val activeNetwork: NetworkInfo? = cm.activeNetworkInfo + return activeNetwork?.isConnected == true + } + + private fun isSuccess(status: Int): Boolean = status == HttpConstants.HTTP_OK + + companion object { + /** + * Maximum time to wait for a response from the server when the connection is being tested, + * in MILLISECONDs. + */ + const val TRY_CONNECTION_TIMEOUT: Long = 5000 + private const val NODE_INSTALLED = "installed" + private const val NODE_VERSION = "version" + private const val HTTPS_PREFIX = "https://" + private const val HTTP_PREFIX = "http://" + } +} diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteStatusOperation.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteStatusOperation.java deleted file mode 100644 index bab59562..00000000 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteStatusOperation.java +++ /dev/null @@ -1,196 +0,0 @@ -/* ownCloud Android Library is available under MIT license - * Copyright (C) 2020 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.resources.status; - -import android.content.Context; -import android.net.ConnectivityManager; -import android.net.Uri; - -import com.owncloud.android.lib.common.OwnCloudClient; -import com.owncloud.android.lib.common.http.HttpConstants; -import com.owncloud.android.lib.common.http.methods.nonwebdav.GetMethod; -import com.owncloud.android.lib.common.operations.RemoteOperation; -import com.owncloud.android.lib.common.operations.RemoteOperationResult; -import org.json.JSONException; -import org.json.JSONObject; -import timber.log.Timber; - -import javax.net.ssl.SSLException; -import java.net.URL; -import java.util.concurrent.TimeUnit; - -import static com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.OK; - -/** - * Checks if the server is valid and if the server supports the Share API - * - * @author David A. Velasco - * @author masensio - * @author David González Verdugo - */ - -public class GetRemoteStatusOperation extends RemoteOperation { - - /** - * Maximum time to wait for a response from the server when the connection is being tested, - * in MILLISECONDs. - */ - public static final long TRY_CONNECTION_TIMEOUT = 5000; - - private static final String NODE_INSTALLED = "installed"; - private static final String NODE_VERSION = "version"; - private static final String HTTPS_PREFIX = "https://"; - private static final String HTTP_PREFIX = "http://"; - - private RemoteOperationResult mLatestResult; - private Context mContext; - - public GetRemoteStatusOperation(Context context) { - mContext = context; - } - - private boolean tryConnection(OwnCloudClient client) { - boolean retval = false; - String baseUrlSt = client.getBaseUri().toString(); - try { - GetMethod getMethod = new GetMethod(new URL(baseUrlSt + OwnCloudClient.STATUS_PATH)); - - getMethod.setReadTimeout(TRY_CONNECTION_TIMEOUT, TimeUnit.SECONDS); - getMethod.setConnectionTimeout(TRY_CONNECTION_TIMEOUT, TimeUnit.SECONDS); - - client.setFollowRedirects(false); - boolean isRedirectToNonSecureConnection = false; - int status; - try { - status = client.executeHttpMethod(getMethod); - mLatestResult = isSuccess(status) - ? new RemoteOperationResult<>(OK) - : new RemoteOperationResult<>(getMethod); - } catch (SSLException sslE) { - mLatestResult = new RemoteOperationResult(sslE); - return false; - } - - String redirectedLocation = mLatestResult.getRedirectedLocation(); - while (redirectedLocation != null && redirectedLocation.length() > 0 - && !mLatestResult.isSuccess()) { - - isRedirectToNonSecureConnection |= ( - baseUrlSt.startsWith(HTTPS_PREFIX) && - redirectedLocation.startsWith(HTTP_PREFIX) - ); - - getMethod = new GetMethod(new URL(redirectedLocation)); - getMethod.setReadTimeout(TRY_CONNECTION_TIMEOUT, TimeUnit.SECONDS); - getMethod.setConnectionTimeout(TRY_CONNECTION_TIMEOUT, TimeUnit.SECONDS); - - status = client.executeHttpMethod(getMethod); - mLatestResult = new RemoteOperationResult<>(getMethod); - redirectedLocation = mLatestResult.getRedirectedLocation(); - } - - if (isSuccess(status)) { - - JSONObject respJSON = new JSONObject(getMethod.getResponseBodyAsString()); - if (!respJSON.getBoolean(NODE_INSTALLED)) { - mLatestResult = new RemoteOperationResult(RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED); - } else { - String version = respJSON.getString(NODE_VERSION); - OwnCloudVersion ocVersion = new OwnCloudVersion(version); - /// the version object will be returned even if the version is invalid, no error code; - /// every app will decide how to act if (ocVersion.isVersionValid() == false) - - if (isRedirectToNonSecureConnection) { - mLatestResult = new RemoteOperationResult<>( - RemoteOperationResult.ResultCode. - OK_REDIRECT_TO_NON_SECURE_CONNECTION); - } else { - mLatestResult = new RemoteOperationResult<>( - baseUrlSt.startsWith(HTTPS_PREFIX) ? - RemoteOperationResult.ResultCode.OK_SSL : - RemoteOperationResult.ResultCode.OK_NO_SSL); - } - - mLatestResult.setData(ocVersion); - retval = true; - } - - } else { - mLatestResult = new RemoteOperationResult<>(getMethod); - } - - } catch (JSONException e) { - mLatestResult = new RemoteOperationResult<>( - RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED); - - } catch (Exception e) { - mLatestResult = new RemoteOperationResult<>(e); - } - - if (mLatestResult.isSuccess()) { - Timber.i("Connection check at " + baseUrlSt + ": " + mLatestResult.getLogMessage()); - - } else if (mLatestResult.getException() != null) { - Timber.e(mLatestResult.getException(), "Connection check at " + baseUrlSt + ": " + mLatestResult.getLogMessage()); - - } else { - Timber.e("Connection check at " + baseUrlSt + ": " + mLatestResult.getLogMessage()); - } - - return retval; - } - - private boolean isOnline() { - ConnectivityManager cm = (ConnectivityManager) mContext - .getSystemService(Context.CONNECTIVITY_SERVICE); - return cm != null && cm.getActiveNetworkInfo() != null - && cm.getActiveNetworkInfo().isConnectedOrConnecting(); - } - - @Override - protected RemoteOperationResult run(OwnCloudClient client) { - if (!isOnline()) { - return new RemoteOperationResult<>(RemoteOperationResult.ResultCode.NO_NETWORK_CONNECTION); - } - String baseUriStr = client.getBaseUri().toString(); - if (baseUriStr.startsWith(HTTP_PREFIX) || baseUriStr.startsWith(HTTPS_PREFIX)) { - tryConnection(client); - - } else { - client.setBaseUri(Uri.parse(HTTPS_PREFIX + baseUriStr)); - boolean httpsSuccess = tryConnection(client); - if (!httpsSuccess && !mLatestResult.isSslRecoverableException()) { - Timber.d("Establishing secure connection failed, trying non secure connection"); - client.setBaseUri(Uri.parse(HTTP_PREFIX + baseUriStr)); - tryConnection(client); - } - } - return mLatestResult; - } - - private boolean isSuccess(int status) { - return (status == HttpConstants.HTTP_OK); - } -} \ No newline at end of file From ec5c9fc4aad325b3a6f2ddfffb19ecaca7da872b Mon Sep 17 00:00:00 2001 From: abelgardep Date: Mon, 27 Jan 2020 22:50:10 +0100 Subject: [PATCH 04/15] Remove ugly dependency from GetRemoteStatusOperation Create AnonymousService for operations that not require authentication --- .../lib/common/accounts/AccountUtils.java | 2 + .../lib/resources/server/AnonymousService.kt | 33 ++++++++++++ .../server/CheckPathExistenceOperation.kt | 9 ++-- .../server/GetRemoteStatusOperation.kt | 50 +++++++------------ .../lib/resources/server/ServerService.kt | 2 - 5 files changed, 56 insertions(+), 40 deletions(-) create mode 100644 owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/AnonymousService.kt diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/accounts/AccountUtils.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/accounts/AccountUtils.java index b2ab1880..fbe4d338 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/accounts/AccountUtils.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/accounts/AccountUtils.java @@ -329,5 +329,7 @@ public class AccountUtils { * OAuth2 scope */ public static final String KEY_OAUTH2_SCOPE = "oc_oauth2_scope"; + + public static final String WEBDAV_PATH_4_0_AND_LATER = "/remote.php/dav"; } } diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/AnonymousService.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/AnonymousService.kt new file mode 100644 index 00000000..ee3c5fc8 --- /dev/null +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/AnonymousService.kt @@ -0,0 +1,33 @@ +/* ownCloud Android Library is available under MIT license + * Copyright (C) 2020 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.resources.server + +import com.owncloud.android.lib.common.operations.RemoteOperationResult +import com.owncloud.android.lib.resources.status.OwnCloudVersion + +interface AnonymousService { + fun checkPathExistence(path: String, isUserLogged: Boolean): RemoteOperationResult + + fun getRemoteStatus(path: String): RemoteOperationResult +} diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/CheckPathExistenceOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/CheckPathExistenceOperation.kt index 0e900dde..051d7691 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/CheckPathExistenceOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/CheckPathExistenceOperation.kt @@ -56,7 +56,7 @@ class CheckPathExistenceOperation( * * @return Sequence of redirections followed, if any, or NULL if the operation was not executed. */ - var redirectionPath: RedirectionPath? = null + lateinit var redirectionPath: RedirectionPath private set override fun run(client: OwnCloudClient): RemoteOperationResult { @@ -75,7 +75,7 @@ class CheckPathExistenceOperation( var status = client.executeHttpMethod(propFindMethod) if (previousFollowRedirects) { redirectionPath = client.followRedirection(propFindMethod) - status = redirectionPath?.lastStatus!! + status = redirectionPath.lastStatus } /* PROPFIND method * 404 NOT FOUND: path doesn't exist, @@ -103,10 +103,9 @@ class CheckPathExistenceOperation( /** * @return 'True' if the operation was executed and at least one redirection was followed. */ - fun wasRedirected() = redirectionPath != null && redirectionPath!!.redirectionsCount > 0 + fun wasRedirected() = redirectionPath.redirectionsCount > 0 - private fun isSuccess(status: Int) = - status == HttpConstants.HTTP_OK || status == HttpConstants.HTTP_MULTI_STATUS || status == HttpConstants.HTTP_MULTI_STATUS + private fun isSuccess(status: Int) = status == HttpConstants.HTTP_OK || status == HttpConstants.HTTP_MULTI_STATUS companion object { /** diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/GetRemoteStatusOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/GetRemoteStatusOperation.kt index 6b903e33..4a92e93b 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/GetRemoteStatusOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/GetRemoteStatusOperation.kt @@ -23,9 +23,6 @@ */ package com.owncloud.android.lib.resources.server -import android.content.Context -import android.net.ConnectivityManager -import android.net.NetworkInfo import android.net.Uri import com.owncloud.android.lib.common.OwnCloudClient import com.owncloud.android.lib.common.http.HttpConstants @@ -42,21 +39,18 @@ import java.util.concurrent.TimeUnit import javax.net.ssl.SSLException /** - * Checks if the server is valid and if the server supports the Share API + * Checks if the server is valid * * @author David A. Velasco * @author masensio * @author David González Verdugo + * @author Abel García de Prada */ -class GetRemoteStatusOperation(private var context: Context) : RemoteOperation() { +class GetRemoteStatusOperation : RemoteOperation() { private lateinit var latestResult: RemoteOperationResult override fun run(client: OwnCloudClient): RemoteOperationResult { - if (!isOnline) { - return RemoteOperationResult(ResultCode.NO_NETWORK_CONNECTION) - } - val baseUriStr = client.baseUri.toString() if (baseUriStr.startsWith(HTTP_PREFIX) || baseUriStr.startsWith(HTTPS_PREFIX)) { tryConnection(client) @@ -73,7 +67,7 @@ class GetRemoteStatusOperation(private var context: Context) : RemoteOperation { - Timber.i("Connection check at $baseUrlSt: ${latestResult.logMessage}") - } - latestResult.exception != null -> { - Timber.e(latestResult.exception, "Connection check at $baseUrlSt: ${latestResult.logMessage}") - } - else -> { - Timber.e("Connection check at $baseUrlSt: ${latestResult.logMessage}") - } - } - return retval - } + latestResult.isSuccess -> Timber.i("Connection check at $baseUrlSt: ${latestResult.logMessage}") - private val isOnline: Boolean - get() { - val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager - val activeNetwork: NetworkInfo? = cm.activeNetworkInfo - return activeNetwork?.isConnected == true + latestResult.isException -> + Timber.e(latestResult.exception, "Connection check at $baseUrlSt: ${latestResult.logMessage}") + + else -> Timber.e("Connection check at $baseUrlSt: ${latestResult.logMessage}") } + return successfulConnection + } private fun isSuccess(status: Int): Boolean = status == HttpConstants.HTTP_OK @@ -161,7 +145,7 @@ class GetRemoteStatusOperation(private var context: Context) : RemoteOperation - } From 3829a1ca32a9d97b9b48b80138d552d574a20ab7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abel=20Garc=C3=ADa=20de=20Prada?= Date: Mon, 3 Feb 2020 15:28:49 +0100 Subject: [PATCH 05/15] Start working on login usecase --- .../lib/common/operations/RemoteOperationResult.java | 6 +++--- .../lib/resources/server/CheckPathExistenceOperation.kt | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationResult.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationResult.java index 0673fc0a..881aa0d2 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationResult.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationResult.java @@ -66,7 +66,7 @@ public class RemoteOperationResult private Exception mException = null; private ResultCode mCode = ResultCode.UNKNOWN_ERROR; private String mRedirectedLocation; - private ArrayList mAuthenticate = new ArrayList<>(); + private String mAuthenticate; private String mLastPermanentLocation = null; private T mData = null; @@ -253,7 +253,7 @@ public class RemoteOperationResult continue; } if ("www-authenticate".equals(header.getKey().toLowerCase())) { - mAuthenticate.add(header.getValue().get(0).toLowerCase()); + mAuthenticate = header.getValue().get(0).toLowerCase(); } } } @@ -494,7 +494,7 @@ public class RemoteOperationResult return (mRedirectedLocation != null && !(mRedirectedLocation.toLowerCase().startsWith("https://"))); } - public ArrayList getAuthenticateHeaders() { + public String getAuthenticateHeaders() { return mAuthenticate; } diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/CheckPathExistenceOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/CheckPathExistenceOperation.kt index 051d7691..9f5636c0 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/CheckPathExistenceOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/CheckPathExistenceOperation.kt @@ -56,7 +56,7 @@ class CheckPathExistenceOperation( * * @return Sequence of redirections followed, if any, or NULL if the operation was not executed. */ - lateinit var redirectionPath: RedirectionPath + var redirectionPath: RedirectionPath? = null private set override fun run(client: OwnCloudClient): RemoteOperationResult { @@ -75,7 +75,7 @@ class CheckPathExistenceOperation( var status = client.executeHttpMethod(propFindMethod) if (previousFollowRedirects) { redirectionPath = client.followRedirection(propFindMethod) - status = redirectionPath.lastStatus + status = redirectionPath?.lastStatus!! } /* PROPFIND method * 404 NOT FOUND: path doesn't exist, @@ -103,7 +103,7 @@ class CheckPathExistenceOperation( /** * @return 'True' if the operation was executed and at least one redirection was followed. */ - fun wasRedirected() = redirectionPath.redirectionsCount > 0 + fun wasRedirected() = (redirectionPath!=null && redirectionPath!!.redirectionsCount > 0) private fun isSuccess(status: Int) = status == HttpConstants.HTTP_OK || status == HttpConstants.HTTP_MULTI_STATUS From 4f07187fa2c9844e0483c9a382b67d55f8e2bf47 Mon Sep 17 00:00:00 2001 From: agarcia Date: Fri, 7 Feb 2020 11:38:25 +0100 Subject: [PATCH 06/15] Rename remote operations --- .../files/RenameRemoteFileOperation.java | 7 ++++--- .../lib/resources/server/AnonymousService.kt | 2 +- ...t => CheckPathExistenceRemoteOperation.kt} | 19 +++++++++---------- ...eration.kt => GetStatusRemoteOperation.kt} | 2 +- .../lib/resources/server/ServerService.kt | 2 +- ...ation.kt => GetUserInfoRemoteOperation.kt} | 2 +- 6 files changed, 17 insertions(+), 17 deletions(-) rename owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/{CheckPathExistenceOperation.kt => CheckPathExistenceRemoteOperation.kt} (88%) rename owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/{GetRemoteStatusOperation.kt => GetStatusRemoteOperation.kt} (99%) rename owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/{GetRemoteUserInfoOperation.kt => GetUserInfoRemoteOperation.kt} (98%) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RenameRemoteFileOperation.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RenameRemoteFileOperation.java index 4c87ef3e..58e6256c 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RenameRemoteFileOperation.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RenameRemoteFileOperation.java @@ -31,7 +31,7 @@ import com.owncloud.android.lib.common.network.WebdavUtils; 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.server.CheckPathExistenceOperation; +import com.owncloud.android.lib.resources.server.CheckPathExistenceRemoteOperation; import timber.log.Timber; import java.io.File; @@ -124,8 +124,9 @@ public class RenameRemoteFileOperation extends RemoteOperation { * @return 'True' if the target path is already used by an existing file. */ private boolean targetPathIsUsed(OwnCloudClient client) { - CheckPathExistenceOperation checkPathExistenceOperation = new CheckPathExistenceOperation(mNewRemotePath, false); - RemoteOperationResult exists = checkPathExistenceOperation.execute(client); + CheckPathExistenceRemoteOperation checkPathExistenceRemoteOperation = + new CheckPathExistenceRemoteOperation(mNewRemotePath, false); + RemoteOperationResult exists = checkPathExistenceRemoteOperation.execute(client); return exists.isSuccess(); } } \ No newline at end of file diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/AnonymousService.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/AnonymousService.kt index ee3c5fc8..53f9fe87 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/AnonymousService.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/AnonymousService.kt @@ -27,7 +27,7 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.lib.resources.status.OwnCloudVersion interface AnonymousService { - fun checkPathExistence(path: String, isUserLogged: Boolean): RemoteOperationResult + fun checkPathExistence(path: String, isUserLogged: Boolean): RemoteOperationResult fun getRemoteStatus(path: String): RemoteOperationResult } diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/CheckPathExistenceOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/CheckPathExistenceRemoteOperation.kt similarity index 88% rename from owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/CheckPathExistenceOperation.kt rename to owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/CheckPathExistenceRemoteOperation.kt index 9f5636c0..a91b133a 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/CheckPathExistenceOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/CheckPathExistenceRemoteOperation.kt @@ -47,10 +47,10 @@ import java.util.concurrent.TimeUnit * @param isUserLogged When `true`, the username won't be added at the end of the PROPFIND url since is not * needed to check user credentials */ -class CheckPathExistenceOperation( +class CheckPathExistenceRemoteOperation( val remotePath: String? = "", val isUserLogged: Boolean -) : RemoteOperation() { +) : RemoteOperation() { /** * Gets the sequence of redirections followed during the execution of the operation. * @@ -59,7 +59,7 @@ class CheckPathExistenceOperation( var redirectionPath: RedirectionPath? = null private set - override fun run(client: OwnCloudClient): RemoteOperationResult { + override fun run(client: OwnCloudClient): RemoteOperationResult { val previousFollowRedirects = client.followRedirects() return try { val stringUrl = @@ -82,14 +82,13 @@ class CheckPathExistenceOperation( * 207 MULTI_STATUS: path exists. */ Timber.d( - "Existence check for $stringUrl${WebdavUtils.encodePath(remotePath)} finished with HTTP status $status${if (!isSuccess( - status - ) - ) "(FAIL)" else ""}" + "Existence check for $stringUrl finished with HTTP status $status${if (!isSuccess(status)) "(FAIL)" else ""}" ) - if (isSuccess(status)) RemoteOperationResult(ResultCode.OK) else RemoteOperationResult(propFindMethod) + if (isSuccess(status)) RemoteOperationResult(ResultCode.OK).apply { data = true } + else RemoteOperationResult(propFindMethod).apply { data = false } + } catch (e: Exception) { - val result = RemoteOperationResult(e) + val result = RemoteOperationResult(e) Timber.e( e, "Existence check for ${client.userFilesWebDavUri}${WebdavUtils.encodePath(remotePath)} : ${result.logMessage}" @@ -103,7 +102,7 @@ class CheckPathExistenceOperation( /** * @return 'True' if the operation was executed and at least one redirection was followed. */ - fun wasRedirected() = (redirectionPath!=null && redirectionPath!!.redirectionsCount > 0) + fun wasRedirected() = redirectionPath?.redirectionsCount ?: 0 > 0 private fun isSuccess(status: Int) = status == HttpConstants.HTTP_OK || status == HttpConstants.HTTP_MULTI_STATUS diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/GetRemoteStatusOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/GetStatusRemoteOperation.kt similarity index 99% rename from owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/GetRemoteStatusOperation.kt rename to owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/GetStatusRemoteOperation.kt index 4a92e93b..76a6def9 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/GetRemoteStatusOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/GetStatusRemoteOperation.kt @@ -46,7 +46,7 @@ import javax.net.ssl.SSLException * @author David González Verdugo * @author Abel García de Prada */ -class GetRemoteStatusOperation : RemoteOperation() { +class GetStatusRemoteOperation : RemoteOperation() { private lateinit var latestResult: RemoteOperationResult override fun run(client: OwnCloudClient): RemoteOperationResult { diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/ServerService.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/ServerService.kt index d6bbbfbb..ed994147 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/ServerService.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/ServerService.kt @@ -27,5 +27,5 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.lib.resources.Service interface ServerService: Service { - fun checkPathExistence(path: String, isUserLogged: Boolean): RemoteOperationResult + fun checkPathExistence(path: String, isUserLogged: Boolean): RemoteOperationResult } diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/GetRemoteUserInfoOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/GetUserInfoRemoteOperation.kt similarity index 98% rename from owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/GetRemoteUserInfoOperation.kt rename to owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/GetUserInfoRemoteOperation.kt index a406e6cb..f670e88d 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/GetRemoteUserInfoOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/GetUserInfoRemoteOperation.kt @@ -45,7 +45,7 @@ import java.net.URL * @author David González Verdugo * @author Abel García de Prada */ -class GetRemoteUserInfoOperation : RemoteOperation() { +class GetUserInfoRemoteOperation : RemoteOperation() { override fun run(client: OwnCloudClient): RemoteOperationResult { var result: RemoteOperationResult //Get the user From 1536a455a630c83f652216a32caf47d2548869ec Mon Sep 17 00:00:00 2001 From: agarcia Date: Thu, 13 Feb 2020 13:40:12 +0100 Subject: [PATCH 07/15] Move constants and utils to proper files --- .../android/lib/common/OwnCloudClient.java | 1 + .../lib/common/accounts/AccountUtils.java | 2 -- .../lib/common/network/WebdavUtils.java | 29 +++++++++++++++++++ .../lib/resources/CommonOcsResponse.kt | 2 ++ ...eration.kt => GetRemoteStatusOperation.kt} | 2 +- ...ation.kt => GetRemoteUserInfoOperation.kt} | 2 +- 6 files changed, 34 insertions(+), 4 deletions(-) rename owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/{GetStatusRemoteOperation.kt => GetRemoteStatusOperation.kt} (99%) rename owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/{GetUserInfoRemoteOperation.kt => GetRemoteUserInfoOperation.kt} (98%) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClient.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClient.java index 5c4ae8e6..1fc9ca94 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClient.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClient.java @@ -53,6 +53,7 @@ import static com.owncloud.android.lib.common.http.HttpConstants.OC_X_REQUEST_ID public class OwnCloudClient extends HttpClient { public static final String WEBDAV_FILES_PATH_4_0 = "/remote.php/dav/files/"; + public static final String WEBDAV_PATH_4_0_AND_LATER = "/remote.php/dav"; private static final String WEBDAV_UPLOADS_PATH_4_0 = "/remote.php/dav/uploads/"; public static final String STATUS_PATH = "/status.php"; diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/accounts/AccountUtils.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/accounts/AccountUtils.java index fbe4d338..b2ab1880 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/accounts/AccountUtils.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/accounts/AccountUtils.java @@ -329,7 +329,5 @@ public class AccountUtils { * OAuth2 scope */ public static final String KEY_OAUTH2_SCOPE = "oc_oauth2_scope"; - - public static final String WEBDAV_PATH_4_0_AND_LATER = "/remote.php/dav"; } } diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/network/WebdavUtils.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/network/WebdavUtils.java index 45b7f35f..51f4d9b3 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/network/WebdavUtils.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/network/WebdavUtils.java @@ -34,6 +34,8 @@ import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; +import static com.owncloud.android.lib.common.OwnCloudClient.WEBDAV_PATH_4_0_AND_LATER; + public class WebdavUtils { public static final SimpleDateFormat DISPLAY_DATE_FORMAT = new SimpleDateFormat( "dd.MM.yyyy hh:mm"); @@ -120,4 +122,31 @@ public class WebdavUtils { } return result; } + + public static String trimWebdavSuffix(String url) { + if (url == null) { + url = ""; + } else { + if (url.endsWith("/")) { + url = url.substring(0, url.length() - 1); + } + if (url.toLowerCase().endsWith(WEBDAV_PATH_4_0_AND_LATER)) { + url = url.substring(0, url.length() - WEBDAV_PATH_4_0_AND_LATER.length()); + } + } + return url; + } + + public static String normalizeProtocolPrefix(String url, boolean isSslConn) { + if (!url.toLowerCase().startsWith("http://") && + !url.toLowerCase().startsWith("https://")) { + if (isSslConn) { + return "https://" + url; + } else { + return "http://" + url; + } + } + return url; + } + } \ No newline at end of file diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/CommonOcsResponse.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/CommonOcsResponse.kt index f0bb805e..2cfbe2ed 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/CommonOcsResponse.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/CommonOcsResponse.kt @@ -25,6 +25,8 @@ package com.owncloud.android.lib.resources import com.squareup.moshi.JsonClass +// Response retrieved by OCS Rest API, used to obtain capabilities, shares and user info among others. +// More info: https://doc.owncloud.com/server/developer_manual/core/apis/ocs-capabilities.html @JsonClass(generateAdapter = true) data class CommonOcsResponse( val ocs: OCSResponse diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/GetStatusRemoteOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/GetRemoteStatusOperation.kt similarity index 99% rename from owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/GetStatusRemoteOperation.kt rename to owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/GetRemoteStatusOperation.kt index 76a6def9..4a92e93b 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/GetStatusRemoteOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/GetRemoteStatusOperation.kt @@ -46,7 +46,7 @@ import javax.net.ssl.SSLException * @author David González Verdugo * @author Abel García de Prada */ -class GetStatusRemoteOperation : RemoteOperation() { +class GetRemoteStatusOperation : RemoteOperation() { private lateinit var latestResult: RemoteOperationResult override fun run(client: OwnCloudClient): RemoteOperationResult { diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/GetUserInfoRemoteOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/GetRemoteUserInfoOperation.kt similarity index 98% rename from owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/GetUserInfoRemoteOperation.kt rename to owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/GetRemoteUserInfoOperation.kt index f670e88d..a406e6cb 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/GetUserInfoRemoteOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/GetRemoteUserInfoOperation.kt @@ -45,7 +45,7 @@ import java.net.URL * @author David González Verdugo * @author Abel García de Prada */ -class GetUserInfoRemoteOperation : RemoteOperation() { +class GetRemoteUserInfoOperation : RemoteOperation() { override fun run(client: OwnCloudClient): RemoteOperationResult { var result: RemoteOperationResult //Get the user From 7e6b63db1f5e4aaa6af7f77cb92956690b38cf19 Mon Sep 17 00:00:00 2001 From: agarcia Date: Tue, 18 Feb 2020 12:33:39 +0100 Subject: [PATCH 08/15] A little cleanup and improve some log messages --- .../lib/common/network/WebdavUtils.java | 29 ++++--------------- .../server/GetRemoteStatusOperation.kt | 9 ++++-- .../users/GetRemoteUserInfoOperation.kt | 2 +- 3 files changed, 12 insertions(+), 28 deletions(-) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/network/WebdavUtils.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/network/WebdavUtils.java index 51f4d9b3..8d7e6572 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/network/WebdavUtils.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/network/WebdavUtils.java @@ -37,10 +37,8 @@ import java.util.Locale; import static com.owncloud.android.lib.common.OwnCloudClient.WEBDAV_PATH_4_0_AND_LATER; public class WebdavUtils { - public static final SimpleDateFormat DISPLAY_DATE_FORMAT = new SimpleDateFormat( - "dd.MM.yyyy hh:mm"); - private static final SimpleDateFormat DATETIME_FORMATS[] = { + private static final SimpleDateFormat[] DATETIME_FORMATS = { new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US), new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US), new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.sss'Z'", Locale.US), @@ -52,11 +50,11 @@ public class WebdavUtils { }; public static Date parseResponseDate(String date) { - Date returnDate = null; - SimpleDateFormat format = null; - for (int i = 0; i < DATETIME_FORMATS.length; ++i) { + Date returnDate; + SimpleDateFormat format; + for (SimpleDateFormat datetimeFormat : DATETIME_FORMATS) { try { - format = DATETIME_FORMATS[i]; + format = datetimeFormat; synchronized (format) { returnDate = format.parse(date); } @@ -84,23 +82,6 @@ public class WebdavUtils { return encodedPath; } - /** - * @param rawEtag - * @return - */ - public static String parseEtag(String rawEtag) { - if (rawEtag == null || rawEtag.length() == 0) { - return ""; - } - if (rawEtag.endsWith("-gzip")) { - rawEtag = rawEtag.substring(0, rawEtag.length() - 5); - } - if (rawEtag.length() >= 2 && rawEtag.startsWith("\"") && rawEtag.endsWith("\"")) { - rawEtag = rawEtag.substring(1, rawEtag.length() - 1); - } - return rawEtag; - } - /** * @param httpBaseMethod from which to get the etag * @return etag from response diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/GetRemoteStatusOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/GetRemoteStatusOperation.kt index 4a92e93b..97c6bad3 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/GetRemoteStatusOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/GetRemoteStatusOperation.kt @@ -82,20 +82,23 @@ class GetRemoteStatusOperation : RemoteOperation() { latestResult = if (isSuccess(status)) RemoteOperationResult(ResultCode.OK) else RemoteOperationResult(getMethod) + } catch (sslE: SSLException) { latestResult = RemoteOperationResult(sslE) return successfulConnection } + var redirectedLocation = latestResult.redirectedLocation while (!redirectedLocation.isNullOrEmpty() && !latestResult.isSuccess) { isRedirectToNonSecureConnection = - isRedirectToNonSecureConnection or + isRedirectToNonSecureConnection || (baseUrlSt.startsWith(HTTPS_PREFIX) && redirectedLocation.startsWith(HTTP_PREFIX)) getMethod = GetMethod(URL(redirectedLocation)).apply { setReadTimeout(TRY_CONNECTION_TIMEOUT, TimeUnit.SECONDS) setConnectionTimeout(TRY_CONNECTION_TIMEOUT, TimeUnit.SECONDS) } + status = client.executeHttpMethod(getMethod) latestResult = RemoteOperationResult(getMethod) redirectedLocation = latestResult.redirectedLocation @@ -128,12 +131,12 @@ class GetRemoteStatusOperation : RemoteOperation() { latestResult = RemoteOperationResult(e) } when { - latestResult.isSuccess -> Timber.i("Connection check at $baseUrlSt: ${latestResult.logMessage}") + latestResult.isSuccess -> Timber.i("Connection check at $baseUrlSt successful: ${latestResult.logMessage}") latestResult.isException -> Timber.e(latestResult.exception, "Connection check at $baseUrlSt: ${latestResult.logMessage}") - else -> Timber.e("Connection check at $baseUrlSt: ${latestResult.logMessage}") + else -> Timber.e("Connection check at $baseUrlSt failed: ${latestResult.logMessage}") } return successfulConnection } diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/GetRemoteUserInfoOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/GetRemoteUserInfoOperation.kt index a406e6cb..54aeb32f 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/GetRemoteUserInfoOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/GetRemoteUserInfoOperation.kt @@ -62,7 +62,7 @@ class GetRemoteUserInfoOperation : RemoteOperation() { val commonResponse: CommonOcsResponse? = adapter.fromJson(response) result = RemoteOperationResult(ResultCode.OK) - result.setData(commonResponse?.ocs?.data?.toRemoteUserInfo()) + result.data = commonResponse?.ocs?.data?.toRemoteUserInfo() } else { result = RemoteOperationResult(getMethod) Timber.e("Failed response while getting user information status code: $status, response: $response") From d2ee1294f2016a81de22c2d662b06a2e36266af2 Mon Sep 17 00:00:00 2001 From: agarcia Date: Tue, 18 Feb 2020 16:32:10 +0100 Subject: [PATCH 09/15] Rename services --- .../CheckPathExistenceRemoteOperation.kt | 2 +- .../{server/ServerService.kt => files/FileService.kt} | 4 ++-- .../resources/files/RenameRemoteFileOperation.java | 1 - .../{server => status}/GetRemoteStatusOperation.kt | 11 +++++++---- .../ServerInfoService.kt} | 4 ++-- 5 files changed, 12 insertions(+), 10 deletions(-) rename owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/{server => files}/CheckPathExistenceRemoteOperation.kt (99%) rename owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/{server/ServerService.kt => files/FileService.kt} (94%) rename owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/{server => status}/GetRemoteStatusOperation.kt (97%) rename owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/{server/AnonymousService.kt => status/ServerInfoService.kt} (95%) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/CheckPathExistenceRemoteOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/CheckPathExistenceRemoteOperation.kt similarity index 99% rename from owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/CheckPathExistenceRemoteOperation.kt rename to owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/CheckPathExistenceRemoteOperation.kt index a91b133a..aafa5fc7 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/CheckPathExistenceRemoteOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/CheckPathExistenceRemoteOperation.kt @@ -21,7 +21,7 @@ * THE SOFTWARE. * */ -package com.owncloud.android.lib.resources.server +package com.owncloud.android.lib.resources.files import com.owncloud.android.lib.common.OwnCloudClient import com.owncloud.android.lib.common.http.HttpConstants diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/ServerService.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/FileService.kt similarity index 94% rename from owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/ServerService.kt rename to owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/FileService.kt index ed994147..2da5bf8f 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/ServerService.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/FileService.kt @@ -21,11 +21,11 @@ * THE SOFTWARE. * */ -package com.owncloud.android.lib.resources.server +package com.owncloud.android.lib.resources.files import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.lib.resources.Service -interface ServerService: Service { +interface FileService: Service { fun checkPathExistence(path: String, isUserLogged: Boolean): RemoteOperationResult } diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RenameRemoteFileOperation.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RenameRemoteFileOperation.java index 58e6256c..90a9c469 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RenameRemoteFileOperation.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RenameRemoteFileOperation.java @@ -31,7 +31,6 @@ import com.owncloud.android.lib.common.network.WebdavUtils; 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.server.CheckPathExistenceRemoteOperation; import timber.log.Timber; import java.io.File; diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/GetRemoteStatusOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteStatusOperation.kt similarity index 97% rename from owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/GetRemoteStatusOperation.kt rename to owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteStatusOperation.kt index 97c6bad3..b6fd1b39 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/GetRemoteStatusOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteStatusOperation.kt @@ -21,7 +21,7 @@ * THE SOFTWARE. * */ -package com.owncloud.android.lib.resources.server +package com.owncloud.android.lib.resources.status import android.net.Uri import com.owncloud.android.lib.common.OwnCloudClient @@ -30,7 +30,6 @@ import com.owncloud.android.lib.common.http.methods.nonwebdav.GetMethod 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 org.json.JSONException import org.json.JSONObject import timber.log.Timber @@ -52,7 +51,9 @@ class GetRemoteStatusOperation : RemoteOperation() { override fun run(client: OwnCloudClient): RemoteOperationResult { val baseUriStr = client.baseUri.toString() - if (baseUriStr.startsWith(HTTP_PREFIX) || baseUriStr.startsWith(HTTPS_PREFIX)) { + if (baseUriStr.startsWith(HTTP_PREFIX) || baseUriStr.startsWith( + HTTPS_PREFIX + )) { tryConnection(client) } else { client.baseUri = Uri.parse(HTTPS_PREFIX + baseUriStr) @@ -92,7 +93,9 @@ class GetRemoteStatusOperation : RemoteOperation() { while (!redirectedLocation.isNullOrEmpty() && !latestResult.isSuccess) { isRedirectToNonSecureConnection = isRedirectToNonSecureConnection || - (baseUrlSt.startsWith(HTTPS_PREFIX) && redirectedLocation.startsWith(HTTP_PREFIX)) + (baseUrlSt.startsWith(HTTPS_PREFIX) && redirectedLocation.startsWith( + HTTP_PREFIX + )) getMethod = GetMethod(URL(redirectedLocation)).apply { setReadTimeout(TRY_CONNECTION_TIMEOUT, TimeUnit.SECONDS) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/AnonymousService.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/ServerInfoService.kt similarity index 95% rename from owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/AnonymousService.kt rename to owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/ServerInfoService.kt index 53f9fe87..c211c8ff 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/server/AnonymousService.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/ServerInfoService.kt @@ -21,12 +21,12 @@ * THE SOFTWARE. * */ -package com.owncloud.android.lib.resources.server +package com.owncloud.android.lib.resources.status import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.lib.resources.status.OwnCloudVersion -interface AnonymousService { +interface ServerInfoService { fun checkPathExistence(path: String, isUserLogged: Boolean): RemoteOperationResult fun getRemoteStatus(path: String): RemoteOperationResult From c6e88b127c4d1818ca363edbc22f26d620c86ac6 Mon Sep 17 00:00:00 2001 From: agarcia Date: Mon, 24 Feb 2020 11:33:00 +0100 Subject: [PATCH 10/15] Fix a potential null pointer exception --- .../java/com/owncloud/android/lib/common/OwnCloudClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClient.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClient.java index 1fc9ca94..3ab812d4 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClient.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClient.java @@ -231,7 +231,7 @@ public class OwnCloudClient extends HttpClient { } public Uri getUserFilesWebDavUri() { - return mCredentials instanceof OwnCloudAnonymousCredentials + return (mCredentials instanceof OwnCloudAnonymousCredentials || mAccount == null) ? Uri.parse(mBaseUri + WEBDAV_FILES_PATH_4_0) : Uri.parse(mBaseUri + WEBDAV_FILES_PATH_4_0 + AccountUtils.getUserId( mAccount.getSavedAccount(), getContext() From 0028d63292b038f195f2e2ca465d170a36b7b665 Mon Sep 17 00:00:00 2001 From: davigonz Date: Wed, 26 Feb 2020 10:38:09 +0100 Subject: [PATCH 11/15] Create account version constant --- .../com/owncloud/android/lib/common/accounts/AccountUtils.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/accounts/AccountUtils.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/accounts/AccountUtils.java index b2ab1880..5b57023d 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/accounts/AccountUtils.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/accounts/AccountUtils.java @@ -47,6 +47,8 @@ import java.util.List; public class AccountUtils { + public static final int ACCOUNT_VERSION = 1; + /** * Constructs full url to host and webdav resource basing on host version * From cf06126ce1fe9b01292003a5c836f868d8be521f Mon Sep 17 00:00:00 2001 From: davigonz Date: Wed, 4 Mar 2020 19:03:48 +0100 Subject: [PATCH 12/15] Move account version constant to a better place within AccountUtils --- .../owncloud/android/lib/common/accounts/AccountUtils.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/accounts/AccountUtils.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/accounts/AccountUtils.java index 5b57023d..19b3b277 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/accounts/AccountUtils.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/accounts/AccountUtils.java @@ -46,9 +46,6 @@ import java.util.ArrayList; import java.util.List; public class AccountUtils { - - public static final int ACCOUNT_VERSION = 1; - /** * Constructs full url to host and webdav resource basing on host version * @@ -331,5 +328,7 @@ public class AccountUtils { * OAuth2 scope */ public static final String KEY_OAUTH2_SCOPE = "oc_oauth2_scope"; + + public static final int ACCOUNT_VERSION = 1; } } From bec5643714108f0398a5e53bae924b18617c0110 Mon Sep 17 00:00:00 2001 From: davigonz Date: Thu, 5 Mar 2020 13:10:46 +0100 Subject: [PATCH 13/15] Include services implementation so that can be used by library users --- .../files/{ => services}/FileService.kt | 2 +- .../services/implementation/OCFileService.kt | 34 +++++++ .../shares/{ => services}/ShareService.kt | 4 +- .../shares/{ => services}/ShareeService.kt | 2 +- .../services/implementation/OCShareService.kt | 91 +++++++++++++++++++ .../implementation/OCShareeService.kt | 42 +++++++++ .../{ => services}/CapabilityService.kt | 3 +- .../{ => services}/ServerInfoService.kt | 2 +- .../implementation/OCCapabilityService.kt | 33 +++++++ .../implementation/OCServerInfoService.kt | 43 +++++++++ .../users/{ => services}/UserService.kt | 3 +- .../services/implementation/OCUserService.kt | 32 +++++++ 12 files changed, 285 insertions(+), 6 deletions(-) rename owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/{ => services}/FileService.kt (96%) create mode 100644 owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/implementation/OCFileService.kt rename owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/{ => services}/ShareService.kt (89%) rename owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/{ => services}/ShareeService.kt (94%) create mode 100644 owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/services/implementation/OCShareService.kt create mode 100644 owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/services/implementation/OCShareeService.kt rename owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/{ => services}/CapabilityService.kt (88%) rename owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/{ => services}/ServerInfoService.kt (96%) create mode 100644 owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/services/implementation/OCCapabilityService.kt create mode 100644 owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/services/implementation/OCServerInfoService.kt rename owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/{ => services}/UserService.kt (92%) create mode 100644 owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/services/implementation/OCUserService.kt diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/FileService.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/FileService.kt similarity index 96% rename from owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/FileService.kt rename to owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/FileService.kt index 2da5bf8f..aa69d505 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/FileService.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/FileService.kt @@ -21,7 +21,7 @@ * THE SOFTWARE. * */ -package com.owncloud.android.lib.resources.files +package com.owncloud.android.lib.resources.files.services import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.lib.resources.Service diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/implementation/OCFileService.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/implementation/OCFileService.kt new file mode 100644 index 00000000..abe1e2e6 --- /dev/null +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/implementation/OCFileService.kt @@ -0,0 +1,34 @@ +/** + * ownCloud Android client application + * + * @author Abel García de Prada + * Copyright (C) 2020 ownCloud GmbH. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.owncloud.android.lib.resources.files.services.implementation + +import com.owncloud.android.lib.common.OwnCloudClient +import com.owncloud.android.lib.common.operations.RemoteOperationResult +import com.owncloud.android.lib.resources.files.CheckPathExistenceRemoteOperation +import com.owncloud.android.lib.resources.files.services.FileService + +class OCFileService(override val client: OwnCloudClient) : + FileService { + override fun checkPathExistence(path: String, isUserLogged: Boolean): RemoteOperationResult = + CheckPathExistenceRemoteOperation( + remotePath = path, + isUserLogged = isUserLogged + ).execute(client) +} diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareService.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/services/ShareService.kt similarity index 89% rename from owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareService.kt rename to owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/services/ShareService.kt index c0047fa8..38980256 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareService.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/services/ShareService.kt @@ -18,10 +18,12 @@ * along with this program. If not, see . */ -package com.owncloud.android.lib.resources.shares +package com.owncloud.android.lib.resources.shares.services import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.lib.resources.Service +import com.owncloud.android.lib.resources.shares.ShareParserResult +import com.owncloud.android.lib.resources.shares.ShareType interface ShareService : Service { fun getShares( diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareeService.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/services/ShareeService.kt similarity index 94% rename from owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareeService.kt rename to owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/services/ShareeService.kt index 8e7c8964..ab6d9e83 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareeService.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/services/ShareeService.kt @@ -18,7 +18,7 @@ * along with this program. If not, see . */ -package com.owncloud.android.lib.resources.shares +package com.owncloud.android.lib.resources.shares.services import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.lib.resources.Service diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/services/implementation/OCShareService.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/services/implementation/OCShareService.kt new file mode 100644 index 00000000..a22919bf --- /dev/null +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/services/implementation/OCShareService.kt @@ -0,0 +1,91 @@ +/** + * ownCloud Android client application + * + * @author David González Verdugo + * + * Copyright (C) 2020 ownCloud GmbH. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.owncloud.android.lib.resources.shares.services.implementation + +import com.owncloud.android.lib.common.OwnCloudClient +import com.owncloud.android.lib.common.operations.RemoteOperationResult +import com.owncloud.android.lib.resources.shares.CreateRemoteShareOperation +import com.owncloud.android.lib.resources.shares.GetRemoteSharesForFileOperation +import com.owncloud.android.lib.resources.shares.RemoveRemoteShareOperation +import com.owncloud.android.lib.resources.shares.ShareParserResult +import com.owncloud.android.lib.resources.shares.ShareType +import com.owncloud.android.lib.resources.shares.UpdateRemoteShareOperation +import com.owncloud.android.lib.resources.shares.services.ShareService + +class OCShareService(override val client: OwnCloudClient) : + ShareService { + override fun getShares( + remoteFilePath: String, + reshares: Boolean, + subfiles: Boolean + ): RemoteOperationResult = GetRemoteSharesForFileOperation( + remoteFilePath, + reshares, + subfiles + ).execute(client) + + override fun insertShare( + remoteFilePath: String, + shareType: ShareType, + shareWith: String, + permissions: Int, + name: String, + password: String, + expirationDate: Long, + publicUpload: Boolean + ): RemoteOperationResult = + CreateRemoteShareOperation( + remoteFilePath, + shareType, + shareWith, + permissions + ).apply { + this.name = name + this.password = password + this.expirationDateInMillis = expirationDate + this.publicUpload = publicUpload + this.retrieveShareDetails = true + }.execute(client) + + override fun updateShare( + remoteId: Long, + name: String, + password: String?, + expirationDate: Long, + permissions: Int, + publicUpload: Boolean + ): RemoteOperationResult = + UpdateRemoteShareOperation( + remoteId + ).apply { + this.name = name + this.password = password + this.expirationDateInMillis = expirationDate + this.permissions = permissions + this.publicUpload = publicUpload + this.retrieveShareDetails = true + }.execute(client) + + override fun deleteShare(remoteId: Long): RemoteOperationResult = + RemoveRemoteShareOperation( + remoteId + ).execute(client) +} diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/services/implementation/OCShareeService.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/services/implementation/OCShareeService.kt new file mode 100644 index 00000000..370ef34b --- /dev/null +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/services/implementation/OCShareeService.kt @@ -0,0 +1,42 @@ +/** + * ownCloud Android client application + * + * @author David González Verdugo + * + * Copyright (C) 2020 ownCloud GmbH. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.owncloud.android.lib.resources.shares.services.implementation + +import com.owncloud.android.lib.common.OwnCloudClient +import com.owncloud.android.lib.common.operations.RemoteOperationResult +import com.owncloud.android.lib.resources.shares.GetRemoteShareesOperation +import com.owncloud.android.lib.resources.shares.services.ShareeService +import org.json.JSONObject +import java.util.ArrayList + +class OCShareeService(override val client: OwnCloudClient) : + ShareeService { + override fun getSharees( + searchString: String, + page: Int, + perPage: Int + ): RemoteOperationResult> = + GetRemoteShareesOperation( + searchString, + page, + perPage + ).execute(client) +} diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/CapabilityService.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/services/CapabilityService.kt similarity index 88% rename from owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/CapabilityService.kt rename to owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/services/CapabilityService.kt index fab4f301..0ad809c8 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/CapabilityService.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/services/CapabilityService.kt @@ -18,10 +18,11 @@ * along with this program. If not, see . */ -package com.owncloud.android.lib.resources.status +package com.owncloud.android.lib.resources.status.services import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.lib.resources.Service +import com.owncloud.android.lib.resources.status.RemoteCapability interface CapabilityService: Service { fun getCapabilities() : RemoteOperationResult diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/ServerInfoService.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/services/ServerInfoService.kt similarity index 96% rename from owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/ServerInfoService.kt rename to owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/services/ServerInfoService.kt index c211c8ff..1efa7f1b 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/ServerInfoService.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/services/ServerInfoService.kt @@ -21,7 +21,7 @@ * THE SOFTWARE. * */ -package com.owncloud.android.lib.resources.status +package com.owncloud.android.lib.resources.status.services import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.lib.resources.status.OwnCloudVersion diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/services/implementation/OCCapabilityService.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/services/implementation/OCCapabilityService.kt new file mode 100644 index 00000000..d2161b05 --- /dev/null +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/services/implementation/OCCapabilityService.kt @@ -0,0 +1,33 @@ +/** + * ownCloud Android client application + * + * @author David González Verdugo + * + * Copyright (C) 2020 ownCloud GmbH. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.owncloud.android.lib.resources.status.services.implementation + +import com.owncloud.android.lib.common.OwnCloudClient +import com.owncloud.android.lib.common.operations.RemoteOperationResult +import com.owncloud.android.lib.resources.status.services.CapabilityService +import com.owncloud.android.lib.resources.status.GetRemoteCapabilitiesOperation +import com.owncloud.android.lib.resources.status.RemoteCapability + +class OCCapabilityService(override val client: OwnCloudClient) : + CapabilityService { + override fun getCapabilities(): RemoteOperationResult = + GetRemoteCapabilitiesOperation().execute(client) +} diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/services/implementation/OCServerInfoService.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/services/implementation/OCServerInfoService.kt new file mode 100644 index 00000000..8efd9def --- /dev/null +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/services/implementation/OCServerInfoService.kt @@ -0,0 +1,43 @@ +/** + * ownCloud Android client application + * + * @author Abel García de Prada + * Copyright (C) 2020 ownCloud GmbH. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.owncloud.android.lib.resources.status.services.implementation + +import android.net.Uri +import com.owncloud.android.lib.common.OwnCloudClient +import com.owncloud.android.lib.common.operations.RemoteOperationResult +import com.owncloud.android.lib.resources.status.services.ServerInfoService +import com.owncloud.android.lib.resources.files.CheckPathExistenceRemoteOperation +import com.owncloud.android.lib.resources.status.GetRemoteStatusOperation +import com.owncloud.android.lib.resources.status.OwnCloudVersion + +class OCServerInfoService : ServerInfoService { + override fun checkPathExistence(path: String, isUserLogged: Boolean): RemoteOperationResult = + CheckPathExistenceRemoteOperation( + remotePath = path, + isUserLogged = true + ).execute(createClientFromPath(path)) + + override fun getRemoteStatus(path: String): RemoteOperationResult = + GetRemoteStatusOperation().execute(createClientFromPath(path)) + + private fun createClientFromPath(path: String): OwnCloudClient { + return OwnCloudClient(Uri.parse(path)) + } +} diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/UserService.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/services/UserService.kt similarity index 92% rename from owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/UserService.kt rename to owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/services/UserService.kt index b3a33d79..4ef2e1a7 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/UserService.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/services/UserService.kt @@ -22,10 +22,11 @@ * */ -package com.owncloud.android.lib.resources.users +package com.owncloud.android.lib.resources.users.services import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.lib.resources.Service +import com.owncloud.android.lib.resources.users.RemoteUserInfo interface UserService: Service { fun getUserInfo() : RemoteOperationResult diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/services/implementation/OCUserService.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/services/implementation/OCUserService.kt new file mode 100644 index 00000000..6b07b25e --- /dev/null +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/services/implementation/OCUserService.kt @@ -0,0 +1,32 @@ +/** + * ownCloud Android client application + * + * @author Abel García de Prada + * Copyright (C) 2020 ownCloud GmbH. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.owncloud.android.lib.resources.users.services.implementation + +import com.owncloud.android.lib.common.OwnCloudClient +import com.owncloud.android.lib.common.operations.RemoteOperationResult +import com.owncloud.android.lib.resources.users.GetRemoteUserInfoOperation +import com.owncloud.android.lib.resources.users.RemoteUserInfo +import com.owncloud.android.lib.resources.users.services.UserService + +class OCUserService(override val client: OwnCloudClient) : + UserService { + override fun getUserInfo(): RemoteOperationResult = + GetRemoteUserInfoOperation().execute(client) +} From 18b0abb01a4a3a2fe2275bedbfc6eb2596b84403 Mon Sep 17 00:00:00 2001 From: davigonz Date: Mon, 16 Mar 2020 10:47:28 +0100 Subject: [PATCH 14/15] Apply CR changes --- .../owncloud/android/lib/common/accounts/AccountUtils.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/accounts/AccountUtils.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/accounts/AccountUtils.java index 19b3b277..8451edb1 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/accounts/AccountUtils.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/accounts/AccountUtils.java @@ -139,7 +139,7 @@ public class AccountUtils { AccountManager am = AccountManager.get(context); String supportsOAuth2 = am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_OAUTH2); - boolean isOauth2 = supportsOAuth2 != null && supportsOAuth2.equals("TRUE"); + boolean isOauth2 = supportsOAuth2 != null && supportsOAuth2.equals(Constants.OAUTH_SUPPORTED_TRUE); String username = AccountUtils.getUsernameForAccount(account); @@ -294,6 +294,8 @@ public class AccountUtils { */ public static final String KEY_SUPPORTS_OAUTH2 = "oc_supports_oauth2"; + public static final String OAUTH_SUPPORTED_TRUE = "TRUE"; + /** * OC account cookies */ From 9e46b83901ad273ce2ed20a964556ff8223cecaa Mon Sep 17 00:00:00 2001 From: agarcia Date: Wed, 18 Mar 2020 17:19:16 +0100 Subject: [PATCH 15/15] A little cleanup --- .../android/lib/common/network/WebdavUtils.java | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/network/WebdavUtils.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/network/WebdavUtils.java index 8d7e6572..5647dec4 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/network/WebdavUtils.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/network/WebdavUtils.java @@ -34,6 +34,7 @@ import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; +import static com.owncloud.android.lib.common.OwnCloudClient.WEBDAV_FILES_PATH_4_0; import static com.owncloud.android.lib.common.OwnCloudClient.WEBDAV_PATH_4_0_AND_LATER; public class WebdavUtils { @@ -104,20 +105,6 @@ public class WebdavUtils { return result; } - public static String trimWebdavSuffix(String url) { - if (url == null) { - url = ""; - } else { - if (url.endsWith("/")) { - url = url.substring(0, url.length() - 1); - } - if (url.toLowerCase().endsWith(WEBDAV_PATH_4_0_AND_LATER)) { - url = url.substring(0, url.length() - WEBDAV_PATH_4_0_AND_LATER.length()); - } - } - return url; - } - public static String normalizeProtocolPrefix(String url, boolean isSslConn) { if (!url.toLowerCase().startsWith("http://") && !url.toLowerCase().startsWith("https://")) {