Skip to content
This repository was archived by the owner on Mar 19, 2024. It is now read-only.

Commit e9f2913

Browse files
committed
Move network operation adapted to spaces
1 parent b65efc2 commit e9f2913

File tree

4 files changed

+31
-17
lines changed

4 files changed

+31
-17
lines changed

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/CheckPathExistenceRemoteOperation.kt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* ownCloud Android Library is available under MIT license
2-
* Copyright (C) 2020 ownCloud GmbH.
2+
* Copyright (C) 2023 ownCloud GmbH.
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy
55
* of this software and associated documentation files (the "Software"), to deal
@@ -41,28 +41,31 @@ import java.util.concurrent.TimeUnit
4141
* @author David A. Velasco
4242
* @author David González Verdugo
4343
* @author Abel García de Prada
44+
* @author Juan Carlos Garrote Gascón
4445
*
4546
* @param remotePath Path to append to the URL owned by the client instance.
4647
* @param isUserLoggedIn When `true`, the username won't be added at the end of the PROPFIND url since is not
4748
* needed to check user credentials
4849
*/
4950
class CheckPathExistenceRemoteOperation(
5051
val remotePath: String? = "",
51-
val isUserLoggedIn: Boolean
52+
val isUserLoggedIn: Boolean,
53+
val spaceWebDavUrl: String? = null,
5254
) : RemoteOperation<Boolean>() {
5355

5456
override fun run(client: OwnCloudClient): RemoteOperationResult<Boolean> {
55-
return try {
56-
val stringUrl =
57-
if (isUserLoggedIn) client.baseFilesWebDavUri.toString()
58-
else client.userFilesWebDavUri.toString() + WebdavUtils.encodePath(remotePath)
57+
val baseStringUrl = spaceWebDavUrl ?:
58+
if (isUserLoggedIn) client.baseFilesWebDavUri.toString()
59+
else client.userFilesWebDavUri.toString()
60+
val stringUrl = baseStringUrl + WebdavUtils.encodePath(remotePath)
5961

62+
return try {
6063
val propFindMethod = PropfindMethod(URL(stringUrl), 0, allPropset).apply {
6164
setReadTimeout(TIMEOUT.toLong(), TimeUnit.SECONDS)
6265
setConnectionTimeout(TIMEOUT.toLong(), TimeUnit.SECONDS)
6366
}
6467

65-
var status = client.executeHttpMethod(propFindMethod)
68+
val status = client.executeHttpMethod(propFindMethod)
6669
/* PROPFIND method
6770
* 404 NOT FOUND: path doesn't exist,
6871
* 207 MULTI_STATUS: path exists.
@@ -77,7 +80,7 @@ class CheckPathExistenceRemoteOperation(
7780
val result = RemoteOperationResult<Boolean>(e)
7881
Timber.e(
7982
e,
80-
"Existence check for ${client.userFilesWebDavUri}${WebdavUtils.encodePath(remotePath)} : ${result.logMessage}"
83+
"Existence check for $stringUrl : ${result.logMessage}"
8184
)
8285
result
8386
}

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/MoveRemoteFileOperation.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* ownCloud Android Library is available under MIT license
2-
* Copyright (C) 2021 ownCloud GmbH.
2+
* Copyright (C) 2023 ownCloud GmbH.
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy
55
* of this software and associated documentation files (the "Software"), to deal
@@ -38,17 +38,22 @@ import java.util.concurrent.TimeUnit
3838

3939
/**
4040
* Remote operation moving a remote file or folder in the ownCloud server to a different folder
41-
* in the same account.
41+
* in the same account and space.
4242
*
4343
* Allows renaming the moving file/folder at the same time.
4444
*
4545
* @author David A. Velasco
4646
* @author David González Verdugo
4747
* @author Abel García de Prada
48+
* @author Juan Carlos Garrote Gascón
49+
*
50+
* @param sourceRemotePath Remote path of the file/folder to copy.
51+
* @param targetRemotePath Remote path desired for the file/folder to copy it.
4852
*/
4953
open class MoveRemoteFileOperation(
5054
private val sourceRemotePath: String,
5155
private val targetRemotePath: String,
56+
private val spaceWebDavUrl: String? = null,
5257
) : RemoteOperation<Unit>() {
5358

5459
/**
@@ -73,8 +78,8 @@ open class MoveRemoteFileOperation(
7378
// so this uri has to be customizable
7479
val srcWebDavUri = getSrcWebDavUriForClient(client)
7580
val moveMethod = MoveMethod(
76-
url = URL(srcWebDavUri.toString() + WebdavUtils.encodePath(sourceRemotePath)),
77-
destinationUrl = client.userFilesWebDavUri.toString() + WebdavUtils.encodePath(targetRemotePath),
81+
url = URL((spaceWebDavUrl ?: srcWebDavUri.toString()) + WebdavUtils.encodePath(sourceRemotePath)),
82+
destinationUrl = (spaceWebDavUrl ?: client.userFilesWebDavUri.toString()) + WebdavUtils.encodePath(targetRemotePath),
7883
).apply {
7984
addRequestHeaders(this)
8085
setReadTimeout(MOVE_READ_TIMEOUT, TimeUnit.SECONDS)

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/FileService.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* ownCloud Android Library is available under MIT license
2-
* Copyright (C) 2020 ownCloud GmbH.
2+
* Copyright (C) 2023 ownCloud GmbH.
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy
55
* of this software and associated documentation files (the "Software"), to deal
@@ -32,7 +32,8 @@ interface FileService : Service {
3232

3333
fun checkPathExistence(
3434
path: String,
35-
isUserLogged: Boolean
35+
isUserLogged: Boolean,
36+
spaceWebDavUrl: String? = null,
3637
): RemoteOperationResult<Boolean>
3738

3839
fun copyFile(
@@ -55,6 +56,7 @@ interface FileService : Service {
5556
fun moveFile(
5657
sourceRemotePath: String,
5758
targetRemotePath: String,
59+
spaceWebDavUrl: String?,
5860
): RemoteOperationResult<Unit>
5961

6062
fun readFile(

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/implementation/OCFileService.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* ownCloud Android Library is available under MIT license
2-
* Copyright (C) 2022 ownCloud GmbH.
2+
* Copyright (C) 2023 ownCloud GmbH.
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy
55
* of this software and associated documentation files (the "Software"), to deal
@@ -42,11 +42,13 @@ class OCFileService(override val client: OwnCloudClient) : FileService {
4242

4343
override fun checkPathExistence(
4444
path: String,
45-
isUserLogged: Boolean
45+
isUserLogged: Boolean,
46+
spaceWebDavUrl: String?,
4647
): RemoteOperationResult<Boolean> =
4748
CheckPathExistenceRemoteOperation(
4849
remotePath = path,
49-
isUserLoggedIn = isUserLogged
50+
isUserLoggedIn = isUserLogged,
51+
spaceWebDavUrl = spaceWebDavUrl,
5052
).execute(client)
5153

5254
override fun getUrlToOpenInWeb(openWebEndpoint: String, fileId: String): RemoteOperationResult<String> =
@@ -86,10 +88,12 @@ class OCFileService(override val client: OwnCloudClient) : FileService {
8688
override fun moveFile(
8789
sourceRemotePath: String,
8890
targetRemotePath: String,
91+
spaceWebDavUrl: String?,
8992
): RemoteOperationResult<Unit> =
9093
MoveRemoteFileOperation(
9194
sourceRemotePath = sourceRemotePath,
9295
targetRemotePath = targetRemotePath,
96+
spaceWebDavUrl = spaceWebDavUrl,
9397
).execute(client)
9498

9599
override fun readFile(

0 commit comments

Comments
 (0)