From 86eb5fdf702c35c95bdfe89b878d24a612d8e8e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abel=20Garci=CC=81a=20de=20Prada?= Date: Thu, 29 Apr 2021 09:32:19 +0200 Subject: [PATCH] Add removeFile to FileService --- .../files/RemoveRemoteFileOperation.kt | 10 +++--- .../resources/files/services/ChunkService.kt | 34 ++++++++++++++++++ .../resources/files/services/FileService.kt | 4 +++ .../services/implementation/OCChunkService.kt | 36 +++++++++++++++++++ .../services/implementation/OCFileService.kt | 4 +++ 5 files changed, 83 insertions(+), 5 deletions(-) create mode 100644 owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/ChunkService.kt create mode 100644 owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/implementation/OCChunkService.kt diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RemoveRemoteFileOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RemoveRemoteFileOperation.kt index 23b16e7e..fa9702ad 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RemoveRemoteFileOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RemoveRemoteFileOperation.kt @@ -22,7 +22,7 @@ * */ -package com.owncloud.android.lib.resources.files; +package com.owncloud.android.lib.resources.files import android.net.Uri import com.owncloud.android.lib.common.OwnCloudClient @@ -46,7 +46,7 @@ import java.net.URL * @author Abel GarcĂ­a de Prada */ open class RemoveRemoteFileOperation( - private val mRemotePath: String + private val remotePath: String ) : RemoteOperation() { override fun run(client: OwnCloudClient): RemoteOperationResult { @@ -54,14 +54,14 @@ open class RemoveRemoteFileOperation( try { val srcWebDavUri = getSrcWebDavUriForClient(client) val deleteMethod = DeleteMethod( - URL(srcWebDavUri.toString() + WebdavUtils.encodePath(mRemotePath)) + URL(srcWebDavUri.toString() + WebdavUtils.encodePath(remotePath)) ) val status = client.executeHttpMethod(deleteMethod) result = if (isSuccess(status)) RemoteOperationResult(ResultCode.OK) else RemoteOperationResult(deleteMethod) - Timber.i("Remove $mRemotePath: ${result.logMessage}") + Timber.i("Remove $remotePath: ${result.logMessage}") } catch (e: Exception) { result = RemoteOperationResult(e) - Timber.e(e, "Remove $mRemotePath: ${result.logMessage}") + Timber.e(e, "Remove $remotePath: ${result.logMessage}") } return result } diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/ChunkService.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/ChunkService.kt new file mode 100644 index 00000000..011dbe35 --- /dev/null +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/ChunkService.kt @@ -0,0 +1,34 @@ +/* ownCloud Android Library is available under MIT license + * Copyright (C) 2021 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.services + +import com.owncloud.android.lib.common.operations.RemoteOperationResult +import com.owncloud.android.lib.resources.Service + +interface ChunkService : Service { + fun removeFile( + remotePath: String + ): RemoteOperationResult +} diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/FileService.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/FileService.kt index 0a43d0f8..cf27ab1e 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/FileService.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/FileService.kt @@ -49,4 +49,8 @@ interface FileService : Service { fun refreshFolder( remotePath: String ): RemoteOperationResult> + + fun removeFile( + remotePath: String + ): RemoteOperationResult } diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/implementation/OCChunkService.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/implementation/OCChunkService.kt new file mode 100644 index 00000000..d7ca75e8 --- /dev/null +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/implementation/OCChunkService.kt @@ -0,0 +1,36 @@ +/* ownCloud Android Library is available under MIT license + * Copyright (C) 2021 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.services.implementation + +import com.owncloud.android.lib.common.OwnCloudClient +import com.owncloud.android.lib.common.operations.RemoteOperationResult +import com.owncloud.android.lib.resources.files.chunks.RemoveRemoteChunksFolderOperation +import com.owncloud.android.lib.resources.files.services.ChunkService + +class OCChunkService(override val client: OwnCloudClient) : ChunkService { + + override fun removeFile(remotePath: String): RemoteOperationResult = + RemoveRemoteChunksFolderOperation(remotePath = remotePath).execute(client) +} 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 index 55892f4a..46d02a27 100644 --- 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 @@ -31,6 +31,7 @@ import com.owncloud.android.lib.resources.files.DownloadRemoteFileOperation import com.owncloud.android.lib.resources.files.GetUrlToOpenInWebRemoteOperation import com.owncloud.android.lib.resources.files.ReadRemoteFolderOperation import com.owncloud.android.lib.resources.files.RemoteFile +import com.owncloud.android.lib.resources.files.RemoveRemoteFileOperation import com.owncloud.android.lib.resources.files.services.FileService class OCFileService(override val client: OwnCloudClient) : FileService { @@ -71,4 +72,7 @@ class OCFileService(override val client: OwnCloudClient) : FileService { ReadRemoteFolderOperation( remotePath = remotePath ).execute(client) + + override fun removeFile(remotePath: String): RemoteOperationResult = + RemoveRemoteFileOperation(remotePath = remotePath).execute(client) }