mirror of
https://github.com/nextcloud/android-library.git
synced 2025-07-21 23:47:23 +00:00
Operations migrated to kotlin.
Signed-off-by: Surinder Kumar <surinder.kumar@t-systems.com>
This commit is contained in:

committed by
Surinder Kumar

parent
333533f582
commit
aab6d51069
@ -4,156 +4,149 @@
|
||||
* SPDX-FileCopyrightText: 2025 TSI-mc <surinder.kumar@t-systems.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
package com.owncloud.android.lib.resources.albums
|
||||
|
||||
package com.owncloud.android.lib.resources.albums;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.nextcloud.common.SessionTimeOut;
|
||||
import com.nextcloud.common.SessionTimeOutKt;
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
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 org.apache.commons.httpclient.HttpStatus;
|
||||
import org.apache.jackrabbit.webdav.DavException;
|
||||
import org.apache.jackrabbit.webdav.MultiStatusResponse;
|
||||
import org.apache.jackrabbit.webdav.Status;
|
||||
import org.apache.jackrabbit.webdav.client.methods.CopyMethod;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import android.util.Log
|
||||
import com.nextcloud.common.SessionTimeOut
|
||||
import com.nextcloud.common.defaultSessionTimeOut
|
||||
import com.owncloud.android.lib.common.OwnCloudClient
|
||||
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.owncloud.android.lib.resources.albums.CopyFileToAlbumRemoteOperation
|
||||
import org.apache.commons.httpclient.HttpStatus
|
||||
import org.apache.jackrabbit.webdav.DavException
|
||||
import org.apache.jackrabbit.webdav.Status
|
||||
import org.apache.jackrabbit.webdav.client.methods.CopyMethod
|
||||
import java.io.IOException
|
||||
|
||||
/**
|
||||
* Remote operation moving a remote file or folder in the ownCloud server to a different folder
|
||||
* in the same account.
|
||||
* <p>
|
||||
*
|
||||
*
|
||||
* Allows renaming the moving file/folder at the same time.
|
||||
*/
|
||||
public class CopyFileToAlbumRemoteOperation extends RemoteOperation {
|
||||
private static final String TAG = CopyFileToAlbumRemoteOperation.class.getSimpleName();
|
||||
|
||||
private final String mSrcRemotePath;
|
||||
private final String mTargetRemotePath;
|
||||
|
||||
private final SessionTimeOut sessionTimeOut;
|
||||
|
||||
public CopyFileToAlbumRemoteOperation(String srcRemotePath, String targetRemotePath) {
|
||||
this(srcRemotePath, targetRemotePath, SessionTimeOutKt.getDefaultSessionTimeOut());
|
||||
}
|
||||
|
||||
public CopyFileToAlbumRemoteOperation(String srcRemotePath, String targetRemotePath, SessionTimeOut sessionTimeOut) {
|
||||
mSrcRemotePath = srcRemotePath;
|
||||
mTargetRemotePath = targetRemotePath;
|
||||
this.sessionTimeOut = sessionTimeOut;
|
||||
}
|
||||
|
||||
class CopyFileToAlbumRemoteOperation @JvmOverloads constructor(
|
||||
private val mSrcRemotePath: String,
|
||||
private val mTargetRemotePath: String,
|
||||
private val sessionTimeOut: SessionTimeOut = defaultSessionTimeOut
|
||||
) :
|
||||
RemoteOperation<Any>() {
|
||||
/**
|
||||
* Performs the operation.
|
||||
*
|
||||
* @param client Client object to communicate with the remote ownCloud server.
|
||||
*/
|
||||
@Override
|
||||
protected RemoteOperationResult run(OwnCloudClient client) {
|
||||
@Deprecated("Deprecated in Java")
|
||||
override fun run(client: OwnCloudClient): RemoteOperationResult<Any> {
|
||||
/** check parameters */
|
||||
|
||||
/// check parameters
|
||||
if (mTargetRemotePath.equals(mSrcRemotePath)) {
|
||||
if (mTargetRemotePath == mSrcRemotePath) {
|
||||
// nothing to do!
|
||||
return new RemoteOperationResult<>(ResultCode.OK);
|
||||
return RemoteOperationResult(ResultCode.OK)
|
||||
}
|
||||
|
||||
if (mTargetRemotePath.startsWith(mSrcRemotePath)) {
|
||||
return new RemoteOperationResult<>(ResultCode.INVALID_COPY_INTO_DESCENDANT);
|
||||
return RemoteOperationResult(ResultCode.INVALID_COPY_INTO_DESCENDANT)
|
||||
}
|
||||
|
||||
/// perform remote operation
|
||||
CopyMethod copyMethod = null;
|
||||
RemoteOperationResult result;
|
||||
/** perform remote operation */
|
||||
var copyMethod: CopyMethod? = null
|
||||
var result: RemoteOperationResult<Any>
|
||||
try {
|
||||
copyMethod = new CopyMethod(
|
||||
copyMethod = CopyMethod(
|
||||
client.getFilesDavUri(this.mSrcRemotePath),
|
||||
client.getBaseUri() + "/remote.php/dav/photos/" + client.getUserId() + "/albums" + WebdavUtils.encodePath(mTargetRemotePath),
|
||||
"${client.baseUri}/remote.php/dav/photos/${client.userId}/albums${
|
||||
WebdavUtils.encodePath(
|
||||
mTargetRemotePath
|
||||
)
|
||||
}",
|
||||
false
|
||||
);
|
||||
int status = client.executeMethod(copyMethod, sessionTimeOut.getReadTimeOut(), sessionTimeOut.getConnectionTimeOut());
|
||||
)
|
||||
val status = client.executeMethod(
|
||||
copyMethod,
|
||||
sessionTimeOut.readTimeOut,
|
||||
sessionTimeOut.connectionTimeOut
|
||||
)
|
||||
|
||||
/// process response
|
||||
/** process response */
|
||||
if (status == HttpStatus.SC_MULTI_STATUS) {
|
||||
result = processPartialError(copyMethod);
|
||||
|
||||
result = processPartialError(copyMethod)
|
||||
} else if (status == HttpStatus.SC_PRECONDITION_FAILED) {
|
||||
|
||||
result = new RemoteOperationResult<>(ResultCode.INVALID_OVERWRITE);
|
||||
client.exhaustResponse(copyMethod.getResponseBodyAsStream());
|
||||
|
||||
result = RemoteOperationResult<Any>(ResultCode.INVALID_OVERWRITE)
|
||||
client.exhaustResponse(copyMethod.responseBodyAsStream)
|
||||
} else {
|
||||
result = new RemoteOperationResult<>(isSuccess(status), copyMethod);
|
||||
client.exhaustResponse(copyMethod.getResponseBodyAsStream());
|
||||
result = RemoteOperationResult<Any>(isSuccess(status), copyMethod)
|
||||
client.exhaustResponse(copyMethod.responseBodyAsStream)
|
||||
}
|
||||
|
||||
Log.i(TAG, "Copy " + mSrcRemotePath + " to " + mTargetRemotePath + ": " + result.getLogMessage());
|
||||
|
||||
} catch (Exception e) {
|
||||
result = new RemoteOperationResult<>(e);
|
||||
Log.e(TAG, "Copy " + mSrcRemotePath + " to " + mTargetRemotePath + ": " + result.getLogMessage(), e);
|
||||
|
||||
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 {
|
||||
if (copyMethod != null) {
|
||||
copyMethod.releaseConnection();
|
||||
}
|
||||
copyMethod?.releaseConnection()
|
||||
}
|
||||
|
||||
return result;
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Analyzes a multistatus response from the OC server to generate an appropriate result.
|
||||
* <p>
|
||||
*
|
||||
*
|
||||
* In WebDAV, a COPY request on collections (folders) can be PARTIALLY successful: some
|
||||
* children are copied, some other aren't.
|
||||
* <p>
|
||||
*
|
||||
*
|
||||
* According to the WebDAV specification, a multistatus response SHOULD NOT include partial
|
||||
* successes (201, 204) nor for descendants of already failed children (424) in the response
|
||||
* entity. But SHOULD NOT != MUST NOT, so take carefully.
|
||||
*
|
||||
* @param copyMethod Copy operation just finished with a multistatus response
|
||||
* @return A result for the {@link CopyFileToAlbumRemoteOperation} caller
|
||||
* @return A result for the [CopyFileToAlbumRemoteOperation] caller
|
||||
* @throws java.io.IOException If the response body could not be parsed
|
||||
* @throws org.apache.jackrabbit.webdav.DavException If the status code is other than MultiStatus or if obtaining
|
||||
* the response XML document fails
|
||||
* the response XML document fails
|
||||
*/
|
||||
private RemoteOperationResult processPartialError(CopyMethod copyMethod)
|
||||
throws IOException, DavException {
|
||||
@Throws(IOException::class, DavException::class)
|
||||
private fun processPartialError(copyMethod: CopyMethod): RemoteOperationResult<Any> {
|
||||
// Adding a list of failed descendants to the result could be interesting; or maybe not.
|
||||
// For the moment, let's take the easy way.
|
||||
/** check that some error really occurred */
|
||||
|
||||
/// check that some error really occurred
|
||||
MultiStatusResponse[] responses = copyMethod.getResponseBodyAsMultiStatus().getResponses();
|
||||
Status[] status;
|
||||
boolean failFound = false;
|
||||
for (int i = 0; i < responses.length && !failFound; i++) {
|
||||
status = responses[i].getStatus();
|
||||
failFound = (
|
||||
status != null &&
|
||||
status.length > 0 &&
|
||||
status[0].getStatusCode() > 299
|
||||
);
|
||||
val responses = copyMethod.responseBodyAsMultiStatus.responses
|
||||
var status: Array<Status>?
|
||||
var failFound = false
|
||||
var i = 0
|
||||
while (i < responses.size && !failFound) {
|
||||
status = responses[i].status
|
||||
failFound = (!status.isNullOrEmpty() && status[0].statusCode > 299
|
||||
)
|
||||
i++
|
||||
}
|
||||
|
||||
RemoteOperationResult result;
|
||||
if (failFound) {
|
||||
result = new RemoteOperationResult<>(ResultCode.PARTIAL_COPY_DONE);
|
||||
val result: RemoteOperationResult<Any> = if (failFound) {
|
||||
RemoteOperationResult<Any>(ResultCode.PARTIAL_COPY_DONE)
|
||||
} else {
|
||||
result = new RemoteOperationResult<>(true, copyMethod);
|
||||
RemoteOperationResult<Any>(true, copyMethod)
|
||||
}
|
||||
|
||||
return result;
|
||||
return result
|
||||
}
|
||||
|
||||
protected boolean isSuccess(int status) {
|
||||
return status == HttpStatus.SC_CREATED || status == HttpStatus.SC_NO_CONTENT;
|
||||
private fun isSuccess(status: Int): Boolean {
|
||||
return status == HttpStatus.SC_CREATED || status == HttpStatus.SC_NO_CONTENT
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val TAG: String = CopyFileToAlbumRemoteOperation::class.java.simpleName
|
||||
}
|
||||
}
|
||||
|
@ -4,69 +4,67 @@
|
||||
* SPDX-FileCopyrightText: 2025 TSI-mc <surinder.kumar@t-systems.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
package com.owncloud.android.lib.resources.albums
|
||||
|
||||
package com.owncloud.android.lib.resources.albums;
|
||||
|
||||
import com.nextcloud.common.SessionTimeOut;
|
||||
import com.nextcloud.common.SessionTimeOutKt;
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
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 org.apache.jackrabbit.webdav.client.methods.MkColMethod;
|
||||
|
||||
public class CreateNewAlbumRemoteOperation extends RemoteOperation<Void> {
|
||||
private static final String TAG = CreateNewAlbumRemoteOperation.class.getSimpleName();
|
||||
private final String newAlbumName;
|
||||
private final SessionTimeOut sessionTimeOut;
|
||||
|
||||
public CreateNewAlbumRemoteOperation(String newAlbumName) {
|
||||
this(newAlbumName, SessionTimeOutKt.getDefaultSessionTimeOut());
|
||||
}
|
||||
|
||||
public CreateNewAlbumRemoteOperation(String newAlbumName, SessionTimeOut sessionTimeOut) {
|
||||
this.newAlbumName = newAlbumName;
|
||||
this.sessionTimeOut = sessionTimeOut;
|
||||
}
|
||||
|
||||
public String getNewAlbumName() {
|
||||
return newAlbumName;
|
||||
}
|
||||
import com.nextcloud.common.SessionTimeOut
|
||||
import com.nextcloud.common.defaultSessionTimeOut
|
||||
import com.owncloud.android.lib.common.OwnCloudClient
|
||||
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.
|
||||
*/
|
||||
@Override
|
||||
protected RemoteOperationResult<Void> run(OwnCloudClient client) {
|
||||
MkColMethod mkCol = null;
|
||||
RemoteOperationResult<Void> result;
|
||||
@Deprecated("Deprecated in Java")
|
||||
override fun run(client: OwnCloudClient): RemoteOperationResult<Void> {
|
||||
var mkCol: MkColMethod? = null
|
||||
var result: RemoteOperationResult<Void>
|
||||
try {
|
||||
mkCol = new MkColMethod(client.getBaseUri() + "/remote.php/dav/photos/" + client.getUserId() + "/albums" + WebdavUtils.encodePath(newAlbumName));
|
||||
client.executeMethod(mkCol, sessionTimeOut.getReadTimeOut(), sessionTimeOut.getConnectionTimeOut());
|
||||
if (405 == mkCol.getStatusCode()) {
|
||||
result = new RemoteOperationResult<>(RemoteOperationResult.ResultCode.FOLDER_ALREADY_EXISTS);
|
||||
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 = new RemoteOperationResult<>(mkCol.succeeded(), mkCol);
|
||||
result.setResultData(null);
|
||||
result = RemoteOperationResult(mkCol.succeeded(), mkCol)
|
||||
result.setResultData(null)
|
||||
}
|
||||
|
||||
Log_OC.d(TAG, "Create album " + newAlbumName + ": " + result.getLogMessage());
|
||||
client.exhaustResponse(mkCol.getResponseBodyAsStream());
|
||||
} catch (Exception e) {
|
||||
result = new RemoteOperationResult<>(e);
|
||||
Log_OC.e(TAG, "Create album " + newAlbumName + ": " + result.getLogMessage(), e);
|
||||
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 {
|
||||
if (mkCol != null) {
|
||||
mkCol.releaseConnection();
|
||||
}
|
||||
|
||||
mkCol?.releaseConnection()
|
||||
}
|
||||
|
||||
return result;
|
||||
return result
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val TAG: String = CreateNewAlbumRemoteOperation::class.java.simpleName
|
||||
}
|
||||
}
|
||||
|
@ -4,96 +4,99 @@
|
||||
* SPDX-FileCopyrightText: 2025 TSI-mc <surinder.kumar@t-systems.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
package com.owncloud.android.lib.resources.albums
|
||||
|
||||
package com.owncloud.android.lib.resources.albums;
|
||||
import com.nextcloud.common.SessionTimeOut
|
||||
import com.nextcloud.common.defaultSessionTimeOut
|
||||
import com.owncloud.android.lib.common.OwnCloudClient
|
||||
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.common.utils.WebDavFileUtils
|
||||
import com.owncloud.android.lib.resources.albums.ReadAlbumItemsRemoteOperation
|
||||
import com.owncloud.android.lib.resources.files.model.RemoteFile
|
||||
import org.apache.commons.httpclient.HttpStatus
|
||||
import org.apache.jackrabbit.webdav.DavConstants
|
||||
import org.apache.jackrabbit.webdav.client.methods.PropFindMethod
|
||||
|
||||
import com.nextcloud.common.SessionTimeOut;
|
||||
import com.nextcloud.common.SessionTimeOutKt;
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
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.common.utils.WebDavFileUtils;
|
||||
import com.owncloud.android.lib.resources.files.model.RemoteFile;
|
||||
|
||||
import org.apache.commons.httpclient.HttpStatus;
|
||||
import org.apache.jackrabbit.webdav.DavConstants;
|
||||
import org.apache.jackrabbit.webdav.MultiStatus;
|
||||
import org.apache.jackrabbit.webdav.client.methods.PropFindMethod;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ReadAlbumItemsRemoteOperation extends RemoteOperation<List<RemoteFile>> {
|
||||
|
||||
private static final String TAG = ReadAlbumItemsRemoteOperation.class.getSimpleName();
|
||||
private final String mRemotePath;
|
||||
private final SessionTimeOut sessionTimeOut;
|
||||
|
||||
public ReadAlbumItemsRemoteOperation(String mRemotePath) {
|
||||
this(mRemotePath, SessionTimeOutKt.getDefaultSessionTimeOut());
|
||||
}
|
||||
|
||||
public ReadAlbumItemsRemoteOperation(String mRemotePath, SessionTimeOut sessionTimeOut) {
|
||||
this.mRemotePath = mRemotePath;
|
||||
this.sessionTimeOut = sessionTimeOut;
|
||||
}
|
||||
|
||||
protected RemoteOperationResult<List<RemoteFile>> run(OwnCloudClient client) {
|
||||
RemoteOperationResult<List<RemoteFile>> result = null;
|
||||
PropFindMethod query = null;
|
||||
String url = client.getBaseUri() + "/remote.php/dav/photos/" + client.getUserId() + "/albums" + WebdavUtils.encodePath(mRemotePath);
|
||||
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 = new PropFindMethod(url,
|
||||
WebdavUtils.getAllPropSet(), // PropFind Properties
|
||||
DavConstants.DEPTH_1);
|
||||
int status = client.executeMethod(query, sessionTimeOut.getReadTimeOut(), sessionTimeOut.getConnectionTimeOut());
|
||||
query = PropFindMethod(
|
||||
url,
|
||||
WebdavUtils.getAllPropSet(), // PropFind Properties
|
||||
DavConstants.DEPTH_1
|
||||
)
|
||||
val status = client.executeMethod(
|
||||
query,
|
||||
sessionTimeOut.readTimeOut,
|
||||
sessionTimeOut.connectionTimeOut
|
||||
)
|
||||
|
||||
// check and process response
|
||||
boolean isSuccess = (status == HttpStatus.SC_MULTI_STATUS || status == HttpStatus.SC_OK);
|
||||
val isSuccess = (status == HttpStatus.SC_MULTI_STATUS || status == HttpStatus.SC_OK)
|
||||
|
||||
if (isSuccess) {
|
||||
// get data from remote folder
|
||||
MultiStatus dataInServer = query.getResponseBodyAsMultiStatus();
|
||||
List<RemoteFile> mFolderAndFiles = new WebDavFileUtils().readAlbumData(dataInServer, client);
|
||||
val dataInServer = query.responseBodyAsMultiStatus
|
||||
val mFolderAndFiles = WebDavFileUtils().readAlbumData(dataInServer, client)
|
||||
|
||||
// Result of the operation
|
||||
result = new RemoteOperationResult<>(true, query);
|
||||
result = RemoteOperationResult(true, query)
|
||||
// Add data to the result
|
||||
if (result.isSuccess()) {
|
||||
result.setResultData(mFolderAndFiles);
|
||||
if (result.isSuccess) {
|
||||
result.resultData = mFolderAndFiles
|
||||
}
|
||||
} else {
|
||||
// synchronization failed
|
||||
client.exhaustResponse(query.getResponseBodyAsStream());
|
||||
result = new RemoteOperationResult<>(false, query);
|
||||
client.exhaustResponse(query.responseBodyAsStream)
|
||||
result = RemoteOperationResult(false, query)
|
||||
}
|
||||
} catch (Exception e) {
|
||||
result = new RemoteOperationResult<>(e);
|
||||
} catch (e: Exception) {
|
||||
result = RemoteOperationResult(e)
|
||||
} finally {
|
||||
if (query != null) {
|
||||
query.releaseConnection(); // let the connection available for other methods
|
||||
}
|
||||
query?.releaseConnection()
|
||||
|
||||
if (result == null) {
|
||||
result = new RemoteOperationResult(new Exception("unknown error"));
|
||||
Log_OC.e(TAG, "Synchronized " + mRemotePath + ": failed");
|
||||
result = RemoteOperationResult<List<RemoteFile>>(Exception("unknown error"))
|
||||
Log_OC.e(
|
||||
TAG,
|
||||
"Synchronized $mRemotePath: failed"
|
||||
)
|
||||
} else {
|
||||
if (result.isSuccess()) {
|
||||
Log_OC.i(TAG, "Synchronized " + mRemotePath + ": " + result.getLogMessage());
|
||||
if (result.isSuccess) {
|
||||
Log_OC.i(TAG, "Synchronized $mRemotePath : ${result.logMessage}")
|
||||
} else {
|
||||
if (result.isException()) {
|
||||
Log_OC.e(TAG, "Synchronized " + mRemotePath + ": " + result.getLogMessage(),
|
||||
result.getException());
|
||||
if (result.isException) {
|
||||
Log_OC.e(
|
||||
TAG, "Synchronized $mRemotePath : ${result.logMessage}",
|
||||
result.exception
|
||||
)
|
||||
} else {
|
||||
Log_OC.e(TAG, "Synchronized " + mRemotePath + ": " + result.getLogMessage());
|
||||
Log_OC.e(TAG, "Synchronized $mRemotePath : ${result.logMessage}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
return result
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val TAG: String = ReadAlbumItemsRemoteOperation::class.java.simpleName
|
||||
}
|
||||
}
|
||||
|
@ -4,96 +4,74 @@
|
||||
* SPDX-FileCopyrightText: 2025 TSI-mc <surinder.kumar@t-systems.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
package com.owncloud.android.lib.resources.albums
|
||||
|
||||
package com.owncloud.android.lib.resources.albums;
|
||||
|
||||
import static org.apache.commons.httpclient.HttpStatus.SC_MULTI_STATUS;
|
||||
import static org.apache.commons.httpclient.HttpStatus.SC_OK;
|
||||
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.nextcloud.common.SessionTimeOut;
|
||||
import com.nextcloud.common.SessionTimeOutKt;
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
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 org.apache.jackrabbit.webdav.DavConstants;
|
||||
import org.apache.jackrabbit.webdav.MultiStatus;
|
||||
import org.apache.jackrabbit.webdav.MultiStatusResponse;
|
||||
import org.apache.jackrabbit.webdav.client.methods.PropFindMethod;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ReadAlbumsRemoteOperation extends RemoteOperation<List<PhotoAlbumEntry>> {
|
||||
|
||||
private static final String TAG = ReadAlbumsRemoteOperation.class.getSimpleName();
|
||||
private final String mAlbumRemotePath;
|
||||
private final SessionTimeOut sessionTimeOut;
|
||||
|
||||
|
||||
public ReadAlbumsRemoteOperation() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public ReadAlbumsRemoteOperation(@Nullable String mAlbumRemotePath) {
|
||||
this(mAlbumRemotePath, SessionTimeOutKt.getDefaultSessionTimeOut());
|
||||
}
|
||||
|
||||
public ReadAlbumsRemoteOperation(@Nullable String mAlbumRemotePath, SessionTimeOut sessionTimeOut) {
|
||||
this.mAlbumRemotePath = mAlbumRemotePath;
|
||||
this.sessionTimeOut = sessionTimeOut;
|
||||
}
|
||||
import android.text.TextUtils
|
||||
import com.nextcloud.common.SessionTimeOut
|
||||
import com.nextcloud.common.defaultSessionTimeOut
|
||||
import com.owncloud.android.lib.common.OwnCloudClient
|
||||
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 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.
|
||||
*/
|
||||
@Override
|
||||
protected RemoteOperationResult<List<PhotoAlbumEntry>> run(OwnCloudClient client) {
|
||||
PropFindMethod propfind = null;
|
||||
RemoteOperationResult<List<PhotoAlbumEntry>> result;
|
||||
String url = client.getBaseUri() + "/remote.php/dav/photos/" + client.getUserId() + "/albums";
|
||||
@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);
|
||||
url += WebdavUtils.encodePath(mAlbumRemotePath)
|
||||
}
|
||||
try {
|
||||
propfind = new PropFindMethod(url, WebdavUtils.getAlbumPropSet(), DavConstants.DEPTH_1);
|
||||
int status = client.executeMethod(propfind, sessionTimeOut.getReadTimeOut(), sessionTimeOut.getConnectionTimeOut());
|
||||
boolean isSuccess = status == SC_MULTI_STATUS || status == SC_OK;
|
||||
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) {
|
||||
MultiStatus multiStatus = propfind.getResponseBodyAsMultiStatus();
|
||||
List<PhotoAlbumEntry> albumsList = new ArrayList<>();
|
||||
for (MultiStatusResponse response : multiStatus.getResponses()) {
|
||||
int st = response.getStatus()[0].getStatusCode();
|
||||
if (st == SC_OK) {
|
||||
PhotoAlbumEntry entry = new PhotoAlbumEntry(response);
|
||||
albumsList.add(entry);
|
||||
val multiStatus = propfind.responseBodyAsMultiStatus
|
||||
val albumsList: MutableList<PhotoAlbumEntry> = ArrayList()
|
||||
for (response in multiStatus.responses) {
|
||||
val st = response.status[0].statusCode
|
||||
if (st == HttpStatus.SC_OK) {
|
||||
val entry = PhotoAlbumEntry(response)
|
||||
albumsList.add(entry)
|
||||
}
|
||||
}
|
||||
result = new RemoteOperationResult(true, propfind);
|
||||
result.setResultData(albumsList);
|
||||
result = RemoteOperationResult<List<PhotoAlbumEntry>>(true, propfind)
|
||||
result.setResultData(albumsList)
|
||||
} else {
|
||||
result = new RemoteOperationResult(false, propfind);
|
||||
client.exhaustResponse(propfind.getResponseBodyAsStream());
|
||||
result = RemoteOperationResult<List<PhotoAlbumEntry>>(false, propfind)
|
||||
client.exhaustResponse(propfind.responseBodyAsStream)
|
||||
}
|
||||
} catch (Exception var13) {
|
||||
Exception e = var13;
|
||||
result = new RemoteOperationResult(e);
|
||||
Log_OC.e(TAG, "Read album " + " failed: " + result.getLogMessage(), result.getException());
|
||||
} catch (var13: Exception) {
|
||||
val e = var13
|
||||
result = RemoteOperationResult<List<PhotoAlbumEntry>>(e)
|
||||
Log_OC.e(TAG, "Read album failed: ${result.logMessage}", result.exception)
|
||||
} finally {
|
||||
if (propfind != null) {
|
||||
propfind.releaseConnection();
|
||||
}
|
||||
|
||||
propfind?.releaseConnection()
|
||||
}
|
||||
|
||||
return result;
|
||||
return result
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val TAG: String = ReadAlbumsRemoteOperation::class.java.simpleName
|
||||
}
|
||||
}
|
||||
|
@ -4,59 +4,55 @@
|
||||
* SPDX-FileCopyrightText: 2025 TSI-mc <surinder.kumar@t-systems.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
package com.owncloud.android.lib.resources.albums
|
||||
|
||||
package com.owncloud.android.lib.resources.albums;
|
||||
import android.net.Uri
|
||||
import com.nextcloud.common.SessionTimeOut
|
||||
import com.nextcloud.common.defaultSessionTimeOut
|
||||
import com.owncloud.android.lib.common.OwnCloudClient
|
||||
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.files.RemoveFileRemoteOperation
|
||||
import org.apache.commons.httpclient.HttpStatus
|
||||
import org.apache.jackrabbit.webdav.client.methods.DeleteMethod
|
||||
|
||||
import android.net.Uri;
|
||||
|
||||
import com.nextcloud.common.SessionTimeOut;
|
||||
import com.nextcloud.common.SessionTimeOutKt;
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
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.files.RemoveFileRemoteOperation;
|
||||
|
||||
import org.apache.commons.httpclient.HttpStatus;
|
||||
import org.apache.jackrabbit.webdav.client.methods.DeleteMethod;
|
||||
|
||||
public class RemoveAlbumFileRemoteOperation extends RemoteOperation {
|
||||
private static final String TAG = RemoveFileRemoteOperation.class.getSimpleName();
|
||||
private final String mRemotePath;
|
||||
private final SessionTimeOut sessionTimeOut;
|
||||
|
||||
public RemoveAlbumFileRemoteOperation(String remotePath) {
|
||||
this(remotePath, SessionTimeOutKt.getDefaultSessionTimeOut());
|
||||
}
|
||||
|
||||
public RemoveAlbumFileRemoteOperation(String remotePath, SessionTimeOut sessionTimeOut) {
|
||||
this.mRemotePath = remotePath;
|
||||
this.sessionTimeOut = sessionTimeOut;
|
||||
}
|
||||
|
||||
protected RemoteOperationResult run(OwnCloudClient client) {
|
||||
RemoteOperationResult result;
|
||||
DeleteMethod delete = null;
|
||||
String webDavUrl = client.getDavUri().toString()+"/photos/";
|
||||
String encodedPath = (client.getUserId() + Uri.encode(this.mRemotePath)).replace("%2F", "/");
|
||||
String fullFilePath = webDavUrl + encodedPath;
|
||||
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"
|
||||
|
||||
try {
|
||||
delete = new DeleteMethod(fullFilePath);
|
||||
int status = client.executeMethod(delete, this.sessionTimeOut.getReadTimeOut(), this.sessionTimeOut.getConnectionTimeOut());
|
||||
delete.getResponseBodyAsString();
|
||||
result = new RemoteOperationResult(delete.succeeded() || status == HttpStatus.SC_NOT_FOUND, delete);
|
||||
Log_OC.i(TAG, "Remove " + this.mRemotePath + ": " + result.getLogMessage());
|
||||
} catch (Exception e) {
|
||||
result = new RemoteOperationResult(e);
|
||||
Log_OC.e(TAG, "Remove " + this.mRemotePath + ": " + result.getLogMessage(), e);
|
||||
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 {
|
||||
if (delete != null) {
|
||||
delete.releaseConnection();
|
||||
}
|
||||
|
||||
delete?.releaseConnection()
|
||||
}
|
||||
|
||||
return result;
|
||||
return result
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val TAG: String = RemoveFileRemoteOperation::class.java.simpleName
|
||||
}
|
||||
}
|
||||
|
@ -4,61 +4,64 @@
|
||||
* SPDX-FileCopyrightText: 2025 TSI-mc <surinder.kumar@t-systems.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
package com.owncloud.android.lib.resources.albums
|
||||
|
||||
package com.owncloud.android.lib.resources.albums;
|
||||
|
||||
import com.nextcloud.common.SessionTimeOut;
|
||||
import com.nextcloud.common.SessionTimeOutKt;
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
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 org.apache.commons.httpclient.HttpStatus;
|
||||
import org.apache.jackrabbit.webdav.client.methods.DeleteMethod;
|
||||
|
||||
public class RemoveAlbumRemoteOperation extends RemoteOperation {
|
||||
private static final String TAG = RemoveAlbumRemoteOperation.class.getSimpleName();
|
||||
private final String albumName;
|
||||
private final SessionTimeOut sessionTimeOut;
|
||||
|
||||
public RemoveAlbumRemoteOperation(String albumName) {
|
||||
this(albumName, SessionTimeOutKt.getDefaultSessionTimeOut());
|
||||
}
|
||||
|
||||
public RemoveAlbumRemoteOperation(String albumName, SessionTimeOut sessionTimeOut) {
|
||||
this.albumName = albumName;
|
||||
this.sessionTimeOut = sessionTimeOut;
|
||||
}
|
||||
import com.nextcloud.common.SessionTimeOut
|
||||
import com.nextcloud.common.defaultSessionTimeOut
|
||||
import com.owncloud.android.lib.common.OwnCloudClient
|
||||
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.RemoveAlbumRemoteOperation
|
||||
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.
|
||||
*/
|
||||
@Override
|
||||
protected RemoteOperationResult run(OwnCloudClient client) {
|
||||
RemoteOperationResult result;
|
||||
DeleteMethod delete = null;
|
||||
@Deprecated("Deprecated in Java")
|
||||
override fun run(client: OwnCloudClient): RemoteOperationResult<Any> {
|
||||
var result: RemoteOperationResult<Any>
|
||||
var delete: DeleteMethod? = null
|
||||
|
||||
try {
|
||||
delete = new DeleteMethod(client.getBaseUri() + "/remote.php/dav/photos/" + client.getUserId() + "/albums" + WebdavUtils.encodePath(albumName));
|
||||
int status = client.executeMethod(delete, sessionTimeOut.getReadTimeOut(), sessionTimeOut.getConnectionTimeOut());
|
||||
delete.getResponseBodyAsString();
|
||||
result = new RemoteOperationResult(delete.succeeded() || status == HttpStatus.SC_NOT_FOUND, delete);
|
||||
Log_OC.i(TAG, "Remove " + this.albumName + ": " + result.getLogMessage());
|
||||
} catch (Exception e) {
|
||||
result = new RemoteOperationResult(e);
|
||||
Log_OC.e(TAG, "Remove " + this.albumName + ": " + result.getLogMessage(), e);
|
||||
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 {
|
||||
if (delete != null) {
|
||||
delete.releaseConnection();
|
||||
}
|
||||
|
||||
delete?.releaseConnection()
|
||||
}
|
||||
|
||||
return result;
|
||||
return result
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val TAG: String = RemoveAlbumRemoteOperation::class.java.simpleName
|
||||
}
|
||||
}
|
||||
|
@ -4,69 +4,72 @@
|
||||
* SPDX-FileCopyrightText: 2025 TSI-mc <surinder.kumar@t-systems.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
package com.owncloud.android.lib.resources.albums
|
||||
|
||||
package com.owncloud.android.lib.resources.albums;
|
||||
|
||||
import com.nextcloud.common.SessionTimeOut;
|
||||
import com.nextcloud.common.SessionTimeOutKt;
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
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 org.apache.jackrabbit.webdav.client.methods.MoveMethod;
|
||||
|
||||
public class RenameAlbumRemoteOperation extends RemoteOperation {
|
||||
private static final String TAG = RenameAlbumRemoteOperation.class.getSimpleName();
|
||||
private final String mOldRemotePath;
|
||||
private final String mNewAlbumName;
|
||||
private final SessionTimeOut sessionTimeOut;
|
||||
|
||||
public RenameAlbumRemoteOperation(String mOldRemotePath, String mNewAlbumName) {
|
||||
this(mOldRemotePath, mNewAlbumName, SessionTimeOutKt.getDefaultSessionTimeOut());
|
||||
}
|
||||
|
||||
public RenameAlbumRemoteOperation(String mOldRemotePath, String mNewAlbumName, SessionTimeOut sessionTimeOut) {
|
||||
this.mOldRemotePath = mOldRemotePath;
|
||||
this.mNewAlbumName = mNewAlbumName;
|
||||
this.sessionTimeOut = sessionTimeOut;
|
||||
}
|
||||
|
||||
public String getNewAlbumName() {
|
||||
return mNewAlbumName;
|
||||
}
|
||||
import com.nextcloud.common.SessionTimeOut
|
||||
import com.nextcloud.common.defaultSessionTimeOut
|
||||
import com.owncloud.android.lib.common.OwnCloudClient
|
||||
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.RenameAlbumRemoteOperation
|
||||
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.
|
||||
*/
|
||||
@Override
|
||||
protected RemoteOperationResult run(OwnCloudClient client) {
|
||||
RemoteOperationResult result = null;
|
||||
MoveMethod move = null;
|
||||
String url = client.getBaseUri() + "/remote.php/dav/photos/" + client.getUserId() + "/albums";
|
||||
@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.mNewAlbumName.equals(this.mOldRemotePath)) {
|
||||
move = new MoveMethod(url + WebdavUtils.encodePath(mOldRemotePath), url + WebdavUtils.encodePath(mNewAlbumName), true);
|
||||
client.executeMethod(move, sessionTimeOut.getReadTimeOut(), sessionTimeOut.getConnectionTimeOut());
|
||||
result = new RemoteOperationResult(move.succeeded(), move);
|
||||
Log_OC.i(TAG, "Rename " + this.mOldRemotePath + " to " + this.mNewAlbumName + ": " + result.getLogMessage());
|
||||
client.exhaustResponse(move.getResponseBodyAsStream());
|
||||
return result;
|
||||
if (this.newAlbumName != this.mOldRemotePath) {
|
||||
move = MoveMethod(
|
||||
"$url${WebdavUtils.encodePath(mOldRemotePath)}", "$url${
|
||||
WebdavUtils.encodePath(
|
||||
newAlbumName
|
||||
)
|
||||
}", true
|
||||
)
|
||||
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)
|
||||
return result
|
||||
}
|
||||
} catch (Exception e) {
|
||||
result = new RemoteOperationResult(e);
|
||||
Log_OC.e(TAG, "Rename " + this.mOldRemotePath + " to " + this.mNewAlbumName + ": " + result.getLogMessage(), e);
|
||||
return result;
|
||||
} catch (e: Exception) {
|
||||
result = RemoteOperationResult<Any>(e)
|
||||
Log_OC.e(
|
||||
TAG,
|
||||
"Rename ${this.mOldRemotePath} to ${this.newAlbumName} : ${result.logMessage}",
|
||||
e
|
||||
)
|
||||
return result
|
||||
} finally {
|
||||
if (move != null) {
|
||||
move.releaseConnection();
|
||||
}
|
||||
move?.releaseConnection()
|
||||
}
|
||||
|
||||
return result;
|
||||
return result
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val TAG: String = RenameAlbumRemoteOperation::class.java.simpleName
|
||||
}
|
||||
}
|
||||
|
@ -4,77 +4,70 @@
|
||||
* SPDX-FileCopyrightText: 2025 TSI-mc <surinder.kumar@t-systems.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
package com.owncloud.android.lib.resources.albums
|
||||
|
||||
package com.owncloud.android.lib.resources.albums;
|
||||
import android.net.Uri
|
||||
import com.nextcloud.common.SessionTimeOut
|
||||
import com.nextcloud.common.defaultSessionTimeOut
|
||||
import com.owncloud.android.lib.common.OwnCloudClient
|
||||
import com.owncloud.android.lib.common.network.WebdavEntry
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperation
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult
|
||||
import org.apache.commons.httpclient.HttpStatus
|
||||
import org.apache.jackrabbit.webdav.client.methods.PropPatchMethod
|
||||
import org.apache.jackrabbit.webdav.property.DavPropertyNameSet
|
||||
import org.apache.jackrabbit.webdav.property.DavPropertySet
|
||||
import org.apache.jackrabbit.webdav.property.DefaultDavProperty
|
||||
import org.apache.jackrabbit.webdav.xml.Namespace
|
||||
import java.io.IOException
|
||||
|
||||
import android.net.Uri;
|
||||
|
||||
import com.nextcloud.common.SessionTimeOut;
|
||||
import com.nextcloud.common.SessionTimeOutKt;
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
import com.owncloud.android.lib.common.network.WebdavEntry;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
|
||||
import org.apache.commons.httpclient.HttpStatus;
|
||||
import org.apache.jackrabbit.webdav.client.methods.PropPatchMethod;
|
||||
import org.apache.jackrabbit.webdav.property.DavPropertyNameSet;
|
||||
import org.apache.jackrabbit.webdav.property.DavPropertySet;
|
||||
import org.apache.jackrabbit.webdav.property.DefaultDavProperty;
|
||||
import org.apache.jackrabbit.webdav.xml.Namespace;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class ToggleAlbumFavoriteRemoteOperation extends RemoteOperation {
|
||||
private boolean makeItFavorited;
|
||||
private String filePath;
|
||||
private final SessionTimeOut sessionTimeOut;
|
||||
|
||||
public ToggleAlbumFavoriteRemoteOperation(boolean makeItFavorited, String filePath) {
|
||||
this(makeItFavorited, filePath, SessionTimeOutKt.getDefaultSessionTimeOut());
|
||||
}
|
||||
|
||||
public ToggleAlbumFavoriteRemoteOperation(boolean makeItFavorited, String filePath, SessionTimeOut sessionTimeOut) {
|
||||
this.makeItFavorited = makeItFavorited;
|
||||
this.filePath = filePath;
|
||||
this.sessionTimeOut = sessionTimeOut;
|
||||
}
|
||||
|
||||
protected RemoteOperationResult run(OwnCloudClient client) {
|
||||
RemoteOperationResult result;
|
||||
PropPatchMethod propPatchMethod = null;
|
||||
DavPropertySet newProps = new DavPropertySet();
|
||||
DavPropertyNameSet removeProperties = new DavPropertyNameSet();
|
||||
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) {
|
||||
DefaultDavProperty<String> favoriteProperty = new DefaultDavProperty("oc:favorite", "1", Namespace.getNamespace(WebdavEntry.NAMESPACE_OC));
|
||||
newProps.add(favoriteProperty);
|
||||
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));
|
||||
removeProperties.add("oc:favorite", Namespace.getNamespace(WebdavEntry.NAMESPACE_OC))
|
||||
}
|
||||
|
||||
String webDavUrl = client.getDavUri().toString() + "/photos/";
|
||||
String encodedPath = (client.getUserId() + Uri.encode(this.filePath)).replace("%2F", "/");
|
||||
String fullFilePath = webDavUrl + encodedPath;
|
||||
val webDavUrl = "${client.davUri}/photos/"
|
||||
val encodedPath = ("${client.userId}${Uri.encode(this.filePath)}").replace("%2F", "/")
|
||||
val fullFilePath = "$webDavUrl$encodedPath"
|
||||
|
||||
try {
|
||||
propPatchMethod = new PropPatchMethod(fullFilePath, newProps, removeProperties);
|
||||
int status = client.executeMethod(propPatchMethod, sessionTimeOut.getReadTimeOut(), sessionTimeOut.getConnectionTimeOut());
|
||||
boolean isSuccess = (status == HttpStatus.SC_MULTI_STATUS || status == HttpStatus.SC_OK);
|
||||
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 = new RemoteOperationResult(true, status, propPatchMethod.getResponseHeaders());
|
||||
result = RemoteOperationResult<Any>(true, status, propPatchMethod.responseHeaders)
|
||||
} else {
|
||||
client.exhaustResponse(propPatchMethod.getResponseBodyAsStream());
|
||||
result = new RemoteOperationResult(false, status, propPatchMethod.getResponseHeaders());
|
||||
client.exhaustResponse(propPatchMethod.responseBodyAsStream)
|
||||
result = RemoteOperationResult<Any>(false, status, propPatchMethod.responseHeaders)
|
||||
}
|
||||
} catch (IOException e) {
|
||||
result = new RemoteOperationResult(e);
|
||||
} catch (e: IOException) {
|
||||
result = RemoteOperationResult<Any>(e)
|
||||
} finally {
|
||||
if (propPatchMethod != null) {
|
||||
propPatchMethod.releaseConnection();
|
||||
}
|
||||
|
||||
propPatchMethod?.releaseConnection()
|
||||
}
|
||||
|
||||
return result;
|
||||
return result
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user