mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-10-31 10:27:45 +00:00 
			
		
		
		
	Merge pull request #533 from owncloud/spaces/list_content
[SPACES] List&Browse Spaces content
This commit is contained in:
		
						commit
						887ea6f2cd
					
				| @ -46,7 +46,8 @@ import java.util.concurrent.TimeUnit | |||||||
| class CreateRemoteFolderOperation( | class CreateRemoteFolderOperation( | ||||||
|     val remotePath: String, |     val remotePath: String, | ||||||
|     private val createFullPath: Boolean, |     private val createFullPath: Boolean, | ||||||
|     private val isChunksFolder: Boolean = false |     private val isChunksFolder: Boolean = false, | ||||||
|  |     val spaceWebDavUrl: String? = null, | ||||||
| ) : RemoteOperation<Unit>() { | ) : RemoteOperation<Unit>() { | ||||||
| 
 | 
 | ||||||
|     override fun run(client: OwnCloudClient): RemoteOperationResult<Unit> { |     override fun run(client: OwnCloudClient): RemoteOperationResult<Unit> { | ||||||
| @ -67,13 +68,13 @@ class CreateRemoteFolderOperation( | |||||||
|         var result: RemoteOperationResult<Unit> |         var result: RemoteOperationResult<Unit> | ||||||
|         try { |         try { | ||||||
|             val webDavUri = if (isChunksFolder) { |             val webDavUri = if (isChunksFolder) { | ||||||
|                 client.uploadsWebDavUri |                 client.uploadsWebDavUri.toString() | ||||||
|             } else { |             } else { | ||||||
|                 client.userFilesWebDavUri |                 spaceWebDavUrl ?: client.userFilesWebDavUri.toString() | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             val mkCol = MkColMethod( |             val mkCol = MkColMethod( | ||||||
|                 URL(webDavUri.toString() + WebdavUtils.encodePath(remotePath)) |                 URL(webDavUri + WebdavUtils.encodePath(remotePath)) | ||||||
|             ).apply { |             ).apply { | ||||||
|                 setReadTimeout(READ_TIMEOUT, TimeUnit.SECONDS) |                 setReadTimeout(READ_TIMEOUT, TimeUnit.SECONDS) | ||||||
|                 setConnectionTimeout(CONNECTION_TIMEOUT, TimeUnit.SECONDS) |                 setConnectionTimeout(CONNECTION_TIMEOUT, TimeUnit.SECONDS) | ||||||
|  | |||||||
| @ -46,7 +46,10 @@ import java.util.concurrent.TimeUnit | |||||||
|  * @author David González Verdugo |  * @author David González Verdugo | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| class ReadRemoteFileOperation(val remotePath: String) : RemoteOperation<RemoteFile>() { | class ReadRemoteFileOperation( | ||||||
|  |     val remotePath: String, | ||||||
|  |     val spaceWebDavUrl: String? = null, | ||||||
|  | ) : RemoteOperation<RemoteFile>() { | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Performs the read operation. |      * Performs the read operation. | ||||||
| @ -57,7 +60,7 @@ class ReadRemoteFileOperation(val remotePath: String) : RemoteOperation<RemoteFi | |||||||
|     override fun run(client: OwnCloudClient): RemoteOperationResult<RemoteFile> { |     override fun run(client: OwnCloudClient): RemoteOperationResult<RemoteFile> { | ||||||
|         try { |         try { | ||||||
|             val propFind = PropfindMethod( |             val propFind = PropfindMethod( | ||||||
|                 url = URL("${client.userFilesWebDavUri}${WebdavUtils.encodePath(remotePath)}"), |                 url = getFinalWebDavUrl(), | ||||||
|                 depth = DEPTH_0, |                 depth = DEPTH_0, | ||||||
|                 propertiesToRequest = DavUtils.allPropset |                 propertiesToRequest = DavUtils.allPropset | ||||||
|             ).apply { |             ).apply { | ||||||
| @ -69,10 +72,11 @@ class ReadRemoteFileOperation(val remotePath: String) : RemoteOperation<RemoteFi | |||||||
|             Timber.i("Read remote file $remotePath with status ${propFind.statusCode}") |             Timber.i("Read remote file $remotePath with status ${propFind.statusCode}") | ||||||
| 
 | 
 | ||||||
|             return if (isSuccess(status)) { |             return if (isSuccess(status)) { | ||||||
|                 // TODO: Remove that !! |  | ||||||
|                 val remoteFile = RemoteFile.getRemoteFileFromDav( |                 val remoteFile = RemoteFile.getRemoteFileFromDav( | ||||||
|                     propFind.root!!, |                     davResource = propFind.root!!, | ||||||
|                     AccountUtils.getUserId(mAccount, mContext), mAccount.name |                     userId = AccountUtils.getUserId(mAccount, mContext), | ||||||
|  |                     userName = mAccount.name, | ||||||
|  |                     spaceWebDavUrl = spaceWebDavUrl, | ||||||
|                 ) |                 ) | ||||||
| 
 | 
 | ||||||
|                 RemoteOperationResult<RemoteFile>(RemoteOperationResult.ResultCode.OK).apply { |                 RemoteOperationResult<RemoteFile>(RemoteOperationResult.ResultCode.OK).apply { | ||||||
| @ -88,6 +92,12 @@ class ReadRemoteFileOperation(val remotePath: String) : RemoteOperation<RemoteFi | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     private fun getFinalWebDavUrl(): URL { | ||||||
|  |         val baseWebDavUrl = spaceWebDavUrl ?: client.userFilesWebDavUri.toString() | ||||||
|  | 
 | ||||||
|  |         return URL(baseWebDavUrl + WebdavUtils.encodePath(remotePath)) | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     private fun isSuccess(status: Int) = status.isOneOf(HTTP_MULTI_STATUS, HTTP_OK) |     private fun isSuccess(status: Int) = status.isOneOf(HTTP_MULTI_STATUS, HTTP_OK) | ||||||
| 
 | 
 | ||||||
|     companion object { |     companion object { | ||||||
|  | |||||||
| @ -48,7 +48,8 @@ import java.net.URL | |||||||
|  * @author David González Verdugo |  * @author David González Verdugo | ||||||
|  */ |  */ | ||||||
| class ReadRemoteFolderOperation( | class ReadRemoteFolderOperation( | ||||||
|     val remotePath: String |     val remotePath: String, | ||||||
|  |     val spaceWebDavUrl: String? = null, | ||||||
| ) : RemoteOperation<ArrayList<RemoteFile>>() { | ) : RemoteOperation<ArrayList<RemoteFile>>() { | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
| @ -61,7 +62,7 @@ class ReadRemoteFolderOperation( | |||||||
|             PropertyRegistry.register(OCShareTypes.Factory()) |             PropertyRegistry.register(OCShareTypes.Factory()) | ||||||
| 
 | 
 | ||||||
|             val propfindMethod = PropfindMethod( |             val propfindMethod = PropfindMethod( | ||||||
|                 URL(client.userFilesWebDavUri.toString() + WebdavUtils.encodePath(remotePath)), |                 getFinalWebDavUrl(), | ||||||
|                 DavConstants.DEPTH_1, |                 DavConstants.DEPTH_1, | ||||||
|                 DavUtils.allPropset |                 DavUtils.allPropset | ||||||
|             ) |             ) | ||||||
| @ -71,12 +72,11 @@ class ReadRemoteFolderOperation( | |||||||
|             if (isSuccess(status)) { |             if (isSuccess(status)) { | ||||||
|                 val mFolderAndFiles = ArrayList<RemoteFile>() |                 val mFolderAndFiles = ArrayList<RemoteFile>() | ||||||
| 
 | 
 | ||||||
|                 // parse data from remote folder |  | ||||||
|                 // TODO: Remove that !! |  | ||||||
|                 val remoteFolder = RemoteFile.getRemoteFileFromDav( |                 val remoteFolder = RemoteFile.getRemoteFileFromDav( | ||||||
|                     davResource = propfindMethod.root!!, |                     davResource = propfindMethod.root!!, | ||||||
|                     userId = AccountUtils.getUserId(mAccount, mContext), |                     userId = AccountUtils.getUserId(mAccount, mContext), | ||||||
|                     userName = mAccount.name |                     userName = mAccount.name, | ||||||
|  |                     spaceWebDavUrl = spaceWebDavUrl, | ||||||
|                 ) |                 ) | ||||||
|                 mFolderAndFiles.add(remoteFolder) |                 mFolderAndFiles.add(remoteFolder) | ||||||
| 
 | 
 | ||||||
| @ -85,7 +85,8 @@ class ReadRemoteFolderOperation( | |||||||
|                     val remoteFile = RemoteFile.getRemoteFileFromDav( |                     val remoteFile = RemoteFile.getRemoteFileFromDav( | ||||||
|                         davResource = resource, |                         davResource = resource, | ||||||
|                         userId = AccountUtils.getUserId(mAccount, mContext), |                         userId = AccountUtils.getUserId(mAccount, mContext), | ||||||
|                         userName = mAccount.name |                         userName = mAccount.name, | ||||||
|  |                         spaceWebDavUrl = spaceWebDavUrl, | ||||||
|                     ) |                     ) | ||||||
|                     mFolderAndFiles.add(remoteFile) |                     mFolderAndFiles.add(remoteFile) | ||||||
|                 } |                 } | ||||||
| @ -107,5 +108,11 @@ class ReadRemoteFolderOperation( | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     private fun getFinalWebDavUrl(): URL { | ||||||
|  |         val baseWebDavUrl = spaceWebDavUrl ?: client.userFilesWebDavUri.toString() | ||||||
|  | 
 | ||||||
|  |         return URL(baseWebDavUrl + WebdavUtils.encodePath(remotePath)) | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     private fun isSuccess(status: Int): Boolean = status.isOneOf(HTTP_OK, HTTP_MULTI_STATUS) |     private fun isSuccess(status: Int): Boolean = status.isOneOf(HTTP_OK, HTTP_MULTI_STATUS) | ||||||
| } | } | ||||||
|  | |||||||
| @ -26,6 +26,7 @@ package com.owncloud.android.lib.resources.files | |||||||
| 
 | 
 | ||||||
| import android.net.Uri | import android.net.Uri | ||||||
| import android.os.Parcelable | import android.os.Parcelable | ||||||
|  | import androidx.annotation.VisibleForTesting | ||||||
| import at.bitfire.dav4jvm.PropStat | import at.bitfire.dav4jvm.PropStat | ||||||
| import at.bitfire.dav4jvm.Property | import at.bitfire.dav4jvm.Property | ||||||
| import at.bitfire.dav4jvm.Response | import at.bitfire.dav4jvm.Response | ||||||
| @ -100,8 +101,13 @@ data class RemoteFile( | |||||||
|         const val MIME_DIR = "DIR" |         const val MIME_DIR = "DIR" | ||||||
|         const val MIME_DIR_UNIX = "httpd/unix-directory" |         const val MIME_DIR_UNIX = "httpd/unix-directory" | ||||||
| 
 | 
 | ||||||
|         fun getRemoteFileFromDav(davResource: Response, userId: String, userName: String): RemoteFile { |         fun getRemoteFileFromDav( | ||||||
|             val remotePath = getRemotePathFromUrl(davResource.href, userId) |             davResource: Response, | ||||||
|  |             userId: String, | ||||||
|  |             userName: String, | ||||||
|  |             spaceWebDavUrl: String? = null | ||||||
|  |         ): RemoteFile { | ||||||
|  |             val remotePath = getRemotePathFromUrl(davResource.href, userId, spaceWebDavUrl) | ||||||
|             val remoteFile = RemoteFile(remotePath = remotePath, owner = userName) |             val remoteFile = RemoteFile(remotePath = remotePath, owner = userName) | ||||||
|             val properties = getPropertiesEvenIfPostProcessing(davResource) |             val properties = getPropertiesEvenIfPostProcessing(davResource) | ||||||
| 
 | 
 | ||||||
| @ -164,15 +170,25 @@ data class RemoteFile( | |||||||
|          * Retrieves a relative path from a remote file url |          * Retrieves a relative path from a remote file url | ||||||
|          * |          * | ||||||
|          * |          * | ||||||
|          * Example: url:port/remote.php/dav/files/username/Documents/text.txt => /Documents/text.txt |          * Example legacy: | ||||||
|  |          * /remote.php/dav/files/username/Documents/text.txt => /Documents/text.txt | ||||||
|  |          * | ||||||
|  |          * Example spaces: | ||||||
|  |          * /dav/spaces/8871f4f3-fc6f-4a66-8bed-62f175f76f38$05bca744-d89f-4e9c-a990-25a0d7f03fe9/Documents/text.txt => /Documents/text.txt | ||||||
|          * |          * | ||||||
|          * @param url    remote file url |          * @param url    remote file url | ||||||
|          * @param userId file owner |          * @param userId file owner | ||||||
|  |          * @param spaceWebDavUrl custom web dav url for space | ||||||
|          * @return remote relative path of the file |          * @return remote relative path of the file | ||||||
|          */ |          */ | ||||||
|         private fun getRemotePathFromUrl(url: HttpUrl, userId: String): String { |         @VisibleForTesting | ||||||
|             val davFilesPath = OwnCloudClient.WEBDAV_FILES_PATH_4_0 + userId |         fun getRemotePathFromUrl( | ||||||
|             val absoluteDavPath = Uri.decode(url.encodedPath) |             url: HttpUrl, | ||||||
|  |             userId: String, | ||||||
|  |             spaceWebDavUrl: String? = null, | ||||||
|  |         ): String { | ||||||
|  |             val davFilesPath = spaceWebDavUrl ?: (OwnCloudClient.WEBDAV_FILES_PATH_4_0 + userId) | ||||||
|  |             val absoluteDavPath = if (spaceWebDavUrl != null) Uri.decode(url.toString()) else Uri.decode(url.encodedPath) | ||||||
|             val pathToOc = absoluteDavPath.split(davFilesPath).first() |             val pathToOc = absoluteDavPath.split(davFilesPath).first() | ||||||
|             return absoluteDavPath.replace(pathToOc + davFilesPath, "") |             return absoluteDavPath.replace(pathToOc + davFilesPath, "") | ||||||
|         } |         } | ||||||
|  | |||||||
| @ -24,7 +24,6 @@ | |||||||
| 
 | 
 | ||||||
| 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 | import com.owncloud.android.lib.common.OwnCloudClient | ||||||
| import com.owncloud.android.lib.common.http.HttpConstants.HTTP_NO_CONTENT | import com.owncloud.android.lib.common.http.HttpConstants.HTTP_NO_CONTENT | ||||||
| import com.owncloud.android.lib.common.http.HttpConstants.HTTP_OK | import com.owncloud.android.lib.common.http.HttpConstants.HTTP_OK | ||||||
| @ -46,7 +45,8 @@ import java.net.URL | |||||||
|  * @author Abel García de Prada |  * @author Abel García de Prada | ||||||
|  */ |  */ | ||||||
| open class RemoveRemoteFileOperation( | open class RemoveRemoteFileOperation( | ||||||
|     private val remotePath: String |     private val remotePath: String, | ||||||
|  |     val spaceWebDavUrl: String? = null, | ||||||
| ) : RemoteOperation<Unit>() { | ) : RemoteOperation<Unit>() { | ||||||
| 
 | 
 | ||||||
|     override fun run(client: OwnCloudClient): RemoteOperationResult<Unit> { |     override fun run(client: OwnCloudClient): RemoteOperationResult<Unit> { | ||||||
| @ -54,7 +54,7 @@ open class RemoveRemoteFileOperation( | |||||||
|         try { |         try { | ||||||
|             val srcWebDavUri = getSrcWebDavUriForClient(client) |             val srcWebDavUri = getSrcWebDavUriForClient(client) | ||||||
|             val deleteMethod = DeleteMethod( |             val deleteMethod = DeleteMethod( | ||||||
|                 URL(srcWebDavUri.toString() + WebdavUtils.encodePath(remotePath)) |                 URL(srcWebDavUri + WebdavUtils.encodePath(remotePath)) | ||||||
|             ) |             ) | ||||||
|             val status = client.executeHttpMethod(deleteMethod) |             val status = client.executeHttpMethod(deleteMethod) | ||||||
| 
 | 
 | ||||||
| @ -75,7 +75,7 @@ open class RemoveRemoteFileOperation( | |||||||
|      * For standard removals, we will use [OwnCloudClient.getUserFilesWebDavUri]. |      * For standard removals, we will use [OwnCloudClient.getUserFilesWebDavUri]. | ||||||
|      * In case we need a different source Uri, override this method. |      * In case we need a different source Uri, override this method. | ||||||
|      */ |      */ | ||||||
|     open fun getSrcWebDavUriForClient(client: OwnCloudClient): Uri = client.userFilesWebDavUri |     open fun getSrcWebDavUriForClient(client: OwnCloudClient): String = spaceWebDavUrl ?: client.userFilesWebDavUri.toString() | ||||||
| 
 | 
 | ||||||
|     private fun isSuccess(status: Int) = status.isOneOf(HTTP_OK, HTTP_NO_CONTENT) |     private fun isSuccess(status: Int) = status.isOneOf(HTTP_OK, HTTP_NO_CONTENT) | ||||||
| } | } | ||||||
|  | |||||||
| @ -48,6 +48,7 @@ class RenameRemoteFileOperation( | |||||||
|     private val oldRemotePath: String, |     private val oldRemotePath: String, | ||||||
|     private val newName: String, |     private val newName: String, | ||||||
|     isFolder: Boolean, |     isFolder: Boolean, | ||||||
|  |     val spaceWebDavUrl: String? = null, | ||||||
| ) : RemoteOperation<Unit>() { | ) : RemoteOperation<Unit>() { | ||||||
| 
 | 
 | ||||||
|     private var newRemotePath: String |     private var newRemotePath: String | ||||||
| @ -75,8 +76,8 @@ class RenameRemoteFileOperation( | |||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             val moveMethod: MoveMethod = MoveMethod( |             val moveMethod: MoveMethod = MoveMethod( | ||||||
|                 url = URL(client.userFilesWebDavUri.toString() + WebdavUtils.encodePath(oldRemotePath)), |                 url = URL((spaceWebDavUrl ?: client.userFilesWebDavUri.toString()) + WebdavUtils.encodePath(oldRemotePath)), | ||||||
|                 destinationUrl = client.userFilesWebDavUri.toString() + WebdavUtils.encodePath(newRemotePath), |                 destinationUrl = (spaceWebDavUrl ?: client.userFilesWebDavUri.toString()) + WebdavUtils.encodePath(newRemotePath), | ||||||
|             ).apply { |             ).apply { | ||||||
|                 setReadTimeout(RENAME_READ_TIMEOUT, TimeUnit.MILLISECONDS) |                 setReadTimeout(RENAME_READ_TIMEOUT, TimeUnit.MILLISECONDS) | ||||||
|                 setConnectionTimeout(RENAME_CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS) |                 setConnectionTimeout(RENAME_CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS) | ||||||
|  | |||||||
| @ -24,10 +24,9 @@ | |||||||
|  */ |  */ | ||||||
| package com.owncloud.android.lib.resources.files.chunks | package com.owncloud.android.lib.resources.files.chunks | ||||||
| 
 | 
 | ||||||
| import android.net.Uri |  | ||||||
| import com.owncloud.android.lib.common.OwnCloudClient | import com.owncloud.android.lib.common.OwnCloudClient | ||||||
| import com.owncloud.android.lib.resources.files.RemoveRemoteFileOperation | import com.owncloud.android.lib.resources.files.RemoveRemoteFileOperation | ||||||
| 
 | 
 | ||||||
| class RemoveRemoteChunksFolderOperation(remotePath: String) : RemoveRemoteFileOperation(remotePath) { | class RemoveRemoteChunksFolderOperation(remotePath: String) : RemoveRemoteFileOperation(remotePath) { | ||||||
|     override fun getSrcWebDavUriForClient(client: OwnCloudClient): Uri = client.uploadsWebDavUri |     override fun getSrcWebDavUriForClient(client: OwnCloudClient): String = client.uploadsWebDavUri.toString() | ||||||
| } | } | ||||||
|  | |||||||
| @ -43,7 +43,8 @@ interface FileService : Service { | |||||||
|     fun createFolder( |     fun createFolder( | ||||||
|         remotePath: String, |         remotePath: String, | ||||||
|         createFullPath: Boolean, |         createFullPath: Boolean, | ||||||
|         isChunkFolder: Boolean = false |         isChunkFolder: Boolean = false, | ||||||
|  |         spaceWebDavUrl: String? = null, | ||||||
|     ): RemoteOperationResult<Unit> |     ): RemoteOperationResult<Unit> | ||||||
| 
 | 
 | ||||||
|     fun downloadFile( |     fun downloadFile( | ||||||
| @ -57,15 +58,18 @@ interface FileService : Service { | |||||||
|     ): RemoteOperationResult<Unit> |     ): RemoteOperationResult<Unit> | ||||||
| 
 | 
 | ||||||
|     fun readFile( |     fun readFile( | ||||||
|         remotePath: String |         remotePath: String, | ||||||
|  |         spaceWebDavUrl: String? = null, | ||||||
|     ): RemoteOperationResult<RemoteFile> |     ): RemoteOperationResult<RemoteFile> | ||||||
| 
 | 
 | ||||||
|     fun refreshFolder( |     fun refreshFolder( | ||||||
|         remotePath: String |         remotePath: String, | ||||||
|  |         spaceWebDavUrl: String? = null, | ||||||
|     ): RemoteOperationResult<ArrayList<RemoteFile>> |     ): RemoteOperationResult<ArrayList<RemoteFile>> | ||||||
| 
 | 
 | ||||||
|     fun removeFile( |     fun removeFile( | ||||||
|         remotePath: String |         remotePath: String, | ||||||
|  |         spaceWebDavUrl: String? = null, | ||||||
|     ): RemoteOperationResult<Unit> |     ): RemoteOperationResult<Unit> | ||||||
| 
 | 
 | ||||||
|     fun renameFile( |     fun renameFile( | ||||||
| @ -73,5 +77,6 @@ interface FileService : Service { | |||||||
|         oldRemotePath: String, |         oldRemotePath: String, | ||||||
|         newName: String, |         newName: String, | ||||||
|         isFolder: Boolean, |         isFolder: Boolean, | ||||||
|  |         spaceWebDavUrl: String? = null, | ||||||
|     ): RemoteOperationResult<Unit> |     ): RemoteOperationResult<Unit> | ||||||
| } | } | ||||||
|  | |||||||
| @ -64,12 +64,14 @@ class OCFileService(override val client: OwnCloudClient) : FileService { | |||||||
|     override fun createFolder( |     override fun createFolder( | ||||||
|         remotePath: String, |         remotePath: String, | ||||||
|         createFullPath: Boolean, |         createFullPath: Boolean, | ||||||
|         isChunkFolder: Boolean |         isChunkFolder: Boolean, | ||||||
|  |         spaceWebDavUrl: String?, | ||||||
|     ): RemoteOperationResult<Unit> = |     ): RemoteOperationResult<Unit> = | ||||||
|         CreateRemoteFolderOperation( |         CreateRemoteFolderOperation( | ||||||
|             remotePath = remotePath, |             remotePath = remotePath, | ||||||
|             createFullPath = createFullPath, |             createFullPath = createFullPath, | ||||||
|             isChunksFolder = isChunkFolder |             isChunksFolder = isChunkFolder, | ||||||
|  |             spaceWebDavUrl = spaceWebDavUrl, | ||||||
|         ).execute(client) |         ).execute(client) | ||||||
| 
 | 
 | ||||||
|     override fun downloadFile( |     override fun downloadFile( | ||||||
| @ -91,36 +93,44 @@ class OCFileService(override val client: OwnCloudClient) : FileService { | |||||||
|         ).execute(client) |         ).execute(client) | ||||||
| 
 | 
 | ||||||
|     override fun readFile( |     override fun readFile( | ||||||
|         remotePath: String |         remotePath: String, | ||||||
|  |         spaceWebDavUrl: String?, | ||||||
|     ): RemoteOperationResult<RemoteFile> = |     ): RemoteOperationResult<RemoteFile> = | ||||||
|         ReadRemoteFileOperation( |         ReadRemoteFileOperation( | ||||||
|             remotePath = remotePath |             remotePath = remotePath, | ||||||
|  |             spaceWebDavUrl = spaceWebDavUrl, | ||||||
|         ).execute(client) |         ).execute(client) | ||||||
| 
 | 
 | ||||||
|     override fun refreshFolder( |     override fun refreshFolder( | ||||||
|         remotePath: String |         remotePath: String, | ||||||
|  |         spaceWebDavUrl: String?, | ||||||
|     ): RemoteOperationResult<ArrayList<RemoteFile>> = |     ): RemoteOperationResult<ArrayList<RemoteFile>> = | ||||||
|         ReadRemoteFolderOperation( |         ReadRemoteFolderOperation( | ||||||
|             remotePath = remotePath |             remotePath = remotePath, | ||||||
|  |             spaceWebDavUrl = spaceWebDavUrl, | ||||||
|         ).execute(client) |         ).execute(client) | ||||||
| 
 | 
 | ||||||
|     override fun removeFile( |     override fun removeFile( | ||||||
|         remotePath: String |         remotePath: String, | ||||||
|  |         spaceWebDavUrl: String?, | ||||||
|     ): RemoteOperationResult<Unit> = |     ): RemoteOperationResult<Unit> = | ||||||
|         RemoveRemoteFileOperation( |         RemoveRemoteFileOperation( | ||||||
|             remotePath = remotePath |             remotePath = remotePath, | ||||||
|  |             spaceWebDavUrl = spaceWebDavUrl, | ||||||
|         ).execute(client) |         ).execute(client) | ||||||
| 
 | 
 | ||||||
|     override fun renameFile( |     override fun renameFile( | ||||||
|         oldName: String, |         oldName: String, | ||||||
|         oldRemotePath: String, |         oldRemotePath: String, | ||||||
|         newName: String, |         newName: String, | ||||||
|         isFolder: Boolean |         isFolder: Boolean, | ||||||
|  |         spaceWebDavUrl: String?, | ||||||
|     ): RemoteOperationResult<Unit> = |     ): RemoteOperationResult<Unit> = | ||||||
|         RenameRemoteFileOperation( |         RenameRemoteFileOperation( | ||||||
|             oldName = oldName, |             oldName = oldName, | ||||||
|             oldRemotePath = oldRemotePath, |             oldRemotePath = oldRemotePath, | ||||||
|             newName = newName, |             newName = newName, | ||||||
|             isFolder = isFolder |             isFolder = isFolder, | ||||||
|  |             spaceWebDavUrl = spaceWebDavUrl, | ||||||
|         ).execute(client) |         ).execute(client) | ||||||
| } | } | ||||||
|  | |||||||
| @ -0,0 +1,59 @@ | |||||||
|  | /* ownCloud Android Library is available under MIT license | ||||||
|  |  *   Copyright (C) 2023 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 | ||||||
|  | 
 | ||||||
|  | import android.os.Build | ||||||
|  | import com.owncloud.android.lib.resources.files.RemoteFile | ||||||
|  | import okhttp3.HttpUrl.Companion.toHttpUrl | ||||||
|  | import org.junit.Assert.assertEquals | ||||||
|  | import org.junit.Test | ||||||
|  | import org.junit.runner.RunWith | ||||||
|  | import org.robolectric.RobolectricTestRunner | ||||||
|  | import org.robolectric.annotation.Config | ||||||
|  | 
 | ||||||
|  | @RunWith(RobolectricTestRunner::class) | ||||||
|  | @Config(sdk = [Build.VERSION_CODES.O], manifest = Config.NONE) | ||||||
|  | class RemoteFileTest { | ||||||
|  | 
 | ||||||
|  |     @Test | ||||||
|  |     fun getRemotePathFromUrl_legacyWebDav() { | ||||||
|  |         val httpUrlToTest = "https://server.url/remote.php/dav/files/username/Documents/text.txt".toHttpUrl() | ||||||
|  |         val expectedRemotePath = "/Documents/text.txt" | ||||||
|  | 
 | ||||||
|  |         val actualRemotePath = RemoteFile.Companion.getRemotePathFromUrl(httpUrlToTest, "username") | ||||||
|  |         assertEquals(expectedRemotePath, actualRemotePath) | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Test | ||||||
|  |     fun getRemotePathFromUrl_spacesWebDav() { | ||||||
|  |         val spaceWebDavUrl = "https://server.url/dav/spaces/8871f4f3-fc6f-4a66-8bed-62f175f76f38$05bca744-d89f-4e9c-a990-25a0d7f03fe9" | ||||||
|  | 
 | ||||||
|  |         val httpUrlToTest = | ||||||
|  |             "https://server.url/dav/spaces/8871f4f3-fc6f-4a66-8bed-62f175f76f38$05bca744-d89f-4e9c-a990-25a0d7f03fe9/Documents/text.txt".toHttpUrl() | ||||||
|  |         val expectedRemotePath = "/Documents/text.txt" | ||||||
|  | 
 | ||||||
|  |         val actualRemotePath = RemoteFile.Companion.getRemotePathFromUrl(httpUrlToTest, "username", spaceWebDavUrl) | ||||||
|  |         assertEquals(expectedRemotePath, actualRemotePath) | ||||||
|  |     } | ||||||
|  | } | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user