mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-11-03 20:08:00 +00:00 
			
		
		
		
	Move network operation adapted to spaces
This commit is contained in:
		
							parent
							
								
									b65efc2b69
								
							
						
					
					
						commit
						e9f291371d
					
				@ -1,5 +1,5 @@
 | 
			
		||||
/* ownCloud Android Library is available under MIT license
 | 
			
		||||
*   Copyright (C) 2020 ownCloud GmbH.
 | 
			
		||||
*   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
 | 
			
		||||
@ -41,6 +41,7 @@ import java.util.concurrent.TimeUnit
 | 
			
		||||
 * @author David A. Velasco
 | 
			
		||||
 * @author David González Verdugo
 | 
			
		||||
 * @author Abel García de Prada
 | 
			
		||||
 * @author Juan Carlos Garrote Gascón
 | 
			
		||||
 *
 | 
			
		||||
 * @param remotePath      Path to append to the URL owned by the client instance.
 | 
			
		||||
 * @param isUserLoggedIn    When `true`, the username won't be added at the end of the PROPFIND url since is not
 | 
			
		||||
@ -48,21 +49,23 @@ import java.util.concurrent.TimeUnit
 | 
			
		||||
 */
 | 
			
		||||
class CheckPathExistenceRemoteOperation(
 | 
			
		||||
    val remotePath: String? = "",
 | 
			
		||||
    val isUserLoggedIn: Boolean
 | 
			
		||||
    val isUserLoggedIn: Boolean,
 | 
			
		||||
    val spaceWebDavUrl: String? = null,
 | 
			
		||||
) : RemoteOperation<Boolean>() {
 | 
			
		||||
 | 
			
		||||
    override fun run(client: OwnCloudClient): RemoteOperationResult<Boolean> {
 | 
			
		||||
        return try {
 | 
			
		||||
            val stringUrl =
 | 
			
		||||
        val baseStringUrl = spaceWebDavUrl ?:
 | 
			
		||||
        if (isUserLoggedIn) client.baseFilesWebDavUri.toString()
 | 
			
		||||
                else client.userFilesWebDavUri.toString() + WebdavUtils.encodePath(remotePath)
 | 
			
		||||
        else client.userFilesWebDavUri.toString()
 | 
			
		||||
        val stringUrl = baseStringUrl + WebdavUtils.encodePath(remotePath)
 | 
			
		||||
 | 
			
		||||
        return try {
 | 
			
		||||
            val propFindMethod = PropfindMethod(URL(stringUrl), 0, allPropset).apply {
 | 
			
		||||
                setReadTimeout(TIMEOUT.toLong(), TimeUnit.SECONDS)
 | 
			
		||||
                setConnectionTimeout(TIMEOUT.toLong(), TimeUnit.SECONDS)
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            var status = client.executeHttpMethod(propFindMethod)
 | 
			
		||||
            val status = client.executeHttpMethod(propFindMethod)
 | 
			
		||||
            /* PROPFIND method
 | 
			
		||||
             * 404 NOT FOUND: path doesn't exist,
 | 
			
		||||
             * 207 MULTI_STATUS: path exists.
 | 
			
		||||
@ -77,7 +80,7 @@ class CheckPathExistenceRemoteOperation(
 | 
			
		||||
            val result = RemoteOperationResult<Boolean>(e)
 | 
			
		||||
            Timber.e(
 | 
			
		||||
                e,
 | 
			
		||||
                "Existence check for ${client.userFilesWebDavUri}${WebdavUtils.encodePath(remotePath)} : ${result.logMessage}"
 | 
			
		||||
                "Existence check for $stringUrl : ${result.logMessage}"
 | 
			
		||||
            )
 | 
			
		||||
            result
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -1,5 +1,5 @@
 | 
			
		||||
/* ownCloud Android Library is available under MIT license
 | 
			
		||||
 *   Copyright (C) 2021 ownCloud GmbH.
 | 
			
		||||
 *   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
 | 
			
		||||
@ -38,17 +38,22 @@ import java.util.concurrent.TimeUnit
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Remote operation moving a remote file or folder in the ownCloud server to a different folder
 | 
			
		||||
 * in the same account.
 | 
			
		||||
 * in the same account and space.
 | 
			
		||||
 *
 | 
			
		||||
 * Allows renaming the moving file/folder at the same time.
 | 
			
		||||
 *
 | 
			
		||||
 * @author David A. Velasco
 | 
			
		||||
 * @author David González Verdugo
 | 
			
		||||
 * @author Abel García de Prada
 | 
			
		||||
 * @author Juan Carlos Garrote Gascón
 | 
			
		||||
 *
 | 
			
		||||
 * @param sourceRemotePath  Remote path of the file/folder to copy.
 | 
			
		||||
 * @param targetRemotePath  Remote path desired for the file/folder to copy it.
 | 
			
		||||
 */
 | 
			
		||||
open class MoveRemoteFileOperation(
 | 
			
		||||
    private val sourceRemotePath: String,
 | 
			
		||||
    private val targetRemotePath: String,
 | 
			
		||||
    private val spaceWebDavUrl: String? = null,
 | 
			
		||||
) : RemoteOperation<Unit>() {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@ -73,8 +78,8 @@ open class MoveRemoteFileOperation(
 | 
			
		||||
            // so this uri has to be customizable
 | 
			
		||||
            val srcWebDavUri = getSrcWebDavUriForClient(client)
 | 
			
		||||
            val moveMethod = MoveMethod(
 | 
			
		||||
                url = URL(srcWebDavUri.toString() + WebdavUtils.encodePath(sourceRemotePath)),
 | 
			
		||||
                destinationUrl = client.userFilesWebDavUri.toString() + WebdavUtils.encodePath(targetRemotePath),
 | 
			
		||||
                url = URL((spaceWebDavUrl ?: srcWebDavUri.toString()) + WebdavUtils.encodePath(sourceRemotePath)),
 | 
			
		||||
                destinationUrl = (spaceWebDavUrl ?: client.userFilesWebDavUri.toString()) + WebdavUtils.encodePath(targetRemotePath),
 | 
			
		||||
            ).apply {
 | 
			
		||||
                addRequestHeaders(this)
 | 
			
		||||
                setReadTimeout(MOVE_READ_TIMEOUT, TimeUnit.SECONDS)
 | 
			
		||||
 | 
			
		||||
@ -1,5 +1,5 @@
 | 
			
		||||
/* ownCloud Android Library is available under MIT license
 | 
			
		||||
 *   Copyright (C) 2020 ownCloud GmbH.
 | 
			
		||||
 *   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
 | 
			
		||||
@ -32,7 +32,8 @@ interface FileService : Service {
 | 
			
		||||
 | 
			
		||||
    fun checkPathExistence(
 | 
			
		||||
        path: String,
 | 
			
		||||
        isUserLogged: Boolean
 | 
			
		||||
        isUserLogged: Boolean,
 | 
			
		||||
        spaceWebDavUrl: String? = null,
 | 
			
		||||
    ): RemoteOperationResult<Boolean>
 | 
			
		||||
 | 
			
		||||
    fun copyFile(
 | 
			
		||||
@ -55,6 +56,7 @@ interface FileService : Service {
 | 
			
		||||
    fun moveFile(
 | 
			
		||||
        sourceRemotePath: String,
 | 
			
		||||
        targetRemotePath: String,
 | 
			
		||||
        spaceWebDavUrl: String?,
 | 
			
		||||
    ): RemoteOperationResult<Unit>
 | 
			
		||||
 | 
			
		||||
    fun readFile(
 | 
			
		||||
 | 
			
		||||
@ -1,5 +1,5 @@
 | 
			
		||||
/* ownCloud Android Library is available under MIT license
 | 
			
		||||
 *   Copyright (C) 2022 ownCloud GmbH.
 | 
			
		||||
 *   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
 | 
			
		||||
@ -42,11 +42,13 @@ class OCFileService(override val client: OwnCloudClient) : FileService {
 | 
			
		||||
 | 
			
		||||
    override fun checkPathExistence(
 | 
			
		||||
        path: String,
 | 
			
		||||
        isUserLogged: Boolean
 | 
			
		||||
        isUserLogged: Boolean,
 | 
			
		||||
        spaceWebDavUrl: String?,
 | 
			
		||||
    ): RemoteOperationResult<Boolean> =
 | 
			
		||||
        CheckPathExistenceRemoteOperation(
 | 
			
		||||
            remotePath = path,
 | 
			
		||||
            isUserLoggedIn = isUserLogged
 | 
			
		||||
            isUserLoggedIn = isUserLogged,
 | 
			
		||||
            spaceWebDavUrl = spaceWebDavUrl,
 | 
			
		||||
        ).execute(client)
 | 
			
		||||
 | 
			
		||||
    override fun getUrlToOpenInWeb(openWebEndpoint: String, fileId: String): RemoteOperationResult<String> =
 | 
			
		||||
@ -86,10 +88,12 @@ class OCFileService(override val client: OwnCloudClient) : FileService {
 | 
			
		||||
    override fun moveFile(
 | 
			
		||||
        sourceRemotePath: String,
 | 
			
		||||
        targetRemotePath: String,
 | 
			
		||||
        spaceWebDavUrl: String?,
 | 
			
		||||
    ): RemoteOperationResult<Unit> =
 | 
			
		||||
        MoveRemoteFileOperation(
 | 
			
		||||
            sourceRemotePath = sourceRemotePath,
 | 
			
		||||
            targetRemotePath = targetRemotePath,
 | 
			
		||||
            spaceWebDavUrl = spaceWebDavUrl,
 | 
			
		||||
        ).execute(client)
 | 
			
		||||
 | 
			
		||||
    override fun readFile(
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user