mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-06 23:46:30 +00:00
Compare commits
24 Commits
2.1-beta.3
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
71224c30d1 | ||
|
c82d75b1d8 | ||
|
530999848f | ||
|
b4625d017c | ||
|
2c698cc2a4 | ||
|
bf183fe04d | ||
|
1f8de383b6 | ||
|
8eb435a1c2 | ||
|
052566d205 | ||
|
063c3fa9e9 | ||
|
fa143804d2 | ||
|
5b64876e2c | ||
|
d81ca97f14 | ||
|
5607f76a1d | ||
|
b4137502d2 | ||
|
261075a8ad | ||
|
c2874357f0 | ||
|
e6937b4210 | ||
|
89dd13cec4 | ||
|
ab3a594e5c | ||
|
cbbe044212 | ||
|
17aa1ea7bd | ||
|
cbf6365e93 | ||
|
15bccd3f80 |
@ -49,6 +49,6 @@ ownCloud Android Library uses OkHttp version 4.6.0, licensed under Apache Licens
|
||||
|
||||
### Compatibility
|
||||
|
||||
ownCloud Android Library is valid for Android systems from version Android 5 (android:minSdkVersion="21" android:targetSdkVersion="29").
|
||||
ownCloud Android Library is valid for Android systems from version Android 6 (android:minSdkVersion="23" android:targetSdkVersion="33").
|
||||
|
||||
ownCloud Android library supports ownCloud server from version 4.5.
|
||||
|
@ -17,7 +17,7 @@ dependencies {
|
||||
ksp "com.squareup.moshi:moshi-kotlin-codegen:$comSquareupMoshi"
|
||||
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
testImplementation 'org.robolectric:robolectric:4.9.2'
|
||||
testImplementation 'org.robolectric:robolectric:4.10'
|
||||
debugImplementation 'com.facebook.stetho:stetho-okhttp3:1.6.0'
|
||||
}
|
||||
|
||||
@ -25,7 +25,7 @@ android {
|
||||
compileSdkVersion 33
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 21
|
||||
minSdkVersion 23
|
||||
targetSdkVersion 33
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- ownCloud Android Library is available under MIT license
|
||||
Copyright (C) 2016 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
|
||||
@ -25,13 +25,6 @@
|
||||
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<!-- USE_CREDENTIALS, MANAGE_ACCOUNTS and AUTHENTICATE_ACCOUNTS are needed for API < 23.
|
||||
In API >= 23 the do not exist anymore -->
|
||||
<uses-permission
|
||||
android:name="android.permission.MANAGE_ACCOUNTS"
|
||||
android:maxSdkVersion="22" />
|
||||
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
|
||||
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
|
||||
</manifest>
|
||||
|
@ -36,7 +36,7 @@ import java.net.URL
|
||||
class CopyMethod(
|
||||
val url: URL,
|
||||
private val destinationUrl: String,
|
||||
private val forceOverride: Boolean = false
|
||||
val forceOverride: Boolean = false
|
||||
) : DavMethod(url) {
|
||||
@Throws(Exception::class)
|
||||
public override fun onDavExecute(davResource: DavOCResource): Int {
|
||||
|
@ -36,7 +36,7 @@ import java.net.URL
|
||||
class MoveMethod(
|
||||
url: URL,
|
||||
private val destinationUrl: String,
|
||||
private val forceOverride: Boolean = false
|
||||
val forceOverride: Boolean = false
|
||||
) : DavMethod(url) {
|
||||
@Throws(Exception::class)
|
||||
override fun onDavExecute(davResource: DavOCResource): Int {
|
||||
|
@ -46,6 +46,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.Serializable;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.ProtocolException;
|
||||
import java.net.SocketException;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.UnknownHostException;
|
||||
@ -166,7 +167,10 @@ public class RemoteOperationResult<T>
|
||||
} else if (e instanceof FileNotFoundException) {
|
||||
mCode = ResultCode.LOCAL_FILE_NOT_FOUND;
|
||||
|
||||
} else {
|
||||
} else if (e instanceof ProtocolException) {
|
||||
mCode = ResultCode.NETWORK_ERROR;
|
||||
}
|
||||
else {
|
||||
mCode = ResultCode.UNKNOWN_ERROR;
|
||||
}
|
||||
}
|
||||
@ -589,5 +593,6 @@ public class RemoteOperationResult<T>
|
||||
SPECIFIC_METHOD_NOT_ALLOWED,
|
||||
SPECIFIC_BAD_REQUEST,
|
||||
TOO_EARLY,
|
||||
NETWORK_ERROR,
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,108 @@
|
||||
/* 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.resources.appregistry
|
||||
|
||||
import com.owncloud.android.lib.common.OwnCloudClient
|
||||
import com.owncloud.android.lib.common.http.HttpConstants
|
||||
import com.owncloud.android.lib.common.http.methods.nonwebdav.PostMethod
|
||||
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.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonAdapter
|
||||
import com.squareup.moshi.JsonClass
|
||||
import com.squareup.moshi.Moshi
|
||||
import okhttp3.FormBody
|
||||
import okhttp3.RequestBody
|
||||
import timber.log.Timber
|
||||
import java.net.URL
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
class CreateRemoteFileWithAppProviderOperation(
|
||||
private val createFileWithAppProviderEndpoint: String,
|
||||
private val parentContainerId: String,
|
||||
private val filename: String,
|
||||
) : RemoteOperation<String>() {
|
||||
|
||||
override fun run(client: OwnCloudClient): RemoteOperationResult<String> {
|
||||
return try {
|
||||
|
||||
val createFileWithAppProviderRequestBody = CreateFileWithAppProviderParams(parentContainerId, filename)
|
||||
.toRequestBody()
|
||||
|
||||
val stringUrl = client.baseUri.toString() + WebdavUtils.encodePath(createFileWithAppProviderEndpoint)
|
||||
|
||||
val postMethod = PostMethod(URL(stringUrl), createFileWithAppProviderRequestBody).apply {
|
||||
setReadTimeout(TIMEOUT, TimeUnit.MILLISECONDS)
|
||||
setConnectionTimeout(TIMEOUT, TimeUnit.MILLISECONDS)
|
||||
}
|
||||
|
||||
val status = client.executeHttpMethod(postMethod)
|
||||
Timber.d("Create file $filename with app provider in folder with ID $parentContainerId - $status${if (!isSuccess(status)) "(FAIL)" else ""}")
|
||||
|
||||
if (isSuccess(status)) RemoteOperationResult<String>(ResultCode.OK).apply {
|
||||
val moshi = Moshi.Builder().build()
|
||||
val adapter: JsonAdapter<CreateFileWithAppProviderResponse> = moshi.adapter(CreateFileWithAppProviderResponse::class.java)
|
||||
|
||||
data = postMethod.getResponseBodyAsString()?.let { adapter.fromJson(it)!!.fileId }
|
||||
}
|
||||
else RemoteOperationResult<String>(postMethod).apply { data = "" }
|
||||
|
||||
} catch (e: Exception) {
|
||||
val result = RemoteOperationResult<String>(e)
|
||||
Timber.e(e, "Create file $filename with app provider in folder with ID $parentContainerId failed")
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
private fun isSuccess(status: Int) = status == HttpConstants.HTTP_OK
|
||||
|
||||
data class CreateFileWithAppProviderParams(
|
||||
val parentContainerId: String,
|
||||
val filename: String,
|
||||
) {
|
||||
fun toRequestBody(): RequestBody =
|
||||
FormBody.Builder()
|
||||
.add(PARAM_PARENT_CONTAINER_ID, parentContainerId)
|
||||
.add(PARAM_FILENAME, filename)
|
||||
.build()
|
||||
|
||||
companion object {
|
||||
const val PARAM_PARENT_CONTAINER_ID = "parent_container_id"
|
||||
const val PARAM_FILENAME = "filename"
|
||||
}
|
||||
}
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class CreateFileWithAppProviderResponse(
|
||||
@Json(name = "file_id")
|
||||
val fileId: String,
|
||||
)
|
||||
|
||||
companion object {
|
||||
private const val TIMEOUT: Long = 5_000
|
||||
}
|
||||
}
|
@ -37,14 +37,14 @@ import com.squareup.moshi.Moshi
|
||||
import timber.log.Timber
|
||||
import java.net.URL
|
||||
|
||||
class GetRemoteAppRegistryOperation : RemoteOperation<AppRegistryResponse>() {
|
||||
class GetRemoteAppRegistryOperation(private val appUrl: String?) : RemoteOperation<AppRegistryResponse>() {
|
||||
|
||||
override fun run(client: OwnCloudClient): RemoteOperationResult<AppRegistryResponse> {
|
||||
var result: RemoteOperationResult<AppRegistryResponse>
|
||||
|
||||
try {
|
||||
val uriBuilder = client.baseUri.buildUpon().apply {
|
||||
appendEncodedPath(APP_REGISTRY_ENDPOINT)
|
||||
appendEncodedPath(appUrl)
|
||||
}
|
||||
val getMethod = GetMethod(URL(uriBuilder.build().toString()))
|
||||
val status = client.executeHttpMethod(getMethod)
|
||||
@ -75,8 +75,4 @@ class GetRemoteAppRegistryOperation : RemoteOperation<AppRegistryResponse>() {
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val APP_REGISTRY_ENDPOINT = "app/list"
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
@ -21,6 +21,7 @@
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.owncloud.android.lib.resources.appregistry
|
||||
|
||||
import com.owncloud.android.lib.common.OwnCloudClient
|
||||
@ -40,9 +41,9 @@ import java.net.URL
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
class GetUrlToOpenInWebRemoteOperation(
|
||||
val openWithWebEndpoint: String,
|
||||
val fileId: String,
|
||||
val appName: String,
|
||||
private val openWithWebEndpoint: String,
|
||||
private val fileId: String,
|
||||
private val appName: String,
|
||||
) : RemoteOperation<String>() {
|
||||
|
||||
override fun run(client: OwnCloudClient): RemoteOperationResult<String> {
|
||||
@ -76,7 +77,7 @@ class GetUrlToOpenInWebRemoteOperation(
|
||||
}
|
||||
}
|
||||
|
||||
private fun isSuccess(status: Int) = status == HttpConstants.HTTP_OK || status == HttpConstants.HTTP_MULTI_STATUS
|
||||
private fun isSuccess(status: Int) = status == HttpConstants.HTTP_OK
|
||||
|
||||
data class OpenInWebParams(
|
||||
val fileId: String,
|
||||
|
@ -20,6 +20,7 @@
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.owncloud.android.lib.resources.appregistry.services
|
||||
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult
|
||||
@ -27,11 +28,17 @@ import com.owncloud.android.lib.resources.Service
|
||||
import com.owncloud.android.lib.resources.appregistry.responses.AppRegistryResponse
|
||||
|
||||
interface AppRegistryService : Service {
|
||||
fun getAppRegistry(): RemoteOperationResult<AppRegistryResponse>
|
||||
fun getAppRegistry(appUrl: String?): RemoteOperationResult<AppRegistryResponse>
|
||||
|
||||
fun getUrlToOpenInWeb(
|
||||
openWebEndpoint: String,
|
||||
fileId: String,
|
||||
appName: String,
|
||||
): RemoteOperationResult<String>
|
||||
|
||||
fun createFileWithAppProvider(
|
||||
createFileWithAppProviderEndpoint: String,
|
||||
parentContainerId: String,
|
||||
filename: String,
|
||||
): RemoteOperationResult<String>
|
||||
}
|
||||
|
@ -20,17 +20,19 @@
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.owncloud.android.lib.resources.appregistry.services
|
||||
|
||||
import com.owncloud.android.lib.common.OwnCloudClient
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult
|
||||
import com.owncloud.android.lib.resources.appregistry.CreateRemoteFileWithAppProviderOperation
|
||||
import com.owncloud.android.lib.resources.appregistry.GetRemoteAppRegistryOperation
|
||||
import com.owncloud.android.lib.resources.appregistry.GetUrlToOpenInWebRemoteOperation
|
||||
import com.owncloud.android.lib.resources.appregistry.responses.AppRegistryResponse
|
||||
|
||||
class OCAppRegistryService(override val client: OwnCloudClient) : AppRegistryService {
|
||||
override fun getAppRegistry(): RemoteOperationResult<AppRegistryResponse> =
|
||||
GetRemoteAppRegistryOperation().execute(client)
|
||||
override fun getAppRegistry(appUrl: String?): RemoteOperationResult<AppRegistryResponse> =
|
||||
GetRemoteAppRegistryOperation(appUrl).execute(client)
|
||||
|
||||
override fun getUrlToOpenInWeb(openWebEndpoint: String, fileId: String, appName: String): RemoteOperationResult<String> =
|
||||
GetUrlToOpenInWebRemoteOperation(
|
||||
@ -38,4 +40,15 @@ class OCAppRegistryService(override val client: OwnCloudClient) : AppRegistrySer
|
||||
fileId = fileId,
|
||||
appName = appName
|
||||
).execute(client)
|
||||
|
||||
override fun createFileWithAppProvider(
|
||||
createFileWithAppProviderEndpoint: String,
|
||||
parentContainerId: String,
|
||||
filename: String
|
||||
): RemoteOperationResult<String> =
|
||||
CreateRemoteFileWithAppProviderOperation(
|
||||
createFileWithAppProviderEndpoint = createFileWithAppProviderEndpoint,
|
||||
parentContainerId = parentContainerId,
|
||||
filename = filename,
|
||||
).execute(client)
|
||||
}
|
||||
|
@ -54,9 +54,8 @@ class CheckPathExistenceRemoteOperation(
|
||||
) : RemoteOperation<Boolean>() {
|
||||
|
||||
override fun run(client: OwnCloudClient): RemoteOperationResult<Boolean> {
|
||||
val baseStringUrl = spaceWebDavUrl ?: if (isUserLoggedIn) client.baseFilesWebDavUri.toString()
|
||||
else client.userFilesWebDavUri.toString()
|
||||
val stringUrl = baseStringUrl + WebdavUtils.encodePath(remotePath)
|
||||
val baseStringUrl = spaceWebDavUrl ?: if (isUserLoggedIn) client.userFilesWebDavUri.toString() else client.baseFilesWebDavUri.toString()
|
||||
val stringUrl = if (isUserLoggedIn) baseStringUrl + WebdavUtils.encodePath(remotePath) else baseStringUrl
|
||||
|
||||
return try {
|
||||
val propFindMethod = PropfindMethod(URL(stringUrl), 0, allPropSet).apply {
|
||||
@ -81,6 +80,7 @@ class CheckPathExistenceRemoteOperation(
|
||||
e,
|
||||
"Existence check for $stringUrl : ${result.logMessage}"
|
||||
)
|
||||
result.data = false
|
||||
result
|
||||
}
|
||||
}
|
||||
|
@ -45,6 +45,7 @@ import java.util.concurrent.TimeUnit
|
||||
* @author Christian Schabesberger
|
||||
* @author David González V.
|
||||
* @author Juan Carlos Garrote Gascón
|
||||
* @author Manuel Plazas Palacio
|
||||
*
|
||||
* @param sourceRemotePath Remote path of the file/folder to copy.
|
||||
* @param targetRemotePath Remote path desired for the file/folder to copy it.
|
||||
@ -54,6 +55,7 @@ class CopyRemoteFileOperation(
|
||||
private val targetRemotePath: String,
|
||||
private val sourceSpaceWebDavUrl: String? = null,
|
||||
private val targetSpaceWebDavUrl: String? = null,
|
||||
private val forceOverride: Boolean = false,
|
||||
) : RemoteOperation<String>() {
|
||||
|
||||
/**
|
||||
@ -74,9 +76,11 @@ class CopyRemoteFileOperation(
|
||||
var result: RemoteOperationResult<String>
|
||||
try {
|
||||
val copyMethod = CopyMethod(
|
||||
URL((sourceSpaceWebDavUrl ?: client.userFilesWebDavUri.toString()) + WebdavUtils.encodePath(sourceRemotePath)),
|
||||
(targetSpaceWebDavUrl ?: client.userFilesWebDavUri.toString()) + WebdavUtils.encodePath(targetRemotePath),
|
||||
url = URL((sourceSpaceWebDavUrl ?: client.userFilesWebDavUri.toString()) + WebdavUtils.encodePath(sourceRemotePath)),
|
||||
destinationUrl = (targetSpaceWebDavUrl ?: client.userFilesWebDavUri.toString()) + WebdavUtils.encodePath(targetRemotePath),
|
||||
forceOverride = forceOverride,
|
||||
).apply {
|
||||
addRequestHeaders(this)
|
||||
setReadTimeout(COPY_READ_TIMEOUT, TimeUnit.SECONDS)
|
||||
setConnectionTimeout(COPY_CONNECTION_TIMEOUT, TimeUnit.SECONDS)
|
||||
}
|
||||
@ -87,6 +91,7 @@ class CopyRemoteFileOperation(
|
||||
result = RemoteOperationResult(ResultCode.OK)
|
||||
result.setData(fileRemoteId)
|
||||
}
|
||||
|
||||
isPreconditionFailed(status) -> {
|
||||
result = RemoteOperationResult(ResultCode.INVALID_OVERWRITE)
|
||||
client.exhaustResponse(copyMethod.getResponseBodyAsStream())
|
||||
@ -94,6 +99,7 @@ class CopyRemoteFileOperation(
|
||||
/// for other errors that could be explicitly handled, check first:
|
||||
/// http://www.webdav.org/specs/rfc4918.html#rfc.section.9.9.4
|
||||
}
|
||||
|
||||
else -> {
|
||||
result = RemoteOperationResult(copyMethod)
|
||||
client.exhaustResponse(copyMethod.getResponseBodyAsStream())
|
||||
@ -107,6 +113,13 @@ class CopyRemoteFileOperation(
|
||||
return result
|
||||
}
|
||||
|
||||
private fun addRequestHeaders(copyMethod: CopyMethod) {
|
||||
//Adding this because the library has an error with override
|
||||
if (copyMethod.forceOverride) {
|
||||
copyMethod.setRequestHeader(OVERWRITE, TRUE)
|
||||
}
|
||||
}
|
||||
|
||||
private fun isSuccess(status: Int) = status.isOneOf(HttpConstants.HTTP_CREATED, HttpConstants.HTTP_NO_CONTENT)
|
||||
|
||||
private fun isPreconditionFailed(status: Int) = status == HttpConstants.HTTP_PRECONDITION_FAILED
|
||||
@ -114,5 +127,7 @@ class CopyRemoteFileOperation(
|
||||
companion object {
|
||||
private const val COPY_READ_TIMEOUT = 10L
|
||||
private const val COPY_CONNECTION_TIMEOUT = 6L
|
||||
private const val OVERWRITE = "overwrite"
|
||||
private const val TRUE = "T"
|
||||
}
|
||||
}
|
||||
|
@ -46,6 +46,7 @@ import java.util.concurrent.TimeUnit
|
||||
* @author David González Verdugo
|
||||
* @author Abel García de Prada
|
||||
* @author Juan Carlos Garrote Gascón
|
||||
* @author Manuel Plazas Palacio
|
||||
*
|
||||
* @param sourceRemotePath Remote path of the file/folder to copy.
|
||||
* @param targetRemotePath Remote path desired for the file/folder to copy it.
|
||||
@ -54,6 +55,7 @@ open class MoveRemoteFileOperation(
|
||||
private val sourceRemotePath: String,
|
||||
private val targetRemotePath: String,
|
||||
private val spaceWebDavUrl: String? = null,
|
||||
private val forceOverride: Boolean = false,
|
||||
) : RemoteOperation<Unit>() {
|
||||
|
||||
/**
|
||||
@ -80,6 +82,7 @@ open class MoveRemoteFileOperation(
|
||||
val moveMethod = MoveMethod(
|
||||
url = URL((spaceWebDavUrl ?: srcWebDavUri.toString()) + WebdavUtils.encodePath(sourceRemotePath)),
|
||||
destinationUrl = (spaceWebDavUrl ?: client.userFilesWebDavUri.toString()) + WebdavUtils.encodePath(targetRemotePath),
|
||||
forceOverride = forceOverride,
|
||||
).apply {
|
||||
addRequestHeaders(this)
|
||||
setReadTimeout(MOVE_READ_TIMEOUT, TimeUnit.SECONDS)
|
||||
@ -92,6 +95,7 @@ open class MoveRemoteFileOperation(
|
||||
isSuccess(status) -> {
|
||||
result = RemoteOperationResult<Unit>(ResultCode.OK)
|
||||
}
|
||||
|
||||
isPreconditionFailed(status) -> {
|
||||
result = RemoteOperationResult<Unit>(ResultCode.INVALID_OVERWRITE)
|
||||
client.exhaustResponse(moveMethod.getResponseBodyAsStream())
|
||||
@ -99,6 +103,7 @@ open class MoveRemoteFileOperation(
|
||||
/// for other errors that could be explicitly handled, check first:
|
||||
/// http://www.webdav.org/specs/rfc4918.html#rfc.section.9.9.4
|
||||
}
|
||||
|
||||
else -> {
|
||||
result = RemoteOperationResult<Unit>(moveMethod)
|
||||
client.exhaustResponse(moveMethod.getResponseBodyAsStream())
|
||||
@ -125,6 +130,10 @@ open class MoveRemoteFileOperation(
|
||||
* In case new headers are needed, override this method
|
||||
*/
|
||||
open fun addRequestHeaders(moveMethod: MoveMethod) {
|
||||
//Adding this because the library has an error with override
|
||||
if (moveMethod.forceOverride) {
|
||||
moveMethod.setRequestHeader(OVERWRITE, TRUE)
|
||||
}
|
||||
}
|
||||
|
||||
private fun isSuccess(status: Int) = status.isOneOf(HttpConstants.HTTP_CREATED, HttpConstants.HTTP_NO_CONTENT)
|
||||
@ -134,5 +143,7 @@ open class MoveRemoteFileOperation(
|
||||
companion object {
|
||||
private const val MOVE_READ_TIMEOUT = 10L
|
||||
private const val MOVE_CONNECTION_TIMEOUT = 6L
|
||||
private const val OVERWRITE = "overwrite"
|
||||
private const val TRUE = "T"
|
||||
}
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ class RenameRemoteFileOperation(
|
||||
* @return 'True' if the target path is already used by an existing file.
|
||||
*/
|
||||
private fun targetPathIsUsed(client: OwnCloudClient): Boolean {
|
||||
val checkPathExistenceRemoteOperation = CheckPathExistenceRemoteOperation(newRemotePath, false)
|
||||
val checkPathExistenceRemoteOperation = CheckPathExistenceRemoteOperation(newRemotePath, true)
|
||||
val exists = checkPathExistenceRemoteOperation.execute(client)
|
||||
return exists.isSuccess
|
||||
}
|
||||
|
@ -39,7 +39,8 @@ interface FileService : Service {
|
||||
targetRemotePath: String,
|
||||
sourceSpaceWebDavUrl: String?,
|
||||
targetSpaceWebDavUrl: String?,
|
||||
): RemoteOperationResult<String>
|
||||
replace: Boolean,
|
||||
): RemoteOperationResult<String?>
|
||||
|
||||
fun createFolder(
|
||||
remotePath: String,
|
||||
@ -57,6 +58,7 @@ interface FileService : Service {
|
||||
sourceRemotePath: String,
|
||||
targetRemotePath: String,
|
||||
spaceWebDavUrl: String?,
|
||||
replace: Boolean,
|
||||
): RemoteOperationResult<Unit>
|
||||
|
||||
fun readFile(
|
||||
|
@ -54,12 +54,14 @@ class OCFileService(override val client: OwnCloudClient) : FileService {
|
||||
targetRemotePath: String,
|
||||
sourceSpaceWebDavUrl: String?,
|
||||
targetSpaceWebDavUrl: String?,
|
||||
): RemoteOperationResult<String> =
|
||||
replace: Boolean,
|
||||
): RemoteOperationResult<String?> =
|
||||
CopyRemoteFileOperation(
|
||||
sourceRemotePath = sourceRemotePath,
|
||||
targetRemotePath = targetRemotePath,
|
||||
sourceSpaceWebDavUrl = sourceSpaceWebDavUrl,
|
||||
targetSpaceWebDavUrl = targetSpaceWebDavUrl,
|
||||
forceOverride = replace,
|
||||
).execute(client)
|
||||
|
||||
override fun createFolder(
|
||||
@ -88,11 +90,13 @@ class OCFileService(override val client: OwnCloudClient) : FileService {
|
||||
sourceRemotePath: String,
|
||||
targetRemotePath: String,
|
||||
spaceWebDavUrl: String?,
|
||||
replace: Boolean,
|
||||
): RemoteOperationResult<Unit> =
|
||||
MoveRemoteFileOperation(
|
||||
sourceRemotePath = sourceRemotePath,
|
||||
targetRemotePath = targetRemotePath,
|
||||
spaceWebDavUrl = spaceWebDavUrl,
|
||||
forceOverride = replace,
|
||||
).execute(client)
|
||||
|
||||
override fun readFile(
|
||||
|
@ -89,8 +89,6 @@ class CreateRemoteShareOperation(
|
||||
|
||||
var expirationDateInMillis: Long = INIT_EXPIRATION_DATE_IN_MILLIS // Expiration date to set for the public link
|
||||
|
||||
var publicUpload: Boolean = false // Upload permissions for the public link (only folders)
|
||||
|
||||
var retrieveShareDetails = false // To retrieve more info about the just created share
|
||||
|
||||
private fun buildRequestUri(baseUri: Uri) =
|
||||
@ -99,7 +97,7 @@ class CreateRemoteShareOperation(
|
||||
.appendQueryParameter(PARAM_FORMAT, VALUE_FORMAT)
|
||||
.build()
|
||||
|
||||
private fun parseResponse(response: String): ShareResponse? {
|
||||
private fun parseResponse(response: String): ShareResponse {
|
||||
val moshi = Moshi.Builder().build()
|
||||
val commonOcsType: Type = Types.newParameterizedType(CommonOcsResponse::class.java, ShareItem::class.java)
|
||||
val adapter: JsonAdapter<CommonOcsResponse<ShareItem>> = moshi.adapter(commonOcsType)
|
||||
@ -155,12 +153,10 @@ class CreateRemoteShareOperation(
|
||||
formBodyBuilder.add(PARAM_EXPIRATION_DATE, formattedExpirationDate)
|
||||
}
|
||||
|
||||
if (publicUpload) {
|
||||
formBodyBuilder.add(PARAM_PUBLIC_UPLOAD, publicUpload.toString())
|
||||
}
|
||||
if (password.isNotEmpty()) {
|
||||
formBodyBuilder.add(PARAM_PASSWORD, password)
|
||||
}
|
||||
|
||||
if (RemoteShare.DEFAULT_PERMISSION != permissions) {
|
||||
formBodyBuilder.add(PARAM_PERMISSIONS, permissions.toString())
|
||||
}
|
||||
@ -207,7 +203,6 @@ class CreateRemoteShareOperation(
|
||||
private const val PARAM_SHARE_TYPE = "shareType"
|
||||
private const val PARAM_SHARE_WITH = "shareWith"
|
||||
private const val PARAM_PASSWORD = "password"
|
||||
private const val PARAM_PUBLIC_UPLOAD = "publicUpload"
|
||||
private const val PARAM_PERMISSIONS = "permissions"
|
||||
|
||||
//Arguments - constant values
|
||||
|
@ -103,13 +103,6 @@ class UpdateRemoteShareOperation
|
||||
*/
|
||||
var permissions: Int = DEFAULT_PERMISSION
|
||||
|
||||
/**
|
||||
* Enable upload permissions to update in Share resource.
|
||||
*
|
||||
* Null results in no update applied to the upload permission.
|
||||
*/
|
||||
var publicUpload: Boolean? = null
|
||||
|
||||
var retrieveShareDetails = false // To retrieve more info about the just updated share
|
||||
|
||||
private fun buildRequestUri(baseUri: Uri) =
|
||||
@ -119,7 +112,7 @@ class UpdateRemoteShareOperation
|
||||
.appendQueryParameter(PARAM_FORMAT, VALUE_FORMAT)
|
||||
.build()
|
||||
|
||||
private fun parseResponse(response: String): ShareResponse? {
|
||||
private fun parseResponse(response: String): ShareResponse {
|
||||
val moshi = Moshi.Builder().build()
|
||||
val commonOcsType: Type = Types.newParameterizedType(CommonOcsResponse::class.java, ShareItem::class.java)
|
||||
val adapter: JsonAdapter<CommonOcsResponse<ShareItem>> = moshi.adapter(commonOcsType)
|
||||
@ -181,10 +174,6 @@ class UpdateRemoteShareOperation
|
||||
formBodyBuilder.add(PARAM_EXPIRATION_DATE, formattedExpirationDate)
|
||||
} // else, ignore - no update
|
||||
|
||||
if (publicUpload != null) {
|
||||
formBodyBuilder.add(PARAM_PUBLIC_UPLOAD, publicUpload.toString())
|
||||
}
|
||||
|
||||
// IMPORTANT: permissions parameter needs to be updated after mPublicUpload parameter,
|
||||
// otherwise they would be set always as 1 (READ) in the server when mPublicUpload was updated
|
||||
if (permissions > DEFAULT_PERMISSION) {
|
||||
@ -233,7 +222,6 @@ class UpdateRemoteShareOperation
|
||||
private const val PARAM_PASSWORD = "password"
|
||||
private const val PARAM_EXPIRATION_DATE = "expireDate"
|
||||
private const val PARAM_PERMISSIONS = "permissions"
|
||||
private const val PARAM_PUBLIC_UPLOAD = "publicUpload"
|
||||
|
||||
//Arguments - constant values
|
||||
private const val FORMAT_EXPIRATION_DATE = "yyyy-MM-dd"
|
||||
|
@ -46,7 +46,6 @@ interface ShareService : Service {
|
||||
name: String,
|
||||
password: String,
|
||||
expirationDate: Long,
|
||||
publicUpload: Boolean
|
||||
): RemoteOperationResult<ShareResponse>
|
||||
|
||||
fun updateShare(
|
||||
@ -55,7 +54,6 @@ interface ShareService : Service {
|
||||
password: String?,
|
||||
expirationDate: Long,
|
||||
permissions: Int,
|
||||
publicUpload: Boolean
|
||||
): RemoteOperationResult<ShareResponse>
|
||||
|
||||
fun deleteShare(remoteId: String): RemoteOperationResult<Unit>
|
||||
|
@ -55,7 +55,6 @@ class OCShareService(override val client: OwnCloudClient) : ShareService {
|
||||
name: String,
|
||||
password: String,
|
||||
expirationDate: Long,
|
||||
publicUpload: Boolean
|
||||
): RemoteOperationResult<ShareResponse> =
|
||||
CreateRemoteShareOperation(
|
||||
remoteFilePath,
|
||||
@ -66,7 +65,6 @@ class OCShareService(override val client: OwnCloudClient) : ShareService {
|
||||
this.name = name
|
||||
this.password = password
|
||||
this.expirationDateInMillis = expirationDate
|
||||
this.publicUpload = publicUpload
|
||||
this.retrieveShareDetails = true
|
||||
}.execute(client)
|
||||
|
||||
@ -76,7 +74,6 @@ class OCShareService(override val client: OwnCloudClient) : ShareService {
|
||||
password: String?,
|
||||
expirationDate: Long,
|
||||
permissions: Int,
|
||||
publicUpload: Boolean
|
||||
): RemoteOperationResult<ShareResponse> =
|
||||
UpdateRemoteShareOperation(
|
||||
remoteId
|
||||
@ -85,7 +82,6 @@ class OCShareService(override val client: OwnCloudClient) : ShareService {
|
||||
this.password = password
|
||||
this.expirationDateInMillis = expirationDate
|
||||
this.permissions = permissions
|
||||
this.publicUpload = publicUpload
|
||||
this.retrieveShareDetails = true
|
||||
}.execute(client)
|
||||
|
||||
|
@ -40,7 +40,7 @@ class OCServerInfoService : ServerInfoService {
|
||||
): RemoteOperationResult<Boolean> =
|
||||
CheckPathExistenceRemoteOperation(
|
||||
remotePath = path,
|
||||
isUserLoggedIn = true,
|
||||
isUserLoggedIn = isUserLoggedIn,
|
||||
).execute(client)
|
||||
|
||||
override fun getRemoteStatus(
|
||||
|
Loading…
x
Reference in New Issue
Block a user