mirror of
https://github.com/nextcloud/android-library.git
synced 2025-07-21 23:47:23 +00:00

committed by
Surinder Kumar

parent
3c1436e84c
commit
5da3690fab
@ -39,60 +39,62 @@ class CopyFileToAlbumRemoteOperation @JvmOverloads constructor(
|
||||
* @param client Client object to communicate with the remote ownCloud server.
|
||||
*/
|
||||
@Deprecated("Deprecated in Java")
|
||||
@Suppress("TooGenericExceptionCaught")
|
||||
override fun run(client: OwnCloudClient): RemoteOperationResult<Any> {
|
||||
/** check parameters */
|
||||
|
||||
var result: RemoteOperationResult<Any>
|
||||
if (mTargetRemotePath == mSrcRemotePath) {
|
||||
// nothing to do!
|
||||
return RemoteOperationResult(ResultCode.OK)
|
||||
}
|
||||
result = RemoteOperationResult(ResultCode.OK)
|
||||
} else if (mTargetRemotePath.startsWith(mSrcRemotePath)) {
|
||||
result = RemoteOperationResult(ResultCode.INVALID_COPY_INTO_DESCENDANT)
|
||||
} else {
|
||||
/** perform remote operation */
|
||||
var copyMethod: CopyMethod? = null
|
||||
try {
|
||||
copyMethod = CopyMethod(
|
||||
client.getFilesDavUri(this.mSrcRemotePath),
|
||||
"${client.baseUri}/remote.php/dav/photos/${client.userId}/albums${
|
||||
WebdavUtils.encodePath(
|
||||
mTargetRemotePath
|
||||
)
|
||||
}",
|
||||
false
|
||||
)
|
||||
val status = client.executeMethod(
|
||||
copyMethod,
|
||||
sessionTimeOut.readTimeOut,
|
||||
sessionTimeOut.connectionTimeOut
|
||||
)
|
||||
|
||||
if (mTargetRemotePath.startsWith(mSrcRemotePath)) {
|
||||
return RemoteOperationResult(ResultCode.INVALID_COPY_INTO_DESCENDANT)
|
||||
}
|
||||
/** process response */
|
||||
result = when (status) {
|
||||
HttpStatus.SC_MULTI_STATUS -> processPartialError(copyMethod)
|
||||
HttpStatus.SC_PRECONDITION_FAILED -> {
|
||||
client.exhaustResponse(copyMethod.responseBodyAsStream)
|
||||
RemoteOperationResult<Any>(ResultCode.INVALID_OVERWRITE)
|
||||
}
|
||||
|
||||
/** perform remote operation */
|
||||
var copyMethod: CopyMethod? = null
|
||||
var result: RemoteOperationResult<Any>
|
||||
try {
|
||||
copyMethod = CopyMethod(
|
||||
client.getFilesDavUri(this.mSrcRemotePath),
|
||||
"${client.baseUri}/remote.php/dav/photos/${client.userId}/albums${
|
||||
WebdavUtils.encodePath(
|
||||
mTargetRemotePath
|
||||
)
|
||||
}",
|
||||
false
|
||||
)
|
||||
val status = client.executeMethod(
|
||||
copyMethod,
|
||||
sessionTimeOut.readTimeOut,
|
||||
sessionTimeOut.connectionTimeOut
|
||||
)
|
||||
else -> {
|
||||
client.exhaustResponse(copyMethod.responseBodyAsStream)
|
||||
RemoteOperationResult<Any>(isSuccess(status), copyMethod)
|
||||
}
|
||||
}
|
||||
|
||||
/** process response */
|
||||
if (status == HttpStatus.SC_MULTI_STATUS) {
|
||||
result = processPartialError(copyMethod)
|
||||
} else if (status == HttpStatus.SC_PRECONDITION_FAILED) {
|
||||
result = RemoteOperationResult<Any>(ResultCode.INVALID_OVERWRITE)
|
||||
client.exhaustResponse(copyMethod.responseBodyAsStream)
|
||||
} else {
|
||||
result = RemoteOperationResult<Any>(isSuccess(status), copyMethod)
|
||||
client.exhaustResponse(copyMethod.responseBodyAsStream)
|
||||
Log.i(
|
||||
TAG,
|
||||
"Copy $mSrcRemotePath to $mTargetRemotePath : ${result.logMessage}"
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
result = RemoteOperationResult<Any>(e)
|
||||
Log.e(
|
||||
TAG,
|
||||
"Copy $mSrcRemotePath to $mTargetRemotePath : ${result.logMessage}", e
|
||||
)
|
||||
} finally {
|
||||
copyMethod?.releaseConnection()
|
||||
}
|
||||
|
||||
Log.i(
|
||||
TAG,
|
||||
"Copy $mSrcRemotePath to $mTargetRemotePath : ${result.logMessage}"
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
result = RemoteOperationResult<Any>(e)
|
||||
Log.e(
|
||||
TAG,
|
||||
"Copy $mSrcRemotePath to $mTargetRemotePath : ${result.logMessage}", e
|
||||
)
|
||||
} finally {
|
||||
copyMethod?.releaseConnection()
|
||||
}
|
||||
|
||||
return result
|
||||
@ -128,7 +130,7 @@ class CopyFileToAlbumRemoteOperation @JvmOverloads constructor(
|
||||
var i = 0
|
||||
while (i < responses.size && !failFound) {
|
||||
status = responses[i].status
|
||||
failFound = (!status.isNullOrEmpty() && status[0].statusCode > 299
|
||||
failFound = (!status.isNullOrEmpty() && status[0].statusCode > FAILED_STATUS_CODE
|
||||
)
|
||||
i++
|
||||
}
|
||||
@ -147,5 +149,6 @@ class CopyFileToAlbumRemoteOperation @JvmOverloads constructor(
|
||||
|
||||
companion object {
|
||||
private val TAG: String = CopyFileToAlbumRemoteOperation::class.java.simpleName
|
||||
private const val FAILED_STATUS_CODE = 299
|
||||
}
|
||||
}
|
||||
|
@ -13,58 +13,60 @@ 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.utils.Log_OC
|
||||
import com.owncloud.android.lib.resources.albums.CreateNewAlbumRemoteOperation
|
||||
import org.apache.commons.httpclient.HttpStatus
|
||||
import org.apache.jackrabbit.webdav.client.methods.MkColMethod
|
||||
|
||||
class CreateNewAlbumRemoteOperation @JvmOverloads constructor(
|
||||
val newAlbumName: String,
|
||||
private val sessionTimeOut: SessionTimeOut = defaultSessionTimeOut
|
||||
) :
|
||||
RemoteOperation<Void>() {
|
||||
/**
|
||||
* Performs the operation.
|
||||
*
|
||||
* @param client Client object to communicate with the remote ownCloud server.
|
||||
*/
|
||||
@Deprecated("Deprecated in Java")
|
||||
override fun run(client: OwnCloudClient): RemoteOperationResult<Void> {
|
||||
var mkCol: MkColMethod? = null
|
||||
var result: RemoteOperationResult<Void>
|
||||
try {
|
||||
mkCol = MkColMethod(
|
||||
"${client.baseUri}/remote.php/dav/photos/${client.userId}/albums${
|
||||
WebdavUtils.encodePath(
|
||||
newAlbumName
|
||||
class CreateNewAlbumRemoteOperation
|
||||
@JvmOverloads
|
||||
constructor(
|
||||
val newAlbumName: String,
|
||||
private val sessionTimeOut: SessionTimeOut = defaultSessionTimeOut
|
||||
) : RemoteOperation<Void>() {
|
||||
/**
|
||||
* Performs the operation.
|
||||
*
|
||||
* @param client Client object to communicate with the remote ownCloud server.
|
||||
*/
|
||||
@Deprecated("Deprecated in Java")
|
||||
@Suppress("TooGenericExceptionCaught")
|
||||
override fun run(client: OwnCloudClient): RemoteOperationResult<Void> {
|
||||
var mkCol: MkColMethod? = null
|
||||
var result: RemoteOperationResult<Void>
|
||||
try {
|
||||
mkCol =
|
||||
MkColMethod(
|
||||
"${client.baseUri}/remote.php/dav/photos/${client.userId}/albums${
|
||||
WebdavUtils.encodePath(
|
||||
newAlbumName
|
||||
)
|
||||
}"
|
||||
)
|
||||
}"
|
||||
)
|
||||
client.executeMethod(
|
||||
mkCol,
|
||||
sessionTimeOut.readTimeOut,
|
||||
sessionTimeOut.connectionTimeOut
|
||||
)
|
||||
if (HttpStatus.SC_METHOD_NOT_ALLOWED == mkCol.statusCode) {
|
||||
result =
|
||||
RemoteOperationResult(RemoteOperationResult.ResultCode.FOLDER_ALREADY_EXISTS)
|
||||
} else {
|
||||
result = RemoteOperationResult(mkCol.succeeded(), mkCol)
|
||||
result.resultData = null
|
||||
client.executeMethod(
|
||||
mkCol,
|
||||
sessionTimeOut.readTimeOut,
|
||||
sessionTimeOut.connectionTimeOut
|
||||
)
|
||||
if (HttpStatus.SC_METHOD_NOT_ALLOWED == mkCol.statusCode) {
|
||||
result =
|
||||
RemoteOperationResult(RemoteOperationResult.ResultCode.FOLDER_ALREADY_EXISTS)
|
||||
} else {
|
||||
result = RemoteOperationResult(mkCol.succeeded(), mkCol)
|
||||
result.resultData = null
|
||||
}
|
||||
|
||||
Log_OC.d(TAG, "Create album $newAlbumName : ${result.logMessage}")
|
||||
client.exhaustResponse(mkCol.responseBodyAsStream)
|
||||
} catch (e: Exception) {
|
||||
result = RemoteOperationResult(e)
|
||||
Log_OC.e(TAG, "Create album $newAlbumName : ${result.logMessage}", e)
|
||||
} finally {
|
||||
mkCol?.releaseConnection()
|
||||
}
|
||||
|
||||
Log_OC.d(TAG, "Create album $newAlbumName : ${result.logMessage}")
|
||||
client.exhaustResponse(mkCol.responseBodyAsStream)
|
||||
} catch (e: Exception) {
|
||||
result = RemoteOperationResult(e)
|
||||
Log_OC.e(TAG, "Create album $newAlbumName : ${result.logMessage}", e)
|
||||
} finally {
|
||||
mkCol?.releaseConnection()
|
||||
return result
|
||||
}
|
||||
|
||||
return result
|
||||
companion object {
|
||||
private val TAG: String = CreateNewAlbumRemoteOperation::class.java.simpleName
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val TAG: String = CreateNewAlbumRemoteOperation::class.java.simpleName
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,9 @@ import java.text.SimpleDateFormat
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
|
||||
class PhotoAlbumEntry(response: MultiStatusResponse) {
|
||||
class PhotoAlbumEntry(
|
||||
response: MultiStatusResponse
|
||||
) {
|
||||
val href: String
|
||||
val lastPhoto: Long
|
||||
val nbItems: Int
|
||||
@ -28,6 +30,7 @@ class PhotoAlbumEntry(response: MultiStatusResponse) {
|
||||
|
||||
companion object {
|
||||
private val dateFormat = SimpleDateFormat("MMM yyyy", Locale.US)
|
||||
private const val MILLIS = 1000L
|
||||
}
|
||||
|
||||
init {
|
||||
@ -42,27 +45,28 @@ class PhotoAlbumEntry(response: MultiStatusResponse) {
|
||||
this.dateRange = parseString(properties, WebdavEntry.PROPERTY_DATE_RANGE)
|
||||
}
|
||||
|
||||
private fun parseString(props: DavPropertySet, name: String): String? {
|
||||
private fun parseString(
|
||||
props: DavPropertySet,
|
||||
name: String
|
||||
): String? {
|
||||
val propName = DavPropertyName.create(name, Namespace.getNamespace("nc", WebdavEntry.NAMESPACE_NC))
|
||||
val prop = props[propName]
|
||||
return if (prop != null && prop.value != null) prop.value.toString() else null
|
||||
}
|
||||
|
||||
private fun parseInt(value: String?): Int {
|
||||
return try {
|
||||
private fun parseInt(value: String?): Int =
|
||||
try {
|
||||
value?.toInt() ?: 0
|
||||
} catch (_: NumberFormatException) {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
private fun parseLong(value: String?): Long {
|
||||
return try {
|
||||
private fun parseLong(value: String?): Long =
|
||||
try {
|
||||
value?.toLong() ?: 0L
|
||||
} catch (_: NumberFormatException) {
|
||||
0L
|
||||
}
|
||||
}
|
||||
|
||||
val albumName: String
|
||||
get() {
|
||||
@ -79,13 +83,14 @@ class PhotoAlbumEntry(response: MultiStatusResponse) {
|
||||
return try {
|
||||
val obj = JSONObject(dateRange ?: return dateFormat.format(currentDate))
|
||||
val startTimestamp = obj.optLong("start", 0)
|
||||
if (startTimestamp > 0)
|
||||
dateFormat.format(Date(startTimestamp * 1000L))
|
||||
else
|
||||
if (startTimestamp > 0) {
|
||||
dateFormat.format(Date(startTimestamp * MILLIS))
|
||||
} else {
|
||||
dateFormat.format(currentDate)
|
||||
}
|
||||
} catch (e: JSONException) {
|
||||
e.printStackTrace()
|
||||
dateFormat.format(currentDate)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,83 +19,77 @@ import org.apache.commons.httpclient.HttpStatus
|
||||
import org.apache.jackrabbit.webdav.DavConstants
|
||||
import org.apache.jackrabbit.webdav.client.methods.PropFindMethod
|
||||
|
||||
class ReadAlbumItemsRemoteOperation @JvmOverloads constructor(
|
||||
private val mRemotePath: String,
|
||||
private val sessionTimeOut: SessionTimeOut = defaultSessionTimeOut
|
||||
) :
|
||||
RemoteOperation<List<RemoteFile>>() {
|
||||
@Deprecated("Deprecated in Java")
|
||||
override fun run(client: OwnCloudClient): RemoteOperationResult<List<RemoteFile>> {
|
||||
var result: RemoteOperationResult<List<RemoteFile>>? = null
|
||||
var query: PropFindMethod? = null
|
||||
val url = "${client.baseUri}/remote.php/dav/photos/${client.userId}/albums${
|
||||
WebdavUtils.encodePath(
|
||||
mRemotePath
|
||||
)
|
||||
}"
|
||||
try {
|
||||
// remote request
|
||||
query = PropFindMethod(
|
||||
url,
|
||||
WebdavUtils.getAllPropSet(), // PropFind Properties
|
||||
DavConstants.DEPTH_1
|
||||
)
|
||||
val status = client.executeMethod(
|
||||
query,
|
||||
sessionTimeOut.readTimeOut,
|
||||
sessionTimeOut.connectionTimeOut
|
||||
)
|
||||
|
||||
// check and process response
|
||||
val isSuccess = (status == HttpStatus.SC_MULTI_STATUS || status == HttpStatus.SC_OK)
|
||||
|
||||
if (isSuccess) {
|
||||
// get data from remote folder
|
||||
val dataInServer = query.responseBodyAsMultiStatus
|
||||
val mFolderAndFiles = WebDavFileUtils().readAlbumData(dataInServer, client)
|
||||
|
||||
// Result of the operation
|
||||
result = RemoteOperationResult(true, query)
|
||||
// Add data to the result
|
||||
if (result.isSuccess) {
|
||||
result.resultData = mFolderAndFiles
|
||||
}
|
||||
} else {
|
||||
// synchronization failed
|
||||
client.exhaustResponse(query.responseBodyAsStream)
|
||||
result = RemoteOperationResult(false, query)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
result = RemoteOperationResult(e)
|
||||
} finally {
|
||||
query?.releaseConnection()
|
||||
|
||||
if (result == null) {
|
||||
result = RemoteOperationResult<List<RemoteFile>>(Exception("unknown error"))
|
||||
Log_OC.e(
|
||||
TAG,
|
||||
"Synchronized $mRemotePath: failed"
|
||||
class ReadAlbumItemsRemoteOperation
|
||||
@JvmOverloads
|
||||
constructor(
|
||||
private val mRemotePath: String,
|
||||
private val sessionTimeOut: SessionTimeOut = defaultSessionTimeOut
|
||||
) : RemoteOperation<List<RemoteFile>>() {
|
||||
@Deprecated("Deprecated in Java")
|
||||
@Suppress("TooGenericExceptionCaught")
|
||||
override fun run(client: OwnCloudClient): RemoteOperationResult<List<RemoteFile>> {
|
||||
var result: RemoteOperationResult<List<RemoteFile>>? = null
|
||||
var query: PropFindMethod? = null
|
||||
val url = "${client.baseUri}/remote.php/dav/photos/${client.userId}/albums${
|
||||
WebdavUtils.encodePath(
|
||||
mRemotePath
|
||||
)
|
||||
} else {
|
||||
}"
|
||||
try {
|
||||
// remote request
|
||||
query =
|
||||
PropFindMethod(
|
||||
url,
|
||||
WebdavUtils.getAllPropSet(), // PropFind Properties
|
||||
DavConstants.DEPTH_1
|
||||
)
|
||||
val status =
|
||||
client.executeMethod(
|
||||
query,
|
||||
sessionTimeOut.readTimeOut,
|
||||
sessionTimeOut.connectionTimeOut
|
||||
)
|
||||
|
||||
// check and process response
|
||||
val isSuccess = (status == HttpStatus.SC_MULTI_STATUS || status == HttpStatus.SC_OK)
|
||||
|
||||
result =
|
||||
if (isSuccess) {
|
||||
// get data from remote folder
|
||||
val dataInServer = query.responseBodyAsMultiStatus
|
||||
val mFolderAndFiles = WebDavFileUtils().readAlbumData(dataInServer, client)
|
||||
|
||||
// Result of the operation
|
||||
RemoteOperationResult<List<RemoteFile>>(true, query).apply {
|
||||
// Add data to the result
|
||||
resultData = mFolderAndFiles
|
||||
}
|
||||
} else {
|
||||
// synchronization failed
|
||||
client.exhaustResponse(query.responseBodyAsStream)
|
||||
RemoteOperationResult(false, query)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
result = RemoteOperationResult(e)
|
||||
} finally {
|
||||
query?.releaseConnection()
|
||||
|
||||
result = result ?: RemoteOperationResult<List<RemoteFile>>(Exception("unknown error")).also {
|
||||
Log_OC.e(TAG, "Synchronized $mRemotePath: failed")
|
||||
}
|
||||
if (result.isSuccess) {
|
||||
Log_OC.i(TAG, "Synchronized $mRemotePath : ${result.logMessage}")
|
||||
} else if (result.isException) {
|
||||
Log_OC.e(TAG, "Synchronized $mRemotePath : ${result.logMessage}", result.exception)
|
||||
} else {
|
||||
if (result.isException) {
|
||||
Log_OC.e(
|
||||
TAG, "Synchronized $mRemotePath : ${result.logMessage}",
|
||||
result.exception
|
||||
)
|
||||
} else {
|
||||
Log_OC.e(TAG, "Synchronized $mRemotePath : ${result.logMessage}")
|
||||
}
|
||||
Log_OC.e(TAG, "Synchronized $mRemotePath : ${result.logMessage}")
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
return result
|
||||
companion object {
|
||||
private val TAG: String = ReadAlbumItemsRemoteOperation::class.java.simpleName
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val TAG: String = ReadAlbumItemsRemoteOperation::class.java.simpleName
|
||||
}
|
||||
}
|
||||
|
@ -18,53 +18,57 @@ import org.apache.commons.httpclient.HttpStatus
|
||||
import org.apache.jackrabbit.webdav.DavConstants
|
||||
import org.apache.jackrabbit.webdav.client.methods.PropFindMethod
|
||||
|
||||
class ReadAlbumsRemoteOperation @JvmOverloads constructor(
|
||||
private val mAlbumRemotePath: String? = null,
|
||||
private val sessionTimeOut: SessionTimeOut = defaultSessionTimeOut
|
||||
) :
|
||||
RemoteOperation<List<PhotoAlbumEntry>>() {
|
||||
/**
|
||||
* Performs the operation.
|
||||
*
|
||||
* @param client Client object to communicate with the remote ownCloud server.
|
||||
*/
|
||||
@Deprecated("Deprecated in Java")
|
||||
override fun run(client: OwnCloudClient): RemoteOperationResult<List<PhotoAlbumEntry>> {
|
||||
var propfind: PropFindMethod? = null
|
||||
var result: RemoteOperationResult<List<PhotoAlbumEntry>>
|
||||
var url = "${client.baseUri}/remote.php/dav/photos/${client.userId}/albums"
|
||||
if (!TextUtils.isEmpty(mAlbumRemotePath)) {
|
||||
url += WebdavUtils.encodePath(mAlbumRemotePath)
|
||||
}
|
||||
try {
|
||||
propfind = PropFindMethod(url, WebdavUtils.getAlbumPropSet(), DavConstants.DEPTH_1)
|
||||
val status = client.executeMethod(
|
||||
propfind,
|
||||
sessionTimeOut.readTimeOut,
|
||||
sessionTimeOut.connectionTimeOut
|
||||
)
|
||||
val isSuccess = status == HttpStatus.SC_MULTI_STATUS || status == HttpStatus.SC_OK
|
||||
if (isSuccess) {
|
||||
val albumsList = propfind.responseBodyAsMultiStatus.responses
|
||||
.filter { it.status[0].statusCode == HttpStatus.SC_OK }
|
||||
.map { res -> PhotoAlbumEntry(res) }
|
||||
result = RemoteOperationResult<List<PhotoAlbumEntry>>(true, propfind)
|
||||
result.resultData = albumsList
|
||||
} else {
|
||||
result = RemoteOperationResult<List<PhotoAlbumEntry>>(false, propfind)
|
||||
client.exhaustResponse(propfind.responseBodyAsStream)
|
||||
class ReadAlbumsRemoteOperation
|
||||
@JvmOverloads
|
||||
constructor(
|
||||
private val mAlbumRemotePath: String? = null,
|
||||
private val sessionTimeOut: SessionTimeOut = defaultSessionTimeOut
|
||||
) : RemoteOperation<List<PhotoAlbumEntry>>() {
|
||||
/**
|
||||
* Performs the operation.
|
||||
*
|
||||
* @param client Client object to communicate with the remote ownCloud server.
|
||||
*/
|
||||
@Deprecated("Deprecated in Java")
|
||||
@Suppress("TooGenericExceptionCaught")
|
||||
override fun run(client: OwnCloudClient): RemoteOperationResult<List<PhotoAlbumEntry>> {
|
||||
var propfind: PropFindMethod? = null
|
||||
var result: RemoteOperationResult<List<PhotoAlbumEntry>>
|
||||
var url = "${client.baseUri}/remote.php/dav/photos/${client.userId}/albums"
|
||||
if (!TextUtils.isEmpty(mAlbumRemotePath)) {
|
||||
url += WebdavUtils.encodePath(mAlbumRemotePath)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
result = RemoteOperationResult<List<PhotoAlbumEntry>>(e)
|
||||
Log_OC.e(TAG, "Read album failed: ${result.logMessage}", result.exception)
|
||||
} finally {
|
||||
propfind?.releaseConnection()
|
||||
try {
|
||||
propfind = PropFindMethod(url, WebdavUtils.getAlbumPropSet(), DavConstants.DEPTH_1)
|
||||
val status =
|
||||
client.executeMethod(
|
||||
propfind,
|
||||
sessionTimeOut.readTimeOut,
|
||||
sessionTimeOut.connectionTimeOut
|
||||
)
|
||||
val isSuccess = status == HttpStatus.SC_MULTI_STATUS || status == HttpStatus.SC_OK
|
||||
if (isSuccess) {
|
||||
val albumsList =
|
||||
propfind.responseBodyAsMultiStatus.responses
|
||||
.filter { it.status[0].statusCode == HttpStatus.SC_OK }
|
||||
.map { res -> PhotoAlbumEntry(res) }
|
||||
result = RemoteOperationResult<List<PhotoAlbumEntry>>(true, propfind)
|
||||
result.resultData = albumsList
|
||||
} else {
|
||||
result = RemoteOperationResult<List<PhotoAlbumEntry>>(false, propfind)
|
||||
client.exhaustResponse(propfind.responseBodyAsStream)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
result = RemoteOperationResult<List<PhotoAlbumEntry>>(e)
|
||||
Log_OC.e(TAG, "Read album failed: ${result.logMessage}", result.exception)
|
||||
} finally {
|
||||
propfind?.releaseConnection()
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
return result
|
||||
companion object {
|
||||
private val TAG: String = ReadAlbumsRemoteOperation::class.java.simpleName
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val TAG: String = ReadAlbumsRemoteOperation::class.java.simpleName
|
||||
}
|
||||
}
|
||||
|
@ -17,42 +17,47 @@ import com.owncloud.android.lib.resources.files.RemoveFileRemoteOperation
|
||||
import org.apache.commons.httpclient.HttpStatus
|
||||
import org.apache.jackrabbit.webdav.client.methods.DeleteMethod
|
||||
|
||||
class RemoveAlbumFileRemoteOperation @JvmOverloads constructor(
|
||||
private val mRemotePath: String,
|
||||
private val sessionTimeOut: SessionTimeOut = defaultSessionTimeOut
|
||||
) :
|
||||
RemoteOperation<Any>() {
|
||||
@Deprecated("Deprecated in Java")
|
||||
override fun run(client: OwnCloudClient): RemoteOperationResult<Any> {
|
||||
var result: RemoteOperationResult<Any>
|
||||
var delete: DeleteMethod? = null
|
||||
val webDavUrl = "${client.davUri}/photos/"
|
||||
val encodedPath = ("${client.userId}${Uri.encode(this.mRemotePath)}").replace("%2F", "/")
|
||||
val fullFilePath = "$webDavUrl$encodedPath"
|
||||
class RemoveAlbumFileRemoteOperation
|
||||
@JvmOverloads
|
||||
constructor(
|
||||
private val mRemotePath: String,
|
||||
private val sessionTimeOut: SessionTimeOut = defaultSessionTimeOut
|
||||
) : RemoteOperation<Any>() {
|
||||
@Deprecated("Deprecated in Java")
|
||||
@Suppress("TooGenericExceptionCaught")
|
||||
override fun run(client: OwnCloudClient): RemoteOperationResult<Any> {
|
||||
var result: RemoteOperationResult<Any>
|
||||
var delete: DeleteMethod? = null
|
||||
val webDavUrl = "${client.davUri}/photos/"
|
||||
val encodedPath = ("${client.userId}${Uri.encode(this.mRemotePath)}").replace("%2F", "/")
|
||||
val fullFilePath = "$webDavUrl$encodedPath"
|
||||
|
||||
try {
|
||||
delete = DeleteMethod(fullFilePath)
|
||||
val status = client.executeMethod(
|
||||
delete,
|
||||
sessionTimeOut.readTimeOut, sessionTimeOut.connectionTimeOut
|
||||
)
|
||||
delete.responseBodyAsString
|
||||
result = RemoteOperationResult<Any>(
|
||||
delete.succeeded() || status == HttpStatus.SC_NOT_FOUND,
|
||||
delete
|
||||
)
|
||||
Log_OC.i(TAG, "Remove ${this.mRemotePath} : ${result.logMessage}")
|
||||
} catch (e: Exception) {
|
||||
result = RemoteOperationResult<Any>(e)
|
||||
Log_OC.e(TAG, "Remove ${this.mRemotePath} : ${result.logMessage}", e)
|
||||
} finally {
|
||||
delete?.releaseConnection()
|
||||
try {
|
||||
delete = DeleteMethod(fullFilePath)
|
||||
val status =
|
||||
client.executeMethod(
|
||||
delete,
|
||||
sessionTimeOut.readTimeOut,
|
||||
sessionTimeOut.connectionTimeOut
|
||||
)
|
||||
delete.responseBodyAsString
|
||||
result =
|
||||
RemoteOperationResult<Any>(
|
||||
delete.succeeded() || status == HttpStatus.SC_NOT_FOUND,
|
||||
delete
|
||||
)
|
||||
Log_OC.i(TAG, "Remove ${this.mRemotePath} : ${result.logMessage}")
|
||||
} catch (e: Exception) {
|
||||
result = RemoteOperationResult<Any>(e)
|
||||
Log_OC.e(TAG, "Remove ${this.mRemotePath} : ${result.logMessage}", e)
|
||||
} finally {
|
||||
delete?.releaseConnection()
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
return result
|
||||
companion object {
|
||||
private val TAG: String = RemoveFileRemoteOperation::class.java.simpleName
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val TAG: String = RemoveFileRemoteOperation::class.java.simpleName
|
||||
}
|
||||
}
|
||||
|
@ -16,51 +16,56 @@ import com.owncloud.android.lib.common.utils.Log_OC
|
||||
import org.apache.commons.httpclient.HttpStatus
|
||||
import org.apache.jackrabbit.webdav.client.methods.DeleteMethod
|
||||
|
||||
class RemoveAlbumRemoteOperation @JvmOverloads constructor(
|
||||
private val albumName: String,
|
||||
private val sessionTimeOut: SessionTimeOut = defaultSessionTimeOut
|
||||
) :
|
||||
RemoteOperation<Any>() {
|
||||
/**
|
||||
* Performs the operation.
|
||||
*
|
||||
* @param client Client object to communicate with the remote ownCloud server.
|
||||
*/
|
||||
@Deprecated("Deprecated in Java")
|
||||
override fun run(client: OwnCloudClient): RemoteOperationResult<Any> {
|
||||
var result: RemoteOperationResult<Any>
|
||||
var delete: DeleteMethod? = null
|
||||
class RemoveAlbumRemoteOperation
|
||||
@JvmOverloads
|
||||
constructor(
|
||||
private val albumName: String,
|
||||
private val sessionTimeOut: SessionTimeOut = defaultSessionTimeOut
|
||||
) : RemoteOperation<Any>() {
|
||||
/**
|
||||
* Performs the operation.
|
||||
*
|
||||
* @param client Client object to communicate with the remote ownCloud server.
|
||||
*/
|
||||
@Deprecated("Deprecated in Java")
|
||||
@Suppress("TooGenericExceptionCaught")
|
||||
override fun run(client: OwnCloudClient): RemoteOperationResult<Any> {
|
||||
var result: RemoteOperationResult<Any>
|
||||
var delete: DeleteMethod? = null
|
||||
|
||||
try {
|
||||
delete = DeleteMethod(
|
||||
"${client.baseUri}/remote.php/dav/photos/${client.userId}/albums${
|
||||
WebdavUtils.encodePath(
|
||||
albumName
|
||||
try {
|
||||
delete =
|
||||
DeleteMethod(
|
||||
"${client.baseUri}/remote.php/dav/photos/${client.userId}/albums${
|
||||
WebdavUtils.encodePath(
|
||||
albumName
|
||||
)
|
||||
}"
|
||||
)
|
||||
}"
|
||||
)
|
||||
val status = client.executeMethod(
|
||||
delete,
|
||||
sessionTimeOut.readTimeOut,
|
||||
sessionTimeOut.connectionTimeOut
|
||||
)
|
||||
delete.responseBodyAsString
|
||||
result = RemoteOperationResult<Any>(
|
||||
delete.succeeded() || status == HttpStatus.SC_NOT_FOUND,
|
||||
delete
|
||||
)
|
||||
Log_OC.i(TAG, "Remove ${this.albumName} : ${result.logMessage}")
|
||||
} catch (e: Exception) {
|
||||
result = RemoteOperationResult<Any>(e)
|
||||
Log_OC.e(TAG, "Remove ${this.albumName} : ${result.logMessage}", e)
|
||||
} finally {
|
||||
delete?.releaseConnection()
|
||||
val status =
|
||||
client.executeMethod(
|
||||
delete,
|
||||
sessionTimeOut.readTimeOut,
|
||||
sessionTimeOut.connectionTimeOut
|
||||
)
|
||||
delete.responseBodyAsString
|
||||
result =
|
||||
RemoteOperationResult<Any>(
|
||||
delete.succeeded() || status == HttpStatus.SC_NOT_FOUND,
|
||||
delete
|
||||
)
|
||||
Log_OC.i(TAG, "Remove ${this.albumName} : ${result.logMessage}")
|
||||
} catch (e: Exception) {
|
||||
result = RemoteOperationResult<Any>(e)
|
||||
Log_OC.e(TAG, "Remove ${this.albumName} : ${result.logMessage}", e)
|
||||
} finally {
|
||||
delete?.releaseConnection()
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
return result
|
||||
companion object {
|
||||
private val TAG: String = RemoveAlbumRemoteOperation::class.java.simpleName
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val TAG: String = RemoveAlbumRemoteOperation::class.java.simpleName
|
||||
}
|
||||
}
|
||||
|
@ -15,58 +15,63 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult
|
||||
import com.owncloud.android.lib.common.utils.Log_OC
|
||||
import org.apache.jackrabbit.webdav.client.methods.MoveMethod
|
||||
|
||||
class RenameAlbumRemoteOperation @JvmOverloads constructor(
|
||||
private val mOldRemotePath: String,
|
||||
val newAlbumName: String,
|
||||
private val sessionTimeOut: SessionTimeOut = defaultSessionTimeOut
|
||||
) :
|
||||
RemoteOperation<Any>() {
|
||||
/**
|
||||
* Performs the operation.
|
||||
*
|
||||
* @param client Client object to communicate with the remote ownCloud server.
|
||||
*/
|
||||
@Deprecated("Deprecated in Java")
|
||||
override fun run(client: OwnCloudClient): RemoteOperationResult<Any>? {
|
||||
var result: RemoteOperationResult<Any>? = null
|
||||
var move: MoveMethod? = null
|
||||
val url = "${client.baseUri}/remote.php/dav/photos/${client.userId}/albums"
|
||||
try {
|
||||
if (this.newAlbumName != this.mOldRemotePath) {
|
||||
move = MoveMethod(
|
||||
"$url${WebdavUtils.encodePath(mOldRemotePath)}", "$url${
|
||||
WebdavUtils.encodePath(
|
||||
newAlbumName
|
||||
class RenameAlbumRemoteOperation
|
||||
@JvmOverloads
|
||||
constructor(
|
||||
private val mOldRemotePath: String,
|
||||
val newAlbumName: String,
|
||||
private val sessionTimeOut: SessionTimeOut = defaultSessionTimeOut
|
||||
) : RemoteOperation<Any>() {
|
||||
/**
|
||||
* Performs the operation.
|
||||
*
|
||||
* @param client Client object to communicate with the remote ownCloud server.
|
||||
*/
|
||||
@Deprecated("Deprecated in Java")
|
||||
@Suppress("TooGenericExceptionCaught")
|
||||
override fun run(client: OwnCloudClient): RemoteOperationResult<Any>? {
|
||||
var result: RemoteOperationResult<Any>? = null
|
||||
var move: MoveMethod? = null
|
||||
val url = "${client.baseUri}/remote.php/dav/photos/${client.userId}/albums"
|
||||
try {
|
||||
if (this.newAlbumName != this.mOldRemotePath) {
|
||||
move =
|
||||
MoveMethod(
|
||||
"$url${WebdavUtils.encodePath(mOldRemotePath)}",
|
||||
"$url${
|
||||
WebdavUtils.encodePath(
|
||||
newAlbumName
|
||||
)
|
||||
}",
|
||||
true
|
||||
)
|
||||
}", true
|
||||
)
|
||||
client.executeMethod(
|
||||
move,
|
||||
sessionTimeOut.readTimeOut,
|
||||
sessionTimeOut.connectionTimeOut
|
||||
)
|
||||
result = RemoteOperationResult<Any>(move.succeeded(), move)
|
||||
Log_OC.i(
|
||||
client.executeMethod(
|
||||
move,
|
||||
sessionTimeOut.readTimeOut,
|
||||
sessionTimeOut.connectionTimeOut
|
||||
)
|
||||
result = RemoteOperationResult<Any>(move.succeeded(), move)
|
||||
Log_OC.i(
|
||||
TAG,
|
||||
"Rename ${this.mOldRemotePath} to ${this.newAlbumName} : ${result.logMessage}"
|
||||
)
|
||||
client.exhaustResponse(move.responseBodyAsStream)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
result = RemoteOperationResult<Any>(e)
|
||||
Log_OC.e(
|
||||
TAG,
|
||||
"Rename ${this.mOldRemotePath} to ${this.newAlbumName} : ${result.logMessage}"
|
||||
"Rename ${this.mOldRemotePath} to ${this.newAlbumName} : ${result.logMessage}",
|
||||
e
|
||||
)
|
||||
client.exhaustResponse(move.responseBodyAsStream)
|
||||
} finally {
|
||||
move?.releaseConnection()
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
result = RemoteOperationResult<Any>(e)
|
||||
Log_OC.e(
|
||||
TAG,
|
||||
"Rename ${this.mOldRemotePath} to ${this.newAlbumName} : ${result.logMessage}",
|
||||
e
|
||||
)
|
||||
} finally {
|
||||
move?.releaseConnection()
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
return result
|
||||
companion object {
|
||||
private val TAG: String = RenameAlbumRemoteOperation::class.java.simpleName
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val TAG: String = RenameAlbumRemoteOperation::class.java.simpleName
|
||||
}
|
||||
}
|
||||
|
@ -21,53 +21,56 @@ import org.apache.jackrabbit.webdav.property.DefaultDavProperty
|
||||
import org.apache.jackrabbit.webdav.xml.Namespace
|
||||
import java.io.IOException
|
||||
|
||||
class ToggleAlbumFavoriteRemoteOperation @JvmOverloads constructor(
|
||||
private val makeItFavorited: Boolean,
|
||||
private val filePath: String,
|
||||
private val sessionTimeOut: SessionTimeOut = defaultSessionTimeOut
|
||||
) :
|
||||
RemoteOperation<Any>() {
|
||||
@Deprecated("Deprecated in Java")
|
||||
override fun run(client: OwnCloudClient): RemoteOperationResult<Any> {
|
||||
var result: RemoteOperationResult<Any>
|
||||
var propPatchMethod: PropPatchMethod? = null
|
||||
val newProps = DavPropertySet()
|
||||
val removeProperties = DavPropertyNameSet()
|
||||
if (this.makeItFavorited) {
|
||||
val favoriteProperty = DefaultDavProperty<Any>(
|
||||
"oc:favorite",
|
||||
"1",
|
||||
Namespace.getNamespace(WebdavEntry.NAMESPACE_OC)
|
||||
)
|
||||
newProps.add(favoriteProperty)
|
||||
} else {
|
||||
removeProperties.add("oc:favorite", Namespace.getNamespace(WebdavEntry.NAMESPACE_OC))
|
||||
}
|
||||
|
||||
val webDavUrl = "${client.davUri}/photos/"
|
||||
val encodedPath = ("${client.userId}${Uri.encode(this.filePath)}").replace("%2F", "/")
|
||||
val fullFilePath = "$webDavUrl$encodedPath"
|
||||
|
||||
try {
|
||||
propPatchMethod = PropPatchMethod(fullFilePath, newProps, removeProperties)
|
||||
val status = client.executeMethod(
|
||||
propPatchMethod,
|
||||
sessionTimeOut.readTimeOut,
|
||||
sessionTimeOut.connectionTimeOut
|
||||
)
|
||||
val isSuccess = (status == HttpStatus.SC_MULTI_STATUS || status == HttpStatus.SC_OK)
|
||||
if (isSuccess) {
|
||||
result = RemoteOperationResult<Any>(true, status, propPatchMethod.responseHeaders)
|
||||
class ToggleAlbumFavoriteRemoteOperation
|
||||
@JvmOverloads
|
||||
constructor(
|
||||
private val makeItFavorited: Boolean,
|
||||
private val filePath: String,
|
||||
private val sessionTimeOut: SessionTimeOut = defaultSessionTimeOut
|
||||
) : RemoteOperation<Any>() {
|
||||
@Deprecated("Deprecated in Java")
|
||||
override fun run(client: OwnCloudClient): RemoteOperationResult<Any> {
|
||||
var result: RemoteOperationResult<Any>
|
||||
var propPatchMethod: PropPatchMethod? = null
|
||||
val newProps = DavPropertySet()
|
||||
val removeProperties = DavPropertyNameSet()
|
||||
if (this.makeItFavorited) {
|
||||
val favoriteProperty =
|
||||
DefaultDavProperty<Any>(
|
||||
"oc:favorite",
|
||||
"1",
|
||||
Namespace.getNamespace(WebdavEntry.NAMESPACE_OC)
|
||||
)
|
||||
newProps.add(favoriteProperty)
|
||||
} else {
|
||||
client.exhaustResponse(propPatchMethod.responseBodyAsStream)
|
||||
result = RemoteOperationResult<Any>(false, status, propPatchMethod.responseHeaders)
|
||||
removeProperties.add("oc:favorite", Namespace.getNamespace(WebdavEntry.NAMESPACE_OC))
|
||||
}
|
||||
} catch (e: IOException) {
|
||||
result = RemoteOperationResult<Any>(e)
|
||||
} finally {
|
||||
propPatchMethod?.releaseConnection()
|
||||
}
|
||||
|
||||
return result
|
||||
val webDavUrl = "${client.davUri}/photos/"
|
||||
val encodedPath = ("${client.userId}${Uri.encode(this.filePath)}").replace("%2F", "/")
|
||||
val fullFilePath = "$webDavUrl$encodedPath"
|
||||
|
||||
try {
|
||||
propPatchMethod = PropPatchMethod(fullFilePath, newProps, removeProperties)
|
||||
val status =
|
||||
client.executeMethod(
|
||||
propPatchMethod,
|
||||
sessionTimeOut.readTimeOut,
|
||||
sessionTimeOut.connectionTimeOut
|
||||
)
|
||||
val isSuccess = (status == HttpStatus.SC_MULTI_STATUS || status == HttpStatus.SC_OK)
|
||||
if (isSuccess) {
|
||||
result = RemoteOperationResult<Any>(true, status, propPatchMethod.responseHeaders)
|
||||
} else {
|
||||
client.exhaustResponse(propPatchMethod.responseBodyAsStream)
|
||||
result = RemoteOperationResult<Any>(false, status, propPatchMethod.responseHeaders)
|
||||
}
|
||||
} catch (e: IOException) {
|
||||
result = RemoteOperationResult<Any>(e)
|
||||
} finally {
|
||||
propPatchMethod?.releaseConnection()
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
}
|
@ -12,7 +12,6 @@ import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class PhotoAlbumEntryTest {
|
||||
|
||||
@Test
|
||||
fun testAlbumName_withTrailingSlash() {
|
||||
val entry = createTestEntry("/remote.php/dav/photos/user_id/albums/vacation2024/")
|
||||
@ -54,4 +53,4 @@ class PhotoAlbumEntryTest {
|
||||
val response = MultiStatusResponse(href, 200)
|
||||
return PhotoAlbumEntry(response)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user