From 14d646ea1d35d3694745d5b76d53105d080b1675 Mon Sep 17 00:00:00 2001 From: "David A. Velasco" Date: Thu, 12 Jan 2017 17:32:50 +0100 Subject: [PATCH] Keep http phrase in RemoteOperationResult as last chance for a detailed user message --- .../operations/RemoteOperationResult.java | 244 +++++++++++------- .../ChunkedUploadRemoteFileOperation.java | 59 ++--- .../files/CopyRemoteFileOperation.java | 15 +- .../files/CreateRemoteFolderOperation.java | 92 +++---- .../files/DownloadRemoteFileOperation.java | 103 ++++---- .../files/ExistenceCheckRemoteOperation.java | 7 +- .../files/MoveRemoteFileOperation.java | 243 +++++++++-------- .../files/ReadRemoteFileOperation.java | 96 +++---- .../files/ReadRemoteFolderOperation.java | 115 ++++----- .../files/RemoveRemoteFileOperation.java | 62 ++--- .../files/RenameRemoteFileOperation.java | 105 ++++---- .../files/UploadRemoteFileOperation.java | 34 +-- .../shares/CreateRemoteShareOperation.java | 231 ++++++++--------- .../shares/GetRemoteShareOperation.java | 90 +++---- .../shares/GetRemoteShareesOperation.java | 4 +- .../GetRemoteSharesForFileOperation.java | 148 +++++------ .../shares/GetRemoteSharesOperation.java | 85 +++--- .../shares/RemoveRemoteShareOperation.java | 94 +++---- .../shares/UpdateRemoteShareOperation.java | 2 +- .../GetRemoteCapabilitiesOperation.java | 6 +- .../status/GetRemoteStatusOperation.java | 144 +++++------ .../users/GetRemoteUserAvatarOperation.java | 4 +- .../users/GetRemoteUserInfoOperation.java | 4 +- .../users/GetRemoteUserQuotaOperation.java | 4 +- 24 files changed, 991 insertions(+), 1000 deletions(-) diff --git a/src/com/owncloud/android/lib/common/operations/RemoteOperationResult.java b/src/com/owncloud/android/lib/common/operations/RemoteOperationResult.java index 1ad543d2..6c9c6ffd 100644 --- a/src/com/owncloud/android/lib/common/operations/RemoteOperationResult.java +++ b/src/com/owncloud/android/lib/common/operations/RemoteOperationResult.java @@ -45,6 +45,7 @@ import com.owncloud.android.lib.common.utils.Log_OC; import org.apache.commons.httpclient.ConnectTimeoutException; import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.HttpException; +import org.apache.commons.httpclient.HttpMethod; import org.apache.commons.httpclient.HttpStatus; import org.apache.jackrabbit.webdav.DavException; import org.json.JSONException; @@ -63,9 +64,8 @@ import javax.net.ssl.SSLException; public class RemoteOperationResult implements Serializable { /** Generated - should be refreshed every time the class changes!! */ - ; - - private static final long serialVersionUID = -1909603208238358633L; + private static final long serialVersionUID = 4968939884332372230L; + private static final String TAG = RemoteOperationResult.class.getSimpleName(); public enum ResultCode { @@ -120,6 +120,7 @@ public class RemoteOperationResult implements Serializable { private boolean mSuccess = false; private int mHttpCode = -1; + private String mHttpPhrase = null; private Exception mException = null; private ResultCode mCode = ResultCode.UNKNOWN_ERROR; private String mRedirectedLocation; @@ -128,6 +129,13 @@ public class RemoteOperationResult implements Serializable { private ArrayList mData; + /** + * Public constructor from result code. + * + * To be used when the caller takes the responsibility of interpreting the result of a {@link RemoteOperation} + * + * @param code {@link ResultCode} decided by the caller. + */ public RemoteOperationResult(ResultCode code) { mCode = code; mSuccess = (code == ResultCode.OK || code == ResultCode.OK_SSL || @@ -136,96 +144,15 @@ public class RemoteOperationResult implements Serializable { mData = null; } - private RemoteOperationResult(boolean success, int httpCode) { - mSuccess = success; - mHttpCode = httpCode; - - if (success) { - mCode = ResultCode.OK; - - } else if (httpCode > 0) { - switch (httpCode) { - case HttpStatus.SC_UNAUTHORIZED: - mCode = ResultCode.UNAUTHORIZED; - break; - case HttpStatus.SC_NOT_FOUND: - mCode = ResultCode.FILE_NOT_FOUND; - break; - case HttpStatus.SC_INTERNAL_SERVER_ERROR: - mCode = ResultCode.INSTANCE_NOT_CONFIGURED; - break; - case HttpStatus.SC_CONFLICT: - mCode = ResultCode.CONFLICT; - break; - case HttpStatus.SC_INSUFFICIENT_STORAGE: - mCode = ResultCode.QUOTA_EXCEEDED; - break; - case HttpStatus.SC_FORBIDDEN: - mCode = ResultCode.FORBIDDEN; - break; - case HttpStatus.SC_SERVICE_UNAVAILABLE: - mCode = ResultCode.MAINTENANCE_MODE; - break; - default: - mCode = ResultCode.UNHANDLED_HTTP_CODE; - Log_OC.d(TAG, "RemoteOperationResult has processed UNHANDLED_HTTP_CODE: " + - httpCode); - } - } - } - - public RemoteOperationResult(boolean success, int httpCode, Header[] headers) { - this(success, httpCode); - if (headers != null) { - Header current; - for (int i = 0; i < headers.length; i++) { - current = headers[i]; - if ("location".equals(current.getName().toLowerCase())) { - mRedirectedLocation = current.getValue(); - continue; - } - if ("www-authenticate".equals(current.getName().toLowerCase())) { - mAuthenticate = current.getValue(); - continue; - } - } - } - if (isIdPRedirection()) { - mCode = ResultCode.UNAUTHORIZED; // overrides default ResultCode.UNKNOWN - } - } - - public RemoteOperationResult(boolean success, String bodyResponse, int httpCode) { - mSuccess = success; - mHttpCode = httpCode; - - if (success) { - mCode = ResultCode.OK; - - } else if (httpCode > 0) { - switch (httpCode) { - case HttpStatus.SC_BAD_REQUEST: - - InputStream is = new ByteArrayInputStream(bodyResponse.getBytes()); - InvalidCharacterExceptionParser xmlParser = new InvalidCharacterExceptionParser(); - try { - if (xmlParser.parseXMLResponse(is)) - mCode = ResultCode.INVALID_CHARACTER_DETECT_IN_SERVER; - - } catch (Exception e) { - mCode = ResultCode.UNHANDLED_HTTP_CODE; - Log_OC.e(TAG, "Exception reading exception from server", e); - } - break; - default: - mCode = ResultCode.UNHANDLED_HTTP_CODE; - Log_OC.d(TAG, "RemoteOperationResult has processed UNHANDLED_HTTP_CODE: " + - httpCode); - } - } - - } - + /** + * Public constructor from exception. + * + * To be used when an exception prevented the end of the {@link RemoteOperation}. + * + * Determines a {@link ResultCode} depending on the type of the exception. + * + * @param e Exception that interrupted the {@link RemoteOperation} + */ public RemoteOperationResult(Exception e) { mException = e; @@ -276,6 +203,133 @@ public class RemoteOperationResult implements Serializable { } + /** + * Public constructor from separate elements of an HTTP or DAV response. + * + * To be used when the result needs to be interpreted from the response of an HTTP/DAV method. + * + * Determines a {@link ResultCode} from the already executed method received as a parameter. Generally, + * will depend on the HTTP code and HTTP response headers received. In some cases will inspect also the + * response body. + * + * @param success The operation was considered successful or not. + * @param httpMethod HTTP/DAV method already executed which response will be examined to interpret the + * result. + */ + public RemoteOperationResult(boolean success, HttpMethod httpMethod) throws IOException { + this( + success, + httpMethod.getStatusCode(), + httpMethod.getStatusText(), + httpMethod.getResponseHeaders() + ); + + if (mHttpCode == HttpStatus.SC_BAD_REQUEST) { // 400 + String bodyResponse = httpMethod.getResponseBodyAsString(); + // do not get for other HTTP codes!; could not be available + + if (bodyResponse != null && bodyResponse.length() > 0) { + InputStream is = new ByteArrayInputStream(bodyResponse.getBytes()); + InvalidCharacterExceptionParser xmlParser = new InvalidCharacterExceptionParser(); + try { + if (xmlParser.parseXMLResponse(is)) { + mCode = ResultCode.INVALID_CHARACTER_DETECT_IN_SERVER; + } + + } catch (Exception e) { + Log_OC.w(TAG, "Error reading exception from server: " + e.getMessage()); + // mCode stays as set in this(success, httpCode, headers) + } + } + } + } + + /** + * Public constructor from separate elements of an HTTP or DAV response. + * + * To be used when the result needs to be interpreted from HTTP response elements that could come from + * different requests (WARNING: black magic, try to avoid). + * + * If all the fields come from the same HTTP/DAV response, {@link #RemoteOperationResult(boolean, HttpMethod)} + * should be used instead. + * + * Determines a {@link ResultCode} depending on the HTTP code and HTTP response headers received. + * + * @param success The operation was considered successful or not. + * @param httpCode HTTP status code returned by an HTTP/DAV method. + * @param httpPhrase HTTP status line phrase returned by an HTTP/DAV method + * @param httpHeaders HTTP response header returned by an HTTP/DAV method + */ + public RemoteOperationResult(boolean success, int httpCode, String httpPhrase, Header[] httpHeaders) { + this(success, httpCode, httpPhrase); + if (httpHeaders != null) { + Header current; + for (Header httpHeader : httpHeaders) { + current = httpHeader; + if ("location".equals(current.getName().toLowerCase())) { + mRedirectedLocation = current.getValue(); + continue; + } + if ("www-authenticate".equals(current.getName().toLowerCase())) { + mAuthenticate = current.getValue(); + break; + } + } + } + if (isIdPRedirection()) { + mCode = ResultCode.UNAUTHORIZED; // overrides default ResultCode.UNKNOWN + } + } + + /** + * Private constructor for results built interpreting a HTTP or DAV response. + * + * Determines a {@link ResultCode} depending of the type of the exception. + * + * @param success Operation was successful or not. + * @param httpCode HTTP status code returned by the HTTP/DAV method. + * @param httpPhrase HTTP status line phrase returned by the HTTP/DAV method + */ + private RemoteOperationResult(boolean success, int httpCode, String httpPhrase) { + mSuccess = success; + mHttpCode = httpCode; + mHttpPhrase = httpPhrase; + + if (success) { + mCode = ResultCode.OK; + + } else if (httpCode > 0) { + switch (httpCode) { + case HttpStatus.SC_UNAUTHORIZED: // 401 + mCode = ResultCode.UNAUTHORIZED; + break; + case HttpStatus.SC_FORBIDDEN: // 403 + mCode = ResultCode.FORBIDDEN; + break; + case HttpStatus.SC_NOT_FOUND: // 404 + mCode = ResultCode.FILE_NOT_FOUND; + break; + case HttpStatus.SC_CONFLICT: // 409 + mCode = ResultCode.CONFLICT; + break; + case HttpStatus.SC_INTERNAL_SERVER_ERROR: // 500 + mCode = ResultCode.INSTANCE_NOT_CONFIGURED; // assuming too much... + break; + case HttpStatus.SC_SERVICE_UNAVAILABLE: // 503 + mCode = ResultCode.MAINTENANCE_MODE; + break; + case HttpStatus.SC_INSUFFICIENT_STORAGE: // 507 + mCode = ResultCode.QUOTA_EXCEEDED; // surprise! + break; + default: + mCode = ResultCode.UNHANDLED_HTTP_CODE; // UNKNOWN ERROR + Log_OC.d(TAG, + "RemoteOperationResult has processed UNHANDLED_HTTP_CODE: " + + mHttpCode + " " + mHttpPhrase + ); + } + } + } public void setData(ArrayList files) { mData = files; @@ -297,6 +351,10 @@ public class RemoteOperationResult implements Serializable { return mHttpCode; } + public String getHttpPhrase() { + return mHttpPhrase; + } + public ResultCode getCode() { return mCode; } diff --git a/src/com/owncloud/android/lib/resources/files/ChunkedUploadRemoteFileOperation.java b/src/com/owncloud/android/lib/resources/files/ChunkedUploadRemoteFileOperation.java index 3135a788..42bcd660 100644 --- a/src/com/owncloud/android/lib/resources/files/ChunkedUploadRemoteFileOperation.java +++ b/src/com/owncloud/android/lib/resources/files/ChunkedUploadRemoteFileOperation.java @@ -39,6 +39,7 @@ import com.owncloud.android.lib.common.network.ChunkFromFileChannelRequestEntity import com.owncloud.android.lib.common.network.ProgressiveDataTransferer; import com.owncloud.android.lib.common.network.WebdavUtils; import com.owncloud.android.lib.common.operations.InvalidCharacterExceptionParser; +import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.utils.Log_OC; @@ -53,20 +54,21 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation private static final String TAG = ChunkedUploadRemoteFileOperation.class.getSimpleName(); public ChunkedUploadRemoteFileOperation(String storagePath, String remotePath, String mimeType, - String fileLastModifTimestamp){ + String fileLastModifTimestamp) { super(storagePath, remotePath, mimeType, fileLastModifTimestamp); } public ChunkedUploadRemoteFileOperation( - String storagePath, String remotePath, String mimeType, String requiredEtag, - String fileLastModifTimestamp - ){ - super(storagePath, remotePath, mimeType, requiredEtag, fileLastModifTimestamp); - } - + String storagePath, String remotePath, String mimeType, String requiredEtag, + String fileLastModifTimestamp + ) { + super(storagePath, remotePath, mimeType, requiredEtag, fileLastModifTimestamp); + } + @Override - protected int uploadFile(OwnCloudClient client) throws IOException { + protected RemoteOperationResult uploadFile(OwnCloudClient client) throws IOException { int status = -1; + RemoteOperationResult result = null; FileChannel channel = null; RandomAccessFile raf = null; @@ -76,24 +78,24 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation channel = raf.getChannel(); mEntity = new ChunkFromFileChannelRequestEntity(channel, mMimeType, CHUNK_SIZE, file); synchronized (mDataTransferListeners) { - ((ProgressiveDataTransferer)mEntity) - .addDatatransferProgressListeners(mDataTransferListeners); - } - + ((ProgressiveDataTransferer) mEntity) + .addDatatransferProgressListeners(mDataTransferListeners); + } + long offset = 0; String uriPrefix = client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath) + - "-chunking-" + Math.abs((new Random()).nextInt(9000)+1000) + "-" ; + "-chunking-" + Math.abs((new Random()).nextInt(9000) + 1000) + "-"; long totalLength = file.length(); - long chunkCount = (long) Math.ceil((double)totalLength / CHUNK_SIZE); + long chunkCount = (long) Math.ceil((double) totalLength / CHUNK_SIZE); String chunkSizeStr = String.valueOf(CHUNK_SIZE); String totalLengthStr = String.valueOf(file.length()); - for (int chunkIndex = 0; chunkIndex < chunkCount ; chunkIndex++, offset += CHUNK_SIZE) { + for (int chunkIndex = 0; chunkIndex < chunkCount; chunkIndex++, offset += CHUNK_SIZE) { if (chunkIndex == chunkCount - 1) { chunkSizeStr = String.valueOf(CHUNK_SIZE * chunkCount - totalLength); } if (mPutMethod != null) { mPutMethod.releaseConnection(); // let the connection available - // for other methods + // for other methods } mPutMethod = new PutMethod(uriPrefix + chunkCount + "-" + chunkIndex); if (mRequiredEtag != null && mRequiredEtag.length() > 0) { @@ -121,29 +123,20 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation status = client.executeMethod(mPutMethod); - if (status == 400) { - InvalidCharacterExceptionParser xmlParser = - new InvalidCharacterExceptionParser(); - InputStream is = new ByteArrayInputStream( - mPutMethod.getResponseBodyAsString().getBytes()); - try { - mForbiddenCharsInServer = xmlParser.parseXMLResponse(is); - - } catch (Exception e) { - mForbiddenCharsInServer = false; - Log_OC.e(TAG, "Exception reading exception from server", e); - } - } + result = new RemoteOperationResult( + isSuccess(status), + mPutMethod + ); client.exhaustResponse(mPutMethod.getResponseBodyAsStream()); Log_OC.d(TAG, "Upload of " + mLocalPath + " to " + mRemotePath + - ", chunk index " + chunkIndex + ", count " + chunkCount + - ", HTTP result status " + status); + ", chunk index " + chunkIndex + ", count " + chunkCount + + ", HTTP result status " + status); if (!isSuccess(status)) break; } - + } finally { if (channel != null) channel.close(); @@ -152,7 +145,7 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation if (mPutMethod != null) mPutMethod.releaseConnection(); // let the connection available for other methods } - return status; + return result; } } diff --git a/src/com/owncloud/android/lib/resources/files/CopyRemoteFileOperation.java b/src/com/owncloud/android/lib/resources/files/CopyRemoteFileOperation.java index c95034b5..9359a23f 100644 --- a/src/com/owncloud/android/lib/resources/files/CopyRemoteFileOperation.java +++ b/src/com/owncloud/android/lib/resources/files/CopyRemoteFileOperation.java @@ -129,15 +129,8 @@ public class CopyRemoteFileOperation extends RemoteOperation { /// for other errors that could be explicitly handled, check first: /// http://www.webdav.org/specs/rfc4918.html#rfc.section.9.9.4 - } else if (status == 400) { - result = new RemoteOperationResult(copyMethod.succeeded(), - copyMethod.getResponseBodyAsString(), status); } else { - result = new RemoteOperationResult( - isSuccess(status), // copy.succeeded()? trustful? - status, - copyMethod.getResponseHeaders() - ); + result = new RemoteOperationResult(isSuccess(status), copyMethod); client.exhaustResponse(copyMethod.getResponseBodyAsStream()); } @@ -196,11 +189,7 @@ public class CopyRemoteFileOperation extends RemoteOperation { if (failFound) { result = new RemoteOperationResult(ResultCode.PARTIAL_COPY_DONE); } else { - result = new RemoteOperationResult( - true, - HttpStatus.SC_MULTI_STATUS, - copyMethod.getResponseHeaders() - ); + result = new RemoteOperationResult(true, copyMethod); } return result; diff --git a/src/com/owncloud/android/lib/resources/files/CreateRemoteFolderOperation.java b/src/com/owncloud/android/lib/resources/files/CreateRemoteFolderOperation.java index 5ee762e9..5152710e 100644 --- a/src/com/owncloud/android/lib/resources/files/CreateRemoteFolderOperation.java +++ b/src/com/owncloud/android/lib/resources/files/CreateRemoteFolderOperation.java @@ -37,28 +37,27 @@ import com.owncloud.android.lib.resources.status.OwnCloudVersion; /** * Remote operation performing the creation of a new folder in the ownCloud server. - * - * @author David A. Velasco - * @author masensio * + * @author David A. Velasco + * @author masensio */ public class CreateRemoteFolderOperation extends RemoteOperation { - + private static final String TAG = CreateRemoteFolderOperation.class.getSimpleName(); private static final int READ_TIMEOUT = 30000; private static final int CONNECTION_TIMEOUT = 5000; - + protected String mRemotePath; protected boolean mCreateFullPath; - + /** * Constructor - * - * @param remotePath Full path to the new directory to create in the remote server. - * @param createFullPath 'True' means that all the ancestor folders should be created - * if don't exist yet. + * + * @param remotePath Full path to the new directory to create in the remote server. + * @param createFullPath 'True' means that all the ancestor folders should be created + * if don't exist yet. */ public CreateRemoteFolderOperation(String remotePath, boolean createFullPath) { mRemotePath = remotePath; @@ -67,69 +66,60 @@ public class CreateRemoteFolderOperation extends RemoteOperation { /** * Performs the operation - * - * @param client Client object to communicate with the remote ownCloud server. + * + * @param client Client object to communicate with the remote ownCloud server. */ @Override protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result = null; OwnCloudVersion version = client.getOwnCloudVersion(); boolean versionWithForbiddenChars = - (version != null && version.isVersionWithForbiddenCharacters()); + (version != null && version.isVersionWithForbiddenCharacters()); boolean noInvalidChars = FileUtils.isValidPath(mRemotePath, versionWithForbiddenChars); if (noInvalidChars) { - result = createFolder(client); - if (!result.isSuccess() && mCreateFullPath && - RemoteOperationResult.ResultCode.CONFLICT == result.getCode()) { - result = createParentFolder(FileUtils.getParentPath(mRemotePath), client); - if (result.isSuccess()) { - result = createFolder(client); // second (and last) try - } - } - + result = createFolder(client); + if (!result.isSuccess() && mCreateFullPath && + RemoteOperationResult.ResultCode.CONFLICT == result.getCode()) { + result = createParentFolder(FileUtils.getParentPath(mRemotePath), client); + if (result.isSuccess()) { + result = createFolder(client); // second (and last) try + } + } + } else { - result = new RemoteOperationResult(ResultCode.INVALID_CHARACTER_IN_NAME); + result = new RemoteOperationResult(ResultCode.INVALID_CHARACTER_IN_NAME); } - + return result; } - + private RemoteOperationResult createFolder(OwnCloudClient client) { RemoteOperationResult result = null; MkColMethod mkcol = null; - try { - mkcol = new MkColMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath)); - int status = client.executeMethod(mkcol, READ_TIMEOUT, CONNECTION_TIMEOUT); - if ( status == 400 ) { - result = new RemoteOperationResult(mkcol.succeeded(), - mkcol.getResponseBodyAsString(), status); - Log_OC.d(TAG, mkcol.getResponseBodyAsString()); - - } else { - result = new RemoteOperationResult(mkcol.succeeded(), status, - mkcol.getResponseHeaders()); - Log_OC.d(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage()); - } + try { + mkcol = new MkColMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath)); + client.executeMethod(mkcol, READ_TIMEOUT, CONNECTION_TIMEOUT); + result = new RemoteOperationResult(mkcol.succeeded(), mkcol); + Log_OC.d(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage()); client.exhaustResponse(mkcol.getResponseBodyAsStream()); - } catch (Exception e) { - result = new RemoteOperationResult(e); - Log_OC.e(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage(), e); + } catch (Exception e) { + result = new RemoteOperationResult(e); + Log_OC.e(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage(), e); - } finally { - if (mkcol != null) - mkcol.releaseConnection(); - } - return result; - } + } finally { + if (mkcol != null) + mkcol.releaseConnection(); + } + return result; + } - private RemoteOperationResult createParentFolder(String parentPath, OwnCloudClient client) { + private RemoteOperationResult createParentFolder(String parentPath, OwnCloudClient client) { RemoteOperation operation = new CreateRemoteFolderOperation(parentPath, - mCreateFullPath); + mCreateFullPath); return operation.execute(client); } - - + } diff --git a/src/com/owncloud/android/lib/resources/files/DownloadRemoteFileOperation.java b/src/com/owncloud/android/lib/resources/files/DownloadRemoteFileOperation.java index 530c10d8..45515943 100644 --- a/src/com/owncloud/android/lib/resources/files/DownloadRemoteFileOperation.java +++ b/src/com/owncloud/android/lib/resources/files/DownloadRemoteFileOperation.java @@ -49,62 +49,61 @@ import com.owncloud.android.lib.common.utils.Log_OC; /** * Remote operation performing the download of a remote file in the ownCloud server. - * + * * @author David A. Velasco * @author masensio */ public class DownloadRemoteFileOperation extends RemoteOperation { - - private static final String TAG = DownloadRemoteFileOperation.class.getSimpleName(); - - private Set mDataTransferListeners = new HashSet(); + + private static final String TAG = DownloadRemoteFileOperation.class.getSimpleName(); + + private Set mDataTransferListeners = new HashSet(); private final AtomicBoolean mCancellationRequested = new AtomicBoolean(false); private long mModificationTimestamp = 0; private String mEtag = ""; private GetMethod mGet; - + private String mRemotePath; private String mLocalFolderPath; - - public DownloadRemoteFileOperation(String remotePath, String localFolderPath) { - mRemotePath = remotePath; - mLocalFolderPath = localFolderPath; - } - @Override - protected RemoteOperationResult run(OwnCloudClient client) { - RemoteOperationResult result = null; - + public DownloadRemoteFileOperation(String remotePath, String localFolderPath) { + mRemotePath = remotePath; + mLocalFolderPath = localFolderPath; + } + + @Override + protected RemoteOperationResult run(OwnCloudClient client) { + RemoteOperationResult result = null; + /// download will be performed to a temporal file, then moved to the final location File tmpFile = new File(getTmpPath()); - + /// perform the download try { - tmpFile.getParentFile().mkdirs(); - int status = downloadFile(client, tmpFile); - result = new RemoteOperationResult(isSuccess(status), status, - (mGet != null ? mGet.getResponseHeaders() : null)); - Log_OC.i(TAG, "Download of " + mRemotePath + " to " + getTmpPath() + ": " + - result.getLogMessage()); + tmpFile.getParentFile().mkdirs(); + int status = downloadFile(client, tmpFile); + result = new RemoteOperationResult(isSuccess(status), mGet); + Log_OC.i(TAG, "Download of " + mRemotePath + " to " + getTmpPath() + ": " + + result.getLogMessage()); } catch (Exception e) { result = new RemoteOperationResult(e); Log_OC.e(TAG, "Download of " + mRemotePath + " to " + getTmpPath() + ": " + - result.getLogMessage(), e); + result.getLogMessage(), e); } - - return result; - } - + return result; + } + + protected int downloadFile(OwnCloudClient client, File targetFile) throws HttpException, - IOException, OperationCancelledException { + IOException, OperationCancelledException { int status = -1; boolean savedFile = false; mGet = new GetMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath)); Iterator it = null; - + FileOutputStream fos = null; try { status = client.executeMethod(mGet); @@ -113,16 +112,16 @@ public class DownloadRemoteFileOperation extends RemoteOperation { BufferedInputStream bis = new BufferedInputStream(mGet.getResponseBodyAsStream()); fos = new FileOutputStream(targetFile); long transferred = 0; - + Header contentLength = mGet.getResponseHeader("Content-Length"); long totalToTransfer = (contentLength != null && - contentLength.getValue().length() >0) ? - Long.parseLong(contentLength.getValue()) : 0; + contentLength.getValue().length() > 0) ? + Long.parseLong(contentLength.getValue()) : 0; byte[] bytes = new byte[4096]; int readResult = 0; while ((readResult = bis.read(bytes)) != -1) { - synchronized(mCancellationRequested) { + synchronized (mCancellationRequested) { if (mCancellationRequested.get()) { mGet.abort(); throw new OperationCancelledException(); @@ -134,20 +133,20 @@ public class DownloadRemoteFileOperation extends RemoteOperation { it = mDataTransferListeners.iterator(); while (it.hasNext()) { it.next().onTransferProgress(readResult, transferred, totalToTransfer, - targetFile.getName()); + targetFile.getName()); } } } if (transferred == totalToTransfer) { // Check if the file is completed - savedFile = true; - Header modificationTime = mGet.getResponseHeader("Last-Modified"); + savedFile = true; + Header modificationTime = mGet.getResponseHeader("Last-Modified"); if (modificationTime == null) { modificationTime = mGet.getResponseHeader("last-modified"); } - if (modificationTime != null) { - Date d = WebdavUtils.parseResponseDate((String) modificationTime.getValue()); - mModificationTimestamp = (d != null) ? d.getTime() : 0; - } else { + if (modificationTime != null) { + Date d = WebdavUtils.parseResponseDate((String) modificationTime.getValue()); + mModificationTimestamp = (d != null) ? d.getTime() : 0; + } else { Log_OC.e(TAG, "Could not read modification time from response downloading " + mRemotePath); } @@ -157,14 +156,14 @@ public class DownloadRemoteFileOperation extends RemoteOperation { } } else { - client.exhaustResponse(mGet.getResponseBodyAsStream()); + client.exhaustResponse(mGet.getResponseBodyAsStream()); // TODO some kind of error control! } - + } else { client.exhaustResponse(mGet.getResponseBodyAsStream()); } - + } finally { if (fos != null) fos.close(); if (!savedFile && targetFile.exists()) { @@ -174,34 +173,34 @@ public class DownloadRemoteFileOperation extends RemoteOperation { } return status; } - + private boolean isSuccess(int status) { return (status == HttpStatus.SC_OK); } - + private String getTmpPath() { return mLocalFolderPath + mRemotePath; } - - public void addDatatransferProgressListener (OnDatatransferProgressListener listener) { + + public void addDatatransferProgressListener(OnDatatransferProgressListener listener) { synchronized (mDataTransferListeners) { mDataTransferListeners.add(listener); } } - + public void removeDatatransferProgressListener(OnDatatransferProgressListener listener) { synchronized (mDataTransferListeners) { mDataTransferListeners.remove(listener); } } - + public void cancel() { mCancellationRequested.set(true); // atomic set; there is no need of synchronizing it } - public long getModificationTimestamp() { - return mModificationTimestamp; - } + public long getModificationTimestamp() { + return mModificationTimestamp; + } public String getEtag() { return mEtag; diff --git a/src/com/owncloud/android/lib/resources/files/ExistenceCheckRemoteOperation.java b/src/com/owncloud/android/lib/resources/files/ExistenceCheckRemoteOperation.java index 6cb2da33..38387b36 100644 --- a/src/com/owncloud/android/lib/resources/files/ExistenceCheckRemoteOperation.java +++ b/src/com/owncloud/android/lib/resources/files/ExistenceCheckRemoteOperation.java @@ -96,7 +96,12 @@ public class ExistenceCheckRemoteOperation extends RemoteOperation { client.exhaustResponse(head.getResponseBodyAsStream()); boolean success = (status == HttpStatus.SC_OK && !mSuccessIfAbsent) || (status == HttpStatus.SC_NOT_FOUND && mSuccessIfAbsent); - result = new RemoteOperationResult(success, status, head.getResponseHeaders()); + result = new RemoteOperationResult( + success, + status, + head.getStatusText(), + head.getResponseHeaders() + ); Log_OC.d(TAG, "Existence check for " + client.getWebdavUri() + WebdavUtils.encodePath(mPath) + " targeting for " + (mSuccessIfAbsent ? " absence " : " existence ") + diff --git a/src/com/owncloud/android/lib/resources/files/MoveRemoteFileOperation.java b/src/com/owncloud/android/lib/resources/files/MoveRemoteFileOperation.java index 5ab7adc3..2a344216 100644 --- a/src/com/owncloud/android/lib/resources/files/MoveRemoteFileOperation.java +++ b/src/com/owncloud/android/lib/resources/files/MoveRemoteFileOperation.java @@ -45,176 +45,163 @@ import com.owncloud.android.lib.resources.status.OwnCloudVersion; /** * Remote operation moving a remote file or folder in the ownCloud server to a different folder * in the same account. - * + *

* Allows renaming the moving file/folder at the same time. - * + * * @author David A. Velasco */ public class MoveRemoteFileOperation extends RemoteOperation { - private static final String TAG = MoveRemoteFileOperation.class.getSimpleName(); + private static final String TAG = MoveRemoteFileOperation.class.getSimpleName(); - private static final int MOVE_READ_TIMEOUT = 600000; - private static final int MOVE_CONNECTION_TIMEOUT = 5000; + private static final int MOVE_READ_TIMEOUT = 600000; + private static final int MOVE_CONNECTION_TIMEOUT = 5000; private String mSrcRemotePath; private String mTargetRemotePath; - private boolean mOverwrite; - - + private boolean mOverwrite; + + /** * Constructor. - * + *

* TODO Paths should finish in "/" in the case of folders. ? - * - * @param srcRemotePath Remote path of the file/folder to move. - * @param targetRemotePath Remove path desired for the file/folder after moving it. + * + * @param srcRemotePath Remote path of the file/folder to move. + * @param targetRemotePath Remove path desired for the file/folder after moving it. */ - public MoveRemoteFileOperation( - String srcRemotePath, String targetRemotePath, boolean overwrite - ) { - - mSrcRemotePath = srcRemotePath; - mTargetRemotePath = targetRemotePath; - mOverwrite = overwrite; - } + public MoveRemoteFileOperation( + String srcRemotePath, String targetRemotePath, boolean overwrite + ) { - - /** + mSrcRemotePath = srcRemotePath; + mTargetRemotePath = targetRemotePath; + mOverwrite = overwrite; + } + + + /** * Performs the rename operation. - * - * @param client Client object to communicate with the remote ownCloud server. + * + * @param client Client object to communicate with the remote ownCloud server. */ - @Override - protected RemoteOperationResult run(OwnCloudClient client) { + @Override + protected RemoteOperationResult run(OwnCloudClient client) { - OwnCloudVersion version = client.getOwnCloudVersion(); - boolean versionWithForbiddenChars = - (version != null && version.isVersionWithForbiddenCharacters()); + OwnCloudVersion version = client.getOwnCloudVersion(); + boolean versionWithForbiddenChars = + (version != null && version.isVersionWithForbiddenCharacters()); - /// check parameters + /// check parameters if (!FileUtils.isValidPath(mTargetRemotePath, versionWithForbiddenChars)) { - return new RemoteOperationResult(ResultCode.INVALID_CHARACTER_IN_NAME); + return new RemoteOperationResult(ResultCode.INVALID_CHARACTER_IN_NAME); } - + if (mTargetRemotePath.equals(mSrcRemotePath)) { - // nothing to do! + // nothing to do! return new RemoteOperationResult(ResultCode.OK); } if (mTargetRemotePath.startsWith(mSrcRemotePath)) { - return new RemoteOperationResult(ResultCode.INVALID_MOVE_INTO_DESCENDANT); + return new RemoteOperationResult(ResultCode.INVALID_MOVE_INTO_DESCENDANT); } - + /// perform remote operation - //LocalMoveMethod move = null; - MoveMethod move = null; - RemoteOperationResult result = null; + MoveMethod move = null; + RemoteOperationResult result = null; try { move = new MoveMethod( - client.getWebdavUri() + WebdavUtils.encodePath(mSrcRemotePath), - client.getWebdavUri() + WebdavUtils.encodePath(mTargetRemotePath), - mOverwrite - ); + client.getWebdavUri() + WebdavUtils.encodePath(mSrcRemotePath), + client.getWebdavUri() + WebdavUtils.encodePath(mTargetRemotePath), + mOverwrite + ); int status = client.executeMethod(move, MOVE_READ_TIMEOUT, MOVE_CONNECTION_TIMEOUT); - - /// process response - if (status == HttpStatus.SC_MULTI_STATUS) { - result = processPartialError(move); - - } else if (status == HttpStatus.SC_PRECONDITION_FAILED && !mOverwrite) { - - result = new RemoteOperationResult(ResultCode.INVALID_OVERWRITE); - client.exhaustResponse(move.getResponseBodyAsStream()); - - /// for other errors that could be explicitly handled, check first: - /// http://www.webdav.org/specs/rfc4918.html#rfc.section.9.9.4 - - } else if (status == 400) { - result = new RemoteOperationResult(move.succeeded(), - move.getResponseBodyAsString(), status); - } else { - result = new RemoteOperationResult( - isSuccess(status), // move.succeeded()? trustful? - status, - move.getResponseHeaders() - ); - client.exhaustResponse(move.getResponseBodyAsStream()); - } - - Log.i(TAG, "Move " + mSrcRemotePath + " to " + mTargetRemotePath + ": " + - result.getLogMessage()); - + /// process response + if (status == HttpStatus.SC_MULTI_STATUS) { + result = processPartialError(move); + + } else if (status == HttpStatus.SC_PRECONDITION_FAILED && !mOverwrite) { + + result = new RemoteOperationResult(ResultCode.INVALID_OVERWRITE); + client.exhaustResponse(move.getResponseBodyAsStream()); + + + /// for other errors that could be explicitly handled, check first: + /// http://www.webdav.org/specs/rfc4918.html#rfc.section.9.9.4 + + } else { + result = new RemoteOperationResult(isSuccess(status), move); + client.exhaustResponse(move.getResponseBodyAsStream()); + } + + Log.i(TAG, "Move " + mSrcRemotePath + " to " + mTargetRemotePath + ": " + + result.getLogMessage()); + } catch (Exception e) { result = new RemoteOperationResult(e); - Log.e(TAG, "Move " + mSrcRemotePath + " to " + mTargetRemotePath + ": " + - result.getLogMessage(), e); - + Log.e(TAG, "Move " + mSrcRemotePath + " to " + mTargetRemotePath + ": " + + result.getLogMessage(), e); + } finally { if (move != null) move.releaseConnection(); } - + return result; - } - - - /** - * Analyzes a multistatus response from the OC server to generate an appropriate result. - * - * In WebDAV, a MOVE request on collections (folders) can be PARTIALLY successful: some - * children are moved, some other aren't. - * - * 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 move Move operation just finished with a multistatus response - * @return A result for the {@link MoveRemoteFileOperation} caller - * - * @throws IOException If the response body could not be parsed - * @throws DavException If the status code is other than MultiStatus or if obtaining - * the response XML document fails - */ - private RemoteOperationResult processPartialError(MoveMethod move) - throws IOException, DavException { - // 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 - MultiStatusResponse[] responses = move.getResponseBodyAsMultiStatus().getResponses(); - Status[] status = null; - 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 - ); - } - - RemoteOperationResult result; - if (failFound) { - result = new RemoteOperationResult(ResultCode.PARTIAL_MOVE_DONE); - } else { - result = new RemoteOperationResult( - true, - HttpStatus.SC_MULTI_STATUS, - move.getResponseHeaders() - ); - } - - return result; - - } + } - protected boolean isSuccess(int status) { + /** + * Analyzes a multistatus response from the OC server to generate an appropriate result. + *

+ * In WebDAV, a MOVE request on collections (folders) can be PARTIALLY successful: some + * children are moved, some other aren't. + *

+ * 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 move Move operation just finished with a multistatus response + * @throws IOException If the response body could not be parsed + * @throws DavException If the status code is other than MultiStatus or if obtaining + * the response XML document fails + * @return A result for the {@link MoveRemoteFileOperation} caller + */ + private RemoteOperationResult processPartialError(MoveMethod move) + throws IOException, DavException { + // 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 + MultiStatusResponse[] responses = move.getResponseBodyAsMultiStatus().getResponses(); + Status[] status = null; + 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 + ); + } + + RemoteOperationResult result; + if (failFound) { + result = new RemoteOperationResult(ResultCode.PARTIAL_MOVE_DONE); + } else { + result = new RemoteOperationResult(true, move); + } + + return result; + + } + + + protected boolean isSuccess(int status) { return status == HttpStatus.SC_CREATED || status == HttpStatus.SC_NO_CONTENT; } - + } diff --git a/src/com/owncloud/android/lib/resources/files/ReadRemoteFileOperation.java b/src/com/owncloud/android/lib/resources/files/ReadRemoteFileOperation.java index dc44fcae..c710d0a2 100644 --- a/src/com/owncloud/android/lib/resources/files/ReadRemoteFileOperation.java +++ b/src/com/owncloud/android/lib/resources/files/ReadRemoteFileOperation.java @@ -40,7 +40,7 @@ import com.owncloud.android.lib.common.utils.Log_OC; /** * Remote operation performing the read a file from the ownCloud server. - * + * * @author David A. Velasco * @author masensio */ @@ -50,70 +50,70 @@ public class ReadRemoteFileOperation extends RemoteOperation { private static final String TAG = ReadRemoteFileOperation.class.getSimpleName(); private static final int SYNC_READ_TIMEOUT = 40000; private static final int SYNC_CONNECTION_TIMEOUT = 5000; - + private String mRemotePath; - - + + /** * Constructor - * - * @param remotePath Remote path of the file. + * + * @param remotePath Remote path of the file. */ public ReadRemoteFileOperation(String remotePath) { - mRemotePath = remotePath; + mRemotePath = remotePath; } /** * Performs the read operation. - * - * @param client Client object to communicate with the remote ownCloud server. + * + * @param client Client object to communicate with the remote ownCloud server. */ @Override protected RemoteOperationResult run(OwnCloudClient client) { - PropFindMethod propfind = null; - RemoteOperationResult result = null; + PropFindMethod propfind = null; + RemoteOperationResult result = null; - /// take the duty of check the server for the current state of the file there - try { + /// take the duty of check the server for the current state of the file there + try { // remote request - propfind = new PropFindMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath), - WebdavUtils.getFilePropSet(), // PropFind Properties - DavConstants.DEPTH_0); - int status; - status = client.executeMethod(propfind, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT); + propfind = new PropFindMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath), + WebdavUtils.getFilePropSet(), // PropFind Properties + DavConstants.DEPTH_0); + int status; + status = client.executeMethod(propfind, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT); - boolean isSuccess = ( - status == HttpStatus.SC_MULTI_STATUS || - status == HttpStatus.SC_OK - ); - if (isSuccess) { - // Parse response - MultiStatus resp = propfind.getResponseBodyAsMultiStatus(); - WebdavEntry we = new WebdavEntry(resp.getResponses()[0], - client.getWebdavUri().getPath()); - RemoteFile remoteFile = new RemoteFile(we); - ArrayList files = new ArrayList(); - files.add(remoteFile); + boolean isSuccess = ( + status == HttpStatus.SC_MULTI_STATUS || + status == HttpStatus.SC_OK + ); + if (isSuccess) { + // Parse response + MultiStatus resp = propfind.getResponseBodyAsMultiStatus(); + WebdavEntry we = new WebdavEntry(resp.getResponses()[0], + client.getWebdavUri().getPath()); + RemoteFile remoteFile = new RemoteFile(we); + ArrayList files = new ArrayList(); + files.add(remoteFile); - // Result of the operation - result = new RemoteOperationResult(true, status, propfind.getResponseHeaders()); - result.setData(files); - - } else { - client.exhaustResponse(propfind.getResponseBodyAsStream()); - result = new RemoteOperationResult(false, status, propfind.getResponseHeaders()); - } + // Result of the operation + result = new RemoteOperationResult(true, propfind); + result.setData(files); - } catch (Exception e) { - result = new RemoteOperationResult(e); - e.printStackTrace(); - Log_OC.e(TAG, "Synchronizing file " + mRemotePath + ": " + result.getLogMessage(), - result.getException()); - } finally { - if (propfind != null) - propfind.releaseConnection(); - } - return result; + } else { + result = new RemoteOperationResult(false, propfind); + client.exhaustResponse(propfind.getResponseBodyAsStream()); + } + + } catch (Exception e) { + result = new RemoteOperationResult(e); + e.printStackTrace(); + Log_OC.e(TAG, "Synchronizing file " + mRemotePath + ": " + result.getLogMessage(), + result.getException()); + } finally { + if (propfind != null) + propfind.releaseConnection(); + } + return result; } } diff --git a/src/com/owncloud/android/lib/resources/files/ReadRemoteFolderOperation.java b/src/com/owncloud/android/lib/resources/files/ReadRemoteFolderOperation.java index ef2a06fa..42ea3529 100644 --- a/src/com/owncloud/android/lib/resources/files/ReadRemoteFolderOperation.java +++ b/src/com/owncloud/android/lib/resources/files/ReadRemoteFolderOperation.java @@ -40,126 +40,125 @@ import com.owncloud.android.lib.common.utils.Log_OC; /** * Remote operation performing the read of remote file or folder in the ownCloud server. - * + * * @author David A. Velasco * @author masensio */ public class ReadRemoteFolderOperation extends RemoteOperation { - private static final String TAG = ReadRemoteFolderOperation.class.getSimpleName(); + private static final String TAG = ReadRemoteFolderOperation.class.getSimpleName(); - private String mRemotePath; - private ArrayList mFolderAndFiles; - - /** + private String mRemotePath; + private ArrayList mFolderAndFiles; + + /** * Constructor - * - * @param remotePath Remote path of the file. + * + * @param remotePath Remote path of the file. */ - public ReadRemoteFolderOperation(String remotePath) { - mRemotePath = remotePath; - } + public ReadRemoteFolderOperation(String remotePath) { + mRemotePath = remotePath; + } - /** + /** * Performs the read operation. - * - * @param client Client object to communicate with the remote ownCloud server. + * + * @param client Client object to communicate with the remote ownCloud server. */ - @Override - protected RemoteOperationResult run(OwnCloudClient client) { - RemoteOperationResult result = null; + @Override + protected RemoteOperationResult run(OwnCloudClient client) { + RemoteOperationResult result = null; PropFindMethod query = null; - + try { // remote request query = new PropFindMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath), - WebdavUtils.getAllPropSet(), // PropFind Properties - DavConstants.DEPTH_1); + WebdavUtils.getAllPropSet(), // PropFind Properties + DavConstants.DEPTH_1); int status = client.executeMethod(query); // check and process response boolean isSuccess = ( - status == HttpStatus.SC_MULTI_STATUS || + status == HttpStatus.SC_MULTI_STATUS || status == HttpStatus.SC_OK - ); + ); if (isSuccess) { - // get data from remote folder - MultiStatus dataInServer = query.getResponseBodyAsMultiStatus(); - readData(dataInServer, client); - - // Result of the operation - result = new RemoteOperationResult(true, status, query.getResponseHeaders()); - // Add data to the result - if (result.isSuccess()) { - result.setData(mFolderAndFiles); - } + // get data from remote folder + MultiStatus dataInServer = query.getResponseBodyAsMultiStatus(); + readData(dataInServer, client); + + // Result of the operation + result = new RemoteOperationResult(true, query); + // Add data to the result + if (result.isSuccess()) { + result.setData(mFolderAndFiles); + } } else { // synchronization failed client.exhaustResponse(query.getResponseBodyAsStream()); - result = new RemoteOperationResult(false, status, query.getResponseHeaders()); + result = new RemoteOperationResult(false, query); } } catch (Exception e) { result = new RemoteOperationResult(e); - + } finally { if (query != null) query.releaseConnection(); // let the connection available for other methods if (result.isSuccess()) { - Log_OC.i(TAG, "Synchronized " + mRemotePath + ": " + result.getLogMessage()); + Log_OC.i(TAG, "Synchronized " + mRemotePath + ": " + result.getLogMessage()); } else { if (result.isException()) { - Log_OC.e(TAG, "Synchronized " + mRemotePath + ": " + result.getLogMessage(), - result.getException()); + Log_OC.e(TAG, "Synchronized " + mRemotePath + ": " + result.getLogMessage(), + result.getException()); } else { Log_OC.e(TAG, "Synchronized " + mRemotePath + ": " + result.getLogMessage()); } } - + } return result; - } + } public boolean isMultiStatus(int status) { - return (status == HttpStatus.SC_MULTI_STATUS); + return (status == HttpStatus.SC_MULTI_STATUS); } /** - * Read the data retrieved from the server about the contents of the target folder - * - * - * @param remoteData Full response got from the server with the data of the target - * folder and its direct children. - * @param client Client instance to the remote server where the data were - * retrieved. - * @return + * Read the data retrieved from the server about the contents of the target folder + * + * @param remoteData Full response got from the server with the data of the target + * folder and its direct children. + * @param client Client instance to the remote server where the data were + * retrieved. + * @return */ - private void readData(MultiStatus remoteData, OwnCloudClient client) { + private void readData(MultiStatus remoteData, OwnCloudClient client) { mFolderAndFiles = new ArrayList(); - + // parse data from remote folder WebdavEntry we = new WebdavEntry(remoteData.getResponses()[0], - client.getWebdavUri().getPath()); + client.getWebdavUri().getPath()); mFolderAndFiles.add(fillOCFile(we)); - + // loop to update every child RemoteFile remoteFile = null; for (int i = 1; i < remoteData.getResponses().length; ++i) { /// new OCFile instance with the data from the server - we = new WebdavEntry(remoteData.getResponses()[i], client.getWebdavUri().getPath()); + we = new WebdavEntry(remoteData.getResponses()[i], client.getWebdavUri().getPath()); remoteFile = fillOCFile(we); mFolderAndFiles.add(remoteFile); } - + } - + /** * Creates and populates a new {@link RemoteFile} object with the data read from the server. - * - * @param we WebDAV entry read from the server for a WebDAV resource (remote file or folder). - * @return New OCFile instance representing the remote resource described by we. + * + * @param we WebDAV entry read from the server for a WebDAV resource (remote file or folder). + * @return New OCFile instance representing the remote resource described by we. */ private RemoteFile fillOCFile(WebdavEntry we) { RemoteFile file = new RemoteFile(we.decodedPath()); diff --git a/src/com/owncloud/android/lib/resources/files/RemoveRemoteFileOperation.java b/src/com/owncloud/android/lib/resources/files/RemoveRemoteFileOperation.java index 6aafa1c7..2f15adeb 100644 --- a/src/com/owncloud/android/lib/resources/files/RemoveRemoteFileOperation.java +++ b/src/com/owncloud/android/lib/resources/files/RemoveRemoteFileOperation.java @@ -35,7 +35,7 @@ import com.owncloud.android.lib.common.utils.Log_OC; /** * Remote operation performing the removal of a remote file or folder in the ownCloud server. - * + * * @author David A. Velasco * @author masensio */ @@ -45,46 +45,48 @@ public class RemoveRemoteFileOperation extends RemoteOperation { private static final int REMOVE_READ_TIMEOUT = 30000; private static final int REMOVE_CONNECTION_TIMEOUT = 5000; - private String mRemotePath; + private String mRemotePath; /** * Constructor - * - * @param remotePath RemotePath of the remote file or folder to remove from the server + * + * @param remotePath RemotePath of the remote file or folder to remove from the server */ - public RemoveRemoteFileOperation(String remotePath) { - mRemotePath = remotePath; - } + public RemoveRemoteFileOperation(String remotePath) { + mRemotePath = remotePath; + } - /** - * Performs the rename operation. - * - * @param client Client object to communicate with the remote ownCloud server. - */ - @Override - protected RemoteOperationResult run(OwnCloudClient client) { - RemoteOperationResult result = null; + /** + * Performs the rename operation. + * + * @param client Client object to communicate with the remote ownCloud server. + */ + @Override + protected RemoteOperationResult run(OwnCloudClient client) { + RemoteOperationResult result = null; DeleteMethod delete = null; - + try { - delete = new DeleteMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath)); - int status = client.executeMethod(delete, REMOVE_READ_TIMEOUT, REMOVE_CONNECTION_TIMEOUT); - - delete.getResponseBodyAsString(); // exhaust the response, although not interesting - result = new RemoteOperationResult((delete.succeeded() || - status == HttpStatus.SC_NOT_FOUND), status, delete.getResponseHeaders()); - Log_OC.i(TAG, "Remove " + mRemotePath + ": " + result.getLogMessage()); + delete = new DeleteMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath)); + int status = client.executeMethod(delete, REMOVE_READ_TIMEOUT, REMOVE_CONNECTION_TIMEOUT); + + delete.getResponseBodyAsString(); // exhaust the response, although not interesting + result = new RemoteOperationResult( + (delete.succeeded() || status == HttpStatus.SC_NOT_FOUND), + delete + ); + Log_OC.i(TAG, "Remove " + mRemotePath + ": " + result.getLogMessage()); } catch (Exception e) { - result = new RemoteOperationResult(e); - Log_OC.e(TAG, "Remove " + mRemotePath + ": " + result.getLogMessage(), e); + result = new RemoteOperationResult(e); + Log_OC.e(TAG, "Remove " + mRemotePath + ": " + result.getLogMessage(), e); } finally { - if (delete != null) - delete.releaseConnection(); + if (delete != null) + delete.releaseConnection(); } - - return result; - } + + return result; + } } diff --git a/src/com/owncloud/android/lib/resources/files/RenameRemoteFileOperation.java b/src/com/owncloud/android/lib/resources/files/RenameRemoteFileOperation.java index ecbf815d..e1cfd9c8 100644 --- a/src/com/owncloud/android/lib/resources/files/RenameRemoteFileOperation.java +++ b/src/com/owncloud/android/lib/resources/files/RenameRemoteFileOperation.java @@ -39,62 +39,62 @@ import com.owncloud.android.lib.resources.status.OwnCloudVersion; /** * Remote operation performing the rename of a remote file or folder in the ownCloud server. - * + * * @author David A. Velasco * @author masensio */ public class RenameRemoteFileOperation extends RemoteOperation { - private static final String TAG = RenameRemoteFileOperation.class.getSimpleName(); + private static final String TAG = RenameRemoteFileOperation.class.getSimpleName(); - private static final int RENAME_READ_TIMEOUT = 600000; - private static final int RENAME_CONNECTION_TIMEOUT = 5000; + private static final int RENAME_READ_TIMEOUT = 600000; + private static final int RENAME_CONNECTION_TIMEOUT = 5000; private String mOldName; private String mOldRemotePath; private String mNewName; private String mNewRemotePath; - - + + /** * Constructor - * - * @param oldName Old name of the file. - * @param oldRemotePath Old remote path of the file. - * @param newName New name to set as the name of file. - * @param isFolder 'true' for folder and 'false' for files + * + * @param oldName Old name of the file. + * @param oldRemotePath Old remote path of the file. + * @param newName New name to set as the name of file. + * @param isFolder 'true' for folder and 'false' for files */ - public RenameRemoteFileOperation(String oldName, String oldRemotePath, String newName, + public RenameRemoteFileOperation(String oldName, String oldRemotePath, String newName, boolean isFolder) { - mOldName = oldName; - mOldRemotePath = oldRemotePath; - mNewName = newName; - + mOldName = oldName; + mOldRemotePath = oldRemotePath; + mNewName = newName; + String parent = (new File(mOldRemotePath)).getParent(); parent = (parent.endsWith(FileUtils.PATH_SEPARATOR)) ? parent : parent + - FileUtils.PATH_SEPARATOR; - mNewRemotePath = parent + mNewName; + FileUtils.PATH_SEPARATOR; + mNewRemotePath = parent + mNewName; if (isFolder) { mNewRemotePath += FileUtils.PATH_SEPARATOR; } - } + } - /** + /** * Performs the rename operation. - * - * @param client Client object to communicate with the remote ownCloud server. + * + * @param client Client object to communicate with the remote ownCloud server. */ - @Override - protected RemoteOperationResult run(OwnCloudClient client) { - RemoteOperationResult result = null; - - LocalMoveMethod move = null; + @Override + protected RemoteOperationResult run(OwnCloudClient client) { + RemoteOperationResult result = null; + + LocalMoveMethod move = null; OwnCloudVersion version = client.getOwnCloudVersion(); boolean versionWithForbiddenChars = - (version != null && version.isVersionWithForbiddenCharacters()); + (version != null && version.isVersionWithForbiddenCharacters()); boolean noInvalidChars = FileUtils.isValidPath(mNewRemotePath, versionWithForbiddenChars); - + if (noInvalidChars) { try { if (mNewName.equals(mOldName)) { @@ -106,29 +106,21 @@ public class RenameRemoteFileOperation extends RemoteOperation { return new RemoteOperationResult(ResultCode.INVALID_OVERWRITE); } - move = new LocalMoveMethod( client.getWebdavUri() + - WebdavUtils.encodePath(mOldRemotePath), - client.getWebdavUri() + WebdavUtils.encodePath(mNewRemotePath)); - int status = client.executeMethod(move, RENAME_READ_TIMEOUT, - RENAME_CONNECTION_TIMEOUT); + move = new LocalMoveMethod(client.getWebdavUri() + + WebdavUtils.encodePath(mOldRemotePath), + client.getWebdavUri() + WebdavUtils.encodePath(mNewRemotePath)); + client.executeMethod(move, RENAME_READ_TIMEOUT, RENAME_CONNECTION_TIMEOUT); + result = new RemoteOperationResult(move.succeeded(), move); + Log_OC.i(TAG, "Rename " + mOldRemotePath + " to " + mNewRemotePath + ": " + + result.getLogMessage() + ); + client.exhaustResponse(move.getResponseBodyAsStream()); - if (status == 400) { - result = new RemoteOperationResult(move.succeeded(), - move.getResponseBodyAsString(), status); - Log_OC.d(TAG, move.getResponseBodyAsString()); - } else { - client.exhaustResponse(move.getResponseBodyAsStream());//exhaust response, - // although not interesting - result = new RemoteOperationResult(move.succeeded(), status, - move.getResponseHeaders()); - Log_OC.i(TAG, "Rename " + mOldRemotePath + " to " + mNewRemotePath + ": " + - result.getLogMessage()); - } } catch (Exception e) { result = new RemoteOperationResult(e); Log_OC.e(TAG, "Rename " + mOldRemotePath + " to " + - ((mNewRemotePath==null) ? mNewName : mNewRemotePath) + ": " + - result.getLogMessage(), e); + ((mNewRemotePath == null) ? mNewName : mNewRemotePath) + ": " + + result.getLogMessage(), e); } finally { if (move != null) @@ -136,16 +128,15 @@ public class RenameRemoteFileOperation extends RemoteOperation { } } else { - result = new RemoteOperationResult(ResultCode.INVALID_CHARACTER_IN_NAME); + result = new RemoteOperationResult(ResultCode.INVALID_CHARACTER_IN_NAME); } - + return result; - } - - /** - * Move operation - * - */ + } + + /** + * Move operation + */ private class LocalMoveMethod extends DavMethodBase { public LocalMoveMethod(String uri, String dest) { @@ -162,7 +153,7 @@ public class RenameRemoteFileOperation extends RemoteOperation { protected boolean isSuccess(int status) { return status == 201 || status == 204; } - + } } diff --git a/src/com/owncloud/android/lib/resources/files/UploadRemoteFileOperation.java b/src/com/owncloud/android/lib/resources/files/UploadRemoteFileOperation.java index 1f5ecb19..74dbdab7 100644 --- a/src/com/owncloud/android/lib/resources/files/UploadRemoteFileOperation.java +++ b/src/com/owncloud/android/lib/resources/files/UploadRemoteFileOperation.java @@ -69,7 +69,6 @@ public class UploadRemoteFileOperation extends RemoteOperation { protected String mMimeType; protected String mFileLastModifTimestamp; protected PutMethod mPutMethod = null; - protected boolean mForbiddenCharsInServer = false; protected String mRequiredEtag = null; protected final AtomicBoolean mCancellationRequested = new AtomicBoolean(false); @@ -112,14 +111,7 @@ public class UploadRemoteFileOperation extends RemoteOperation { } else { // perform the upload - int status = uploadFile(client); - if (mForbiddenCharsInServer){ - result = new RemoteOperationResult( - RemoteOperationResult.ResultCode.INVALID_CHARACTER_DETECT_IN_SERVER); - } else { - result = new RemoteOperationResult(isSuccess(status), status, - (mPutMethod != null ? mPutMethod.getResponseHeaders() : null)); - } + result = uploadFile(client); } } catch (Exception e) { @@ -144,8 +136,9 @@ public class UploadRemoteFileOperation extends RemoteOperation { status == HttpStatus.SC_NO_CONTENT)); } - protected int uploadFile(OwnCloudClient client) throws IOException { - int status = -1; + protected RemoteOperationResult uploadFile(OwnCloudClient client) throws IOException { + int status; + RemoteOperationResult result; try { File f = new File(mLocalPath); mEntity = new FileRequestEntity(f, mMimeType); @@ -163,25 +156,16 @@ public class UploadRemoteFileOperation extends RemoteOperation { mPutMethod.setRequestEntity(mEntity); status = client.executeMethod(mPutMethod); - if (status == 400) { - InvalidCharacterExceptionParser xmlParser = new InvalidCharacterExceptionParser(); - InputStream is = new ByteArrayInputStream( - mPutMethod.getResponseBodyAsString().getBytes()); - try { - mForbiddenCharsInServer = xmlParser.parseXMLResponse(is); - - } catch (Exception e) { - mForbiddenCharsInServer = false; - Log_OC.e(TAG, "Exception reading exception from server", e); - } - } - + result = new RemoteOperationResult( + isSuccess(status), + mPutMethod + ); client.exhaustResponse(mPutMethod.getResponseBodyAsStream()); } finally { mPutMethod.releaseConnection(); // let the connection available for other methods } - return status; + return result; } public Set getDataTransferListeners() { diff --git a/src/com/owncloud/android/lib/resources/shares/CreateRemoteShareOperation.java b/src/com/owncloud/android/lib/resources/shares/CreateRemoteShareOperation.java index 7990a05e..7d8f2179 100644 --- a/src/com/owncloud/android/lib/resources/shares/CreateRemoteShareOperation.java +++ b/src/com/owncloud/android/lib/resources/shares/CreateRemoteShareOperation.java @@ -39,137 +39,138 @@ import com.owncloud.android.lib.common.utils.Log_OC; */ public class CreateRemoteShareOperation extends RemoteOperation { - private static final String TAG = CreateRemoteShareOperation.class.getSimpleName(); + private static final String TAG = CreateRemoteShareOperation.class.getSimpleName(); - private static final String PARAM_PATH = "path"; - private static final String PARAM_SHARE_TYPE = "shareType"; - private static final String PARAM_SHARE_WITH = "shareWith"; - private static final String PARAM_PUBLIC_UPLOAD = "publicUpload"; - private static final String PARAM_PASSWORD = "password"; - private static final String PARAM_PERMISSIONS = "permissions"; + private static final String PARAM_PATH = "path"; + private static final String PARAM_SHARE_TYPE = "shareType"; + private static final String PARAM_SHARE_WITH = "shareWith"; + private static final String PARAM_PUBLIC_UPLOAD = "publicUpload"; + private static final String PARAM_PASSWORD = "password"; + private static final String PARAM_PERMISSIONS = "permissions"; - private String mRemoteFilePath; - private ShareType mShareType; - private String mShareWith; - private boolean mPublicUpload; - private String mPassword; - private int mPermissions; - private boolean mGetShareDetails; + private String mRemoteFilePath; + private ShareType mShareType; + private String mShareWith; + private boolean mPublicUpload; + private String mPassword; + private int mPermissions; + private boolean mGetShareDetails; - /** - * Constructor - * @param remoteFilePath Full path of the file/folder being shared. Mandatory argument - * @param shareType 0 = user, 1 = group, 3 = Public link. Mandatory argument - * @param shareWith User/group ID with who the file should be shared. This is mandatory for shareType - * of 0 or 1 - * @param publicUpload If false (default) public cannot upload to a public shared folder. - * If true public can upload to a shared folder. Only available for public link shares - * @param password Password to protect a public link share. Only available for public link shares - * @param permissions 1 - Read only Default for public shares - * 2 - Update - * 4 - Create - * 8 - Delete - * 16- Re-share - * 31- All above Default for private shares - * For user or group shares. - * To obtain combinations, add the desired values together. - * For instance, for Re-Share, delete, read, update, add 16+8+2+1 = 27. - */ - public CreateRemoteShareOperation( - String remoteFilePath, - ShareType shareType, - String shareWith, - boolean publicUpload, - String password, - int permissions - ) { + /** + * Constructor + * + * @param remoteFilePath Full path of the file/folder being shared. Mandatory argument + * @param shareType 0 = user, 1 = group, 3 = Public link. Mandatory argument + * @param shareWith User/group ID with who the file should be shared. This is mandatory for shareType + * of 0 or 1 + * @param publicUpload If false (default) public cannot upload to a public shared folder. + * If true public can upload to a shared folder. Only available for public link shares + * @param password Password to protect a public link share. Only available for public link shares + * @param permissions 1 - Read only Default for public shares + * 2 - Update + * 4 - Create + * 8 - Delete + * 16- Re-share + * 31- All above Default for private shares + * For user or group shares. + * To obtain combinations, add the desired values together. + * For instance, for Re-Share, delete, read, update, add 16+8+2+1 = 27. + */ + public CreateRemoteShareOperation( + String remoteFilePath, + ShareType shareType, + String shareWith, + boolean publicUpload, + String password, + int permissions + ) { - mRemoteFilePath = remoteFilePath; - mShareType = shareType; - mShareWith = shareWith; - mPublicUpload = publicUpload; - mPassword = password; - mPermissions = permissions; - mGetShareDetails = false; // defaults to false for backwards compatibility - } + mRemoteFilePath = remoteFilePath; + mShareType = shareType; + mShareWith = shareWith; + mPublicUpload = publicUpload; + mPassword = password; + mPermissions = permissions; + mGetShareDetails = false; // defaults to false for backwards compatibility + } - public boolean isGettingShareDetails () { - return mGetShareDetails; - } + public boolean isGettingShareDetails() { + return mGetShareDetails; + } - public void setGetShareDetails(boolean set) { - mGetShareDetails = set; - } + public void setGetShareDetails(boolean set) { + mGetShareDetails = set; + } - @Override - protected RemoteOperationResult run(OwnCloudClient client) { - RemoteOperationResult result = null; - int status = -1; + @Override + protected RemoteOperationResult run(OwnCloudClient client) { + RemoteOperationResult result = null; + int status = -1; - PostMethod post = null; + PostMethod post = null; - try { - // Post Method - post = new PostMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH); + try { + // Post Method + post = new PostMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH); - post.setRequestHeader( "Content-Type", - "application/x-www-form-urlencoded; charset=utf-8"); // necessary for special characters + post.setRequestHeader("Content-Type", + "application/x-www-form-urlencoded; charset=utf-8"); // necessary for special characters - post.addParameter(PARAM_PATH, mRemoteFilePath); - post.addParameter(PARAM_SHARE_TYPE, Integer.toString(mShareType.getValue())); - post.addParameter(PARAM_SHARE_WITH, mShareWith); - if (mPublicUpload) { - post.addParameter(PARAM_PUBLIC_UPLOAD, Boolean.toString(true)); - } - if (mPassword != null && mPassword.length() > 0) { - post.addParameter(PARAM_PASSWORD, mPassword); - } - if (OCShare.DEFAULT_PERMISSION != mPermissions) { - post.addParameter(PARAM_PERMISSIONS, Integer.toString(mPermissions)); - } + post.addParameter(PARAM_PATH, mRemoteFilePath); + post.addParameter(PARAM_SHARE_TYPE, Integer.toString(mShareType.getValue())); + post.addParameter(PARAM_SHARE_WITH, mShareWith); + if (mPublicUpload) { + post.addParameter(PARAM_PUBLIC_UPLOAD, Boolean.toString(true)); + } + if (mPassword != null && mPassword.length() > 0) { + post.addParameter(PARAM_PASSWORD, mPassword); + } + if (OCShare.DEFAULT_PERMISSION != mPermissions) { + post.addParameter(PARAM_PERMISSIONS, Integer.toString(mPermissions)); + } - post.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); - - status = client.executeMethod(post); + post.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); - if(isSuccess(status)) { - String response = post.getResponseBodyAsString(); + status = client.executeMethod(post); - ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser( - new ShareXMLParser() - ); - parser.setOneOrMoreSharesRequired(true); - parser.setOwnCloudVersion(client.getOwnCloudVersion()); - parser.setServerBaseUri(client.getBaseUri()); - result = parser.parse(response); + if (isSuccess(status)) { + String response = post.getResponseBodyAsString(); - if (result.isSuccess() && mGetShareDetails) { - // retrieve more info - POST only returns the index of the new share - OCShare emptyShare = (OCShare) result.getData().get(0); - GetRemoteShareOperation getInfo = new GetRemoteShareOperation( - emptyShare.getRemoteId() - ); - result = getInfo.execute(client); - } + ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser( + new ShareXMLParser() + ); + parser.setOneOrMoreSharesRequired(true); + parser.setOwnCloudVersion(client.getOwnCloudVersion()); + parser.setServerBaseUri(client.getBaseUri()); + result = parser.parse(response); - } else { - result = new RemoteOperationResult(false, status, post.getResponseHeaders()); - } - - } catch (Exception e) { - result = new RemoteOperationResult(e); - Log_OC.e(TAG, "Exception while Creating New Share", e); - - } finally { - if (post != null) { - post.releaseConnection(); - } - } - return result; - } + if (result.isSuccess() && mGetShareDetails) { + // retrieve more info - POST only returns the index of the new share + OCShare emptyShare = (OCShare) result.getData().get(0); + GetRemoteShareOperation getInfo = new GetRemoteShareOperation( + emptyShare.getRemoteId() + ); + result = getInfo.execute(client); + } - private boolean isSuccess(int status) { - return (status == HttpStatus.SC_OK); - } + } else { + result = new RemoteOperationResult(false, post); + } + + } catch (Exception e) { + result = new RemoteOperationResult(e); + Log_OC.e(TAG, "Exception while Creating New Share", e); + + } finally { + if (post != null) { + post.releaseConnection(); + } + } + return result; + } + + private boolean isSuccess(int status) { + return (status == HttpStatus.SC_OK); + } } diff --git a/src/com/owncloud/android/lib/resources/shares/GetRemoteShareOperation.java b/src/com/owncloud/android/lib/resources/shares/GetRemoteShareOperation.java index 165a28fa..3d3e396c 100644 --- a/src/com/owncloud/android/lib/resources/shares/GetRemoteShareOperation.java +++ b/src/com/owncloud/android/lib/resources/shares/GetRemoteShareOperation.java @@ -33,68 +33,68 @@ import com.owncloud.android.lib.common.utils.Log_OC; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.GetMethod; -/** +/** * Get the data about a Share resource, known its remote ID. */ public class GetRemoteShareOperation extends RemoteOperation { - private static final String TAG = GetRemoteShareOperation.class.getSimpleName(); + private static final String TAG = GetRemoteShareOperation.class.getSimpleName(); - private long mRemoteId; + private long mRemoteId; - public GetRemoteShareOperation(long remoteId) { - mRemoteId = remoteId; - } + public GetRemoteShareOperation(long remoteId) { + mRemoteId = remoteId; + } - @Override - protected RemoteOperationResult run(OwnCloudClient client) { - RemoteOperationResult result = null; - int status = -1; + @Override + protected RemoteOperationResult run(OwnCloudClient client) { + RemoteOperationResult result = null; + int status = -1; - // Get Method - GetMethod get = null; + // Get Method + GetMethod get = null; - // Get the response - try{ - get = new GetMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH + "/" + Long.toString(mRemoteId)); - get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); + // Get the response + try { + get = new GetMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH + "/" + Long.toString(mRemoteId)); + get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); - status = client.executeMethod(get); + status = client.executeMethod(get); - if(isSuccess(status)) { - String response = get.getResponseBodyAsString(); + if (isSuccess(status)) { + String response = get.getResponseBodyAsString(); - // Parse xml response and obtain the list of shares - ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser( - new ShareXMLParser() - ); - parser.setOneOrMoreSharesRequired(true); - parser.setOwnCloudVersion(client.getOwnCloudVersion()); - parser.setServerBaseUri(client.getBaseUri()); - result = parser.parse(response); + // Parse xml response and obtain the list of shares + ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser( + new ShareXMLParser() + ); + parser.setOneOrMoreSharesRequired(true); + parser.setOwnCloudVersion(client.getOwnCloudVersion()); + parser.setServerBaseUri(client.getBaseUri()); + result = parser.parse(response); - } else { - result = new RemoteOperationResult(false, status, get.getResponseHeaders()); - } - - } catch (Exception e) { - result = new RemoteOperationResult(e); - Log_OC.e(TAG, "Exception while getting remote shares ", e); - - } finally { - if (get != null) { - get.releaseConnection(); - } - } - return result; - } + } else { + result = new RemoteOperationResult(false, get); + } - private boolean isSuccess(int status) { - return (status == HttpStatus.SC_OK); - } + } catch (Exception e) { + result = new RemoteOperationResult(e); + Log_OC.e(TAG, "Exception while getting remote shares ", e); + + } finally { + if (get != null) { + get.releaseConnection(); + } + } + return result; + } + + private boolean isSuccess(int status) { + return (status == HttpStatus.SC_OK); + } } diff --git a/src/com/owncloud/android/lib/resources/shares/GetRemoteShareesOperation.java b/src/com/owncloud/android/lib/resources/shares/GetRemoteShareesOperation.java index b9d279e7..569101cc 100644 --- a/src/com/owncloud/android/lib/resources/shares/GetRemoteShareesOperation.java +++ b/src/com/owncloud/android/lib/resources/shares/GetRemoteShareesOperation.java @@ -166,13 +166,13 @@ public class GetRemoteShareesOperation extends RemoteOperation{ } // Result - result = new RemoteOperationResult(true, status, get.getResponseHeaders()); + result = new RemoteOperationResult(true, get); result.setData(data); Log_OC.d(TAG, "*** Get Users or groups completed " ); } else { - result = new RemoteOperationResult(false, status, get.getResponseHeaders()); + result = new RemoteOperationResult(false, get); String response = get.getResponseBodyAsString(); Log_OC.e(TAG, "Failed response while getting users/groups from the server "); if (response != null) { diff --git a/src/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.java b/src/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.java index f2bbe161..3f6a434e 100644 --- a/src/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.java +++ b/src/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.java @@ -36,94 +36,94 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.utils.Log_OC; /** - * Provide a list shares for a specific file. - * The input is the full path of the desired file. + * Provide a list shares for a specific file. + * The input is the full path of the desired file. * The output is a list of everyone who has the file shared with them. */ public class GetRemoteSharesForFileOperation extends RemoteOperation { - private static final String TAG = GetRemoteSharesForFileOperation.class.getSimpleName(); - - private static final String PARAM_PATH = "path"; - private static final String PARAM_RESHARES = "reshares"; - private static final String PARAM_SUBFILES = "subfiles"; + private static final String TAG = GetRemoteSharesForFileOperation.class.getSimpleName(); - private String mRemoteFilePath; - private boolean mReshares; - private boolean mSubfiles; - - /** - * Constructor - * - * @param remoteFilePath Path to file or folder - * @param reshares If set to false (default), only shares owned by the current user are - * returned. - * If set to true, shares owned by any user from the given file are returned. - * @param subfiles If set to false (default), lists only the folder being shared - * If set to true, all shared files within the folder are returned. - */ - public GetRemoteSharesForFileOperation(String remoteFilePath, boolean reshares, - boolean subfiles) { - mRemoteFilePath = remoteFilePath; - mReshares = reshares; - mSubfiles = subfiles; - } + private static final String PARAM_PATH = "path"; + private static final String PARAM_RESHARES = "reshares"; + private static final String PARAM_SUBFILES = "subfiles"; - @Override - protected RemoteOperationResult run(OwnCloudClient client) { - RemoteOperationResult result = null; - int status = -1; + private String mRemoteFilePath; + private boolean mReshares; + private boolean mSubfiles; - GetMethod get = null; + /** + * Constructor + * + * @param remoteFilePath Path to file or folder + * @param reshares If set to false (default), only shares owned by the current user are + * returned. + * If set to true, shares owned by any user from the given file are returned. + * @param subfiles If set to false (default), lists only the folder being shared + * If set to true, all shared files within the folder are returned. + */ + public GetRemoteSharesForFileOperation(String remoteFilePath, boolean reshares, + boolean subfiles) { + mRemoteFilePath = remoteFilePath; + mReshares = reshares; + mSubfiles = subfiles; + } - try { - // Get Method - get = new GetMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH); + @Override + protected RemoteOperationResult run(OwnCloudClient client) { + RemoteOperationResult result = null; + int status = -1; - // Add Parameters to Get Method - get.setQueryString(new NameValuePair[]{ - new NameValuePair(PARAM_PATH, mRemoteFilePath), - new NameValuePair(PARAM_RESHARES, String.valueOf(mReshares)), - new NameValuePair(PARAM_SUBFILES, String.valueOf(mSubfiles)) - }); + GetMethod get = null; - get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); - - status = client.executeMethod(get); + try { + // Get Method + get = new GetMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH); - if(isSuccess(status)) { - String response = get.getResponseBodyAsString(); + // Add Parameters to Get Method + get.setQueryString(new NameValuePair[]{ + new NameValuePair(PARAM_PATH, mRemoteFilePath), + new NameValuePair(PARAM_RESHARES, String.valueOf(mReshares)), + new NameValuePair(PARAM_SUBFILES, String.valueOf(mSubfiles)) + }); - // Parse xml response and obtain the list of shares - ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser( - new ShareXMLParser() - ); - parser.setOwnCloudVersion(client.getOwnCloudVersion()); - parser.setServerBaseUri(client.getBaseUri()); - result = parser.parse(response); + get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); - if (result.isSuccess()) { - Log_OC.d(TAG, "Got " + result.getData().size() + " shares"); - } + status = client.executeMethod(get); - } else { - result = new RemoteOperationResult(false, status, get.getResponseHeaders()); - } - - } catch (Exception e) { - result = new RemoteOperationResult(e); - Log_OC.e(TAG, "Exception while getting shares", e); - - } finally { - if (get != null) { - get.releaseConnection(); - } - } - return result; - } + if (isSuccess(status)) { + String response = get.getResponseBodyAsString(); - private boolean isSuccess(int status) { - return (status == HttpStatus.SC_OK); - } + // Parse xml response and obtain the list of shares + ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser( + new ShareXMLParser() + ); + parser.setOwnCloudVersion(client.getOwnCloudVersion()); + parser.setServerBaseUri(client.getBaseUri()); + result = parser.parse(response); + + if (result.isSuccess()) { + Log_OC.d(TAG, "Got " + result.getData().size() + " shares"); + } + + } else { + result = new RemoteOperationResult(false, get); + } + + } catch (Exception e) { + result = new RemoteOperationResult(e); + Log_OC.e(TAG, "Exception while getting shares", e); + + } finally { + if (get != null) { + get.releaseConnection(); + } + } + return result; + } + + private boolean isSuccess(int status) { + return (status == HttpStatus.SC_OK); + } } diff --git a/src/com/owncloud/android/lib/resources/shares/GetRemoteSharesOperation.java b/src/com/owncloud/android/lib/resources/shares/GetRemoteSharesOperation.java index 05a45b08..022a644a 100644 --- a/src/com/owncloud/android/lib/resources/shares/GetRemoteSharesOperation.java +++ b/src/com/owncloud/android/lib/resources/shares/GetRemoteSharesOperation.java @@ -34,62 +34,61 @@ 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; -/** +/** * Get the data from the server about ALL the known shares owned by the requester. - * */ public class GetRemoteSharesOperation extends RemoteOperation { - private static final String TAG = GetRemoteSharesOperation.class.getSimpleName(); + private static final String TAG = GetRemoteSharesOperation.class.getSimpleName(); - public GetRemoteSharesOperation() { - } + public GetRemoteSharesOperation() { + } - @Override - protected RemoteOperationResult run(OwnCloudClient client) { - RemoteOperationResult result = null; - int status = -1; + @Override + protected RemoteOperationResult run(OwnCloudClient client) { + RemoteOperationResult result = null; + int status = -1; - // Get Method - GetMethod get = null; + // Get Method + GetMethod get = null; - // Get the response - try{ - get = new GetMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH); - get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); - status = client.executeMethod(get); + // Get the response + try { + get = new GetMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH); + get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); + status = client.executeMethod(get); - if(isSuccess(status)) { - String response = get.getResponseBodyAsString(); + if (isSuccess(status)) { + String response = get.getResponseBodyAsString(); - // Parse xml response and obtain the list of shares - ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser( - new ShareXMLParser() - ); - parser.setOwnCloudVersion(client.getOwnCloudVersion()); - parser.setServerBaseUri(client.getBaseUri()); - result = parser.parse(response); - } else { - result = new RemoteOperationResult(false, status, get.getResponseHeaders()); - } - - } catch (Exception e) { - result = new RemoteOperationResult(e); - Log_OC.e(TAG, "Exception while getting remote shares ", e); - - } finally { - if (get != null) { - get.releaseConnection(); - } - } - return result; - } + // Parse xml response and obtain the list of shares + ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser( + new ShareXMLParser() + ); + parser.setOwnCloudVersion(client.getOwnCloudVersion()); + parser.setServerBaseUri(client.getBaseUri()); + result = parser.parse(response); + } else { + result = new RemoteOperationResult(false, get); + } - private boolean isSuccess(int status) { - return (status == HttpStatus.SC_OK); - } + } catch (Exception e) { + result = new RemoteOperationResult(e); + Log_OC.e(TAG, "Exception while getting remote shares ", e); + + } finally { + if (get != null) { + get.releaseConnection(); + } + } + return result; + } + + private boolean isSuccess(int status) { + return (status == HttpStatus.SC_OK); + } } diff --git a/src/com/owncloud/android/lib/resources/shares/RemoveRemoteShareOperation.java b/src/com/owncloud/android/lib/resources/shares/RemoveRemoteShareOperation.java index 65e68f0c..b61a8cee 100644 --- a/src/com/owncloud/android/lib/resources/shares/RemoveRemoteShareOperation.java +++ b/src/com/owncloud/android/lib/resources/shares/RemoveRemoteShareOperation.java @@ -40,63 +40,63 @@ import com.owncloud.android.lib.common.utils.Log_OC; public class RemoveRemoteShareOperation extends RemoteOperation { - private static final String TAG = RemoveRemoteShareOperation.class.getSimpleName(); - - private int mRemoteShareId; - - /** - * Constructor - * - * @param remoteShareId Share ID - */ - - public RemoveRemoteShareOperation(int remoteShareId) { - mRemoteShareId = remoteShareId; - - } + private static final String TAG = RemoveRemoteShareOperation.class.getSimpleName(); - @Override - protected RemoteOperationResult run(OwnCloudClient client) { - RemoteOperationResult result = null; - int status = -1; + private int mRemoteShareId; - DeleteMethod delete = null; + /** + * Constructor + * + * @param remoteShareId Share ID + */ - try { - String id = "/" + String.valueOf(mRemoteShareId); - delete = new DeleteMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH + id); + public RemoveRemoteShareOperation(int remoteShareId) { + mRemoteShareId = remoteShareId; - delete.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); + } - status = client.executeMethod(delete); + @Override + protected RemoteOperationResult run(OwnCloudClient client) { + RemoteOperationResult result = null; + int status = -1; - if(isSuccess(status)) { - String response = delete.getResponseBodyAsString(); + DeleteMethod delete = null; - // Parse xml response and obtain the list of shares - ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser( - new ShareXMLParser() - ); - result = parser.parse(response); + try { + String id = "/" + String.valueOf(mRemoteShareId); + delete = new DeleteMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH + id); - Log_OC.d(TAG, "Unshare " + id + ": " + result.getLogMessage()); + delete.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); - } else { - result = new RemoteOperationResult(false, status, delete.getResponseHeaders()); - } - } catch (Exception e) { - result = new RemoteOperationResult(e); - Log_OC.e(TAG, "Unshare Link Exception " + result.getLogMessage(), e); + status = client.executeMethod(delete); - } finally { - if (delete != null) - delete.releaseConnection(); - } - return result; - } + if (isSuccess(status)) { + String response = delete.getResponseBodyAsString(); + + // Parse xml response and obtain the list of shares + ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser( + new ShareXMLParser() + ); + result = parser.parse(response); + + Log_OC.d(TAG, "Unshare " + id + ": " + result.getLogMessage()); + + } else { + result = new RemoteOperationResult(false, delete); + } + } catch (Exception e) { + result = new RemoteOperationResult(e); + Log_OC.e(TAG, "Unshare Link Exception " + result.getLogMessage(), e); + + } finally { + if (delete != null) + delete.releaseConnection(); + } + return result; + } - private boolean isSuccess(int status) { - return (status == HttpStatus.SC_OK); - } + private boolean isSuccess(int status) { + return (status == HttpStatus.SC_OK); + } } \ No newline at end of file diff --git a/src/com/owncloud/android/lib/resources/shares/UpdateRemoteShareOperation.java b/src/com/owncloud/android/lib/resources/shares/UpdateRemoteShareOperation.java index 34d4c3cb..7226cbe3 100644 --- a/src/com/owncloud/android/lib/resources/shares/UpdateRemoteShareOperation.java +++ b/src/com/owncloud/android/lib/resources/shares/UpdateRemoteShareOperation.java @@ -216,7 +216,7 @@ public class UpdateRemoteShareOperation extends RemoteOperation { result = parser.parse(response); } else { - result = new RemoteOperationResult(false, status, put.getResponseHeaders()); + result = new RemoteOperationResult(false, put); } if (!result.isSuccess()) { break; diff --git a/src/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.java b/src/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.java index d963e1e8..87095024 100644 --- a/src/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.java +++ b/src/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.java @@ -242,18 +242,18 @@ public class GetRemoteCapabilitiesOperation extends RemoteOperation { } // Result data.add(capability); - result = new RemoteOperationResult(true, status, get.getResponseHeaders()); + result = new RemoteOperationResult(true, get); result.setData(data); Log_OC.d(TAG, "*** Get Capabilities completed "); } else { - result = new RemoteOperationResult(statusProp, statuscode, null); + result = new RemoteOperationResult(statusProp, statuscode, null, null); Log_OC.e(TAG, "Failed response while getting capabilities from the server "); Log_OC.e(TAG, "*** status: " + statusProp + "; message: " + message); } } else { - result = new RemoteOperationResult(false, status, get.getResponseHeaders()); + result = new RemoteOperationResult(false, get); String response = get.getResponseBodyAsString(); Log_OC.e(TAG, "Failed response while getting capabilities from the server "); if (response != null) { diff --git a/src/com/owncloud/android/lib/resources/status/GetRemoteStatusOperation.java b/src/com/owncloud/android/lib/resources/status/GetRemoteStatusOperation.java index 8d5aa7a0..d488274f 100644 --- a/src/com/owncloud/android/lib/resources/status/GetRemoteStatusOperation.java +++ b/src/com/owncloud/android/lib/resources/status/GetRemoteStatusOperation.java @@ -46,32 +46,31 @@ import com.owncloud.android.lib.common.utils.Log_OC; /** * Checks if the server is valid and if the server supports the Share API - * + * * @author David A. Velasco * @author masensio - * */ public class GetRemoteStatusOperation extends RemoteOperation { - - /** - * Maximum time to wait for a response from the server when the connection is being tested, + + /** + * Maximum time to wait for a response from the server when the connection is being tested, * in MILLISECONDs. */ public static final int TRY_CONNECTION_TIMEOUT = 5000; - + private static final String TAG = GetRemoteStatusOperation.class.getSimpleName(); - + private static final String NODE_INSTALLED = "installed"; private static final String NODE_VERSION = "version"; - + private RemoteOperationResult mLatestResult; private Context mContext; public GetRemoteStatusOperation(Context context) { mContext = context; } - + private boolean tryConnection(OwnCloudClient client) { boolean retval = false; GetMethod get = null; @@ -81,95 +80,90 @@ public class GetRemoteStatusOperation extends RemoteOperation { HttpParams params = get.getParams().getDefaultParams(); params.setParameter(HttpMethodParams.USER_AGENT, - OwnCloudClientManagerFactory.getUserAgent()); + OwnCloudClientManagerFactory.getUserAgent()); get.getParams().setDefaults(params); client.setFollowRedirects(false); boolean isRedirectToNonSecureConnection = false; int status = client.executeMethod(get, TRY_CONNECTION_TIMEOUT, TRY_CONNECTION_TIMEOUT); - mLatestResult = new RemoteOperationResult( - (status == HttpStatus.SC_OK), - status, - get.getResponseHeaders() - ); + mLatestResult = new RemoteOperationResult((status == HttpStatus.SC_OK), get); - String redirectedLocation = mLatestResult.getRedirectedLocation(); - while (redirectedLocation != null && redirectedLocation.length() > 0 - && !mLatestResult.isSuccess()) { - - isRedirectToNonSecureConnection |= ( - baseUrlSt.startsWith("https://") && - redirectedLocation.startsWith("http://") - ); - get.releaseConnection(); - get = new GetMethod(redirectedLocation); - status = client.executeMethod(get, TRY_CONNECTION_TIMEOUT, TRY_CONNECTION_TIMEOUT); - mLatestResult = new RemoteOperationResult( - (status == HttpStatus.SC_OK), - status, - get.getResponseHeaders() - ); - redirectedLocation = mLatestResult.getRedirectedLocation(); - } + String redirectedLocation = mLatestResult.getRedirectedLocation(); + while (redirectedLocation != null && redirectedLocation.length() > 0 + && !mLatestResult.isSuccess()) { + + isRedirectToNonSecureConnection |= ( + baseUrlSt.startsWith("https://") && + redirectedLocation.startsWith("http://") + ); + get.releaseConnection(); + get = new GetMethod(redirectedLocation); + status = client.executeMethod(get, TRY_CONNECTION_TIMEOUT, TRY_CONNECTION_TIMEOUT); + mLatestResult = new RemoteOperationResult( + (status == HttpStatus.SC_OK), + get + ); + redirectedLocation = mLatestResult.getRedirectedLocation(); + } String response = get.getResponseBodyAsString(); if (status == HttpStatus.SC_OK) { JSONObject json = new JSONObject(response); if (!json.getBoolean(NODE_INSTALLED)) { mLatestResult = new RemoteOperationResult( - RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED); + RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED); } else { String version = json.getString(NODE_VERSION); - OwnCloudVersion ocVersion = new OwnCloudVersion(version); + OwnCloudVersion ocVersion = new OwnCloudVersion(version); if (!ocVersion.isVersionValid()) { mLatestResult = new RemoteOperationResult( - RemoteOperationResult.ResultCode.BAD_OC_VERSION); - - } else { - // success - if (isRedirectToNonSecureConnection) { - mLatestResult = new RemoteOperationResult( - RemoteOperationResult.ResultCode. - OK_REDIRECT_TO_NON_SECURE_CONNECTION - ); - } else { - mLatestResult = new RemoteOperationResult( - baseUrlSt.startsWith("https://") ? - RemoteOperationResult.ResultCode.OK_SSL : - RemoteOperationResult.ResultCode.OK_NO_SSL - ); - } + RemoteOperationResult.ResultCode.BAD_OC_VERSION); - ArrayList data = new ArrayList(); - data.add(ocVersion); - mLatestResult.setData(data); - retval = true; + } else { + // success + if (isRedirectToNonSecureConnection) { + mLatestResult = new RemoteOperationResult( + RemoteOperationResult.ResultCode. + OK_REDIRECT_TO_NON_SECURE_CONNECTION + ); + } else { + mLatestResult = new RemoteOperationResult( + baseUrlSt.startsWith("https://") ? + RemoteOperationResult.ResultCode.OK_SSL : + RemoteOperationResult.ResultCode.OK_NO_SSL + ); + } + + ArrayList data = new ArrayList(); + data.add(ocVersion); + mLatestResult.setData(data); + retval = true; } } - + } else { - mLatestResult = new RemoteOperationResult(false, status, get.getResponseHeaders()); + mLatestResult = new RemoteOperationResult(false, get); } } catch (JSONException e) { mLatestResult = new RemoteOperationResult( - RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED); - + RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED); + } catch (Exception e) { mLatestResult = new RemoteOperationResult(e); - + } finally { if (get != null) get.releaseConnection(); } - + if (mLatestResult.isSuccess()) { Log_OC.i(TAG, "Connection check at " + baseUrlSt + ": " + mLatestResult.getLogMessage()); - + } else if (mLatestResult.getException() != null) { - Log_OC.e(TAG, "Connection check at " + baseUrlSt + ": " + mLatestResult.getLogMessage(), - mLatestResult.getException()); - + Log_OC.e(TAG, "Connection check at " + baseUrlSt + ": " + mLatestResult.getLogMessage(), + mLatestResult.getException()); + } else { Log_OC.e(TAG, "Connection check at " + baseUrlSt + ": " + mLatestResult.getLogMessage()); } @@ -179,30 +173,30 @@ public class GetRemoteStatusOperation extends RemoteOperation { private boolean isOnline() { ConnectivityManager cm = (ConnectivityManager) mContext - .getSystemService(Context.CONNECTIVITY_SERVICE); + .getSystemService(Context.CONNECTIVITY_SERVICE); return cm != null && cm.getActiveNetworkInfo() != null - && cm.getActiveNetworkInfo().isConnectedOrConnecting(); + && cm.getActiveNetworkInfo().isConnectedOrConnecting(); } - @Override - protected RemoteOperationResult run(OwnCloudClient client) { + @Override + protected RemoteOperationResult run(OwnCloudClient client) { if (!isOnline()) { - return new RemoteOperationResult(RemoteOperationResult.ResultCode.NO_NETWORK_CONNECTION); + return new RemoteOperationResult(RemoteOperationResult.ResultCode.NO_NETWORK_CONNECTION); } String baseUriStr = client.getBaseUri().toString(); if (baseUriStr.startsWith("http://") || baseUriStr.startsWith("https://")) { tryConnection(client); - + } else { client.setBaseUri(Uri.parse("https://" + baseUriStr)); - boolean httpsSuccess = tryConnection(client); - if (!httpsSuccess && !mLatestResult.isSslRecoverableException()) { + boolean httpsSuccess = tryConnection(client); + if (!httpsSuccess && !mLatestResult.isSslRecoverableException()) { Log_OC.d(TAG, "establishing secure connection failed, trying non secure connection"); client.setBaseUri(Uri.parse("http://" + baseUriStr)); tryConnection(client); } } return mLatestResult; - } - + } + } diff --git a/src/com/owncloud/android/lib/resources/users/GetRemoteUserAvatarOperation.java b/src/com/owncloud/android/lib/resources/users/GetRemoteUserAvatarOperation.java index c6e9fe93..2c1ea9ce 100644 --- a/src/com/owncloud/android/lib/resources/users/GetRemoteUserAvatarOperation.java +++ b/src/com/owncloud/android/lib/resources/users/GetRemoteUserAvatarOperation.java @@ -143,15 +143,15 @@ public class GetRemoteUserAvatarOperation extends RemoteOperation { } // Result - result = new RemoteOperationResult(true, status, get.getResponseHeaders()); + result = new RemoteOperationResult(true, get); ResultData resultData = new ResultData(bos.toByteArray(), mimeType, etag); ArrayList data = new ArrayList(); data.add(resultData); result.setData(data); } else { + result = new RemoteOperationResult(false, get); client.exhaustResponse(get.getResponseBodyAsStream()); - result = new RemoteOperationResult(false, status, get.getResponseHeaders()); } } catch (Exception e) { diff --git a/src/com/owncloud/android/lib/resources/users/GetRemoteUserInfoOperation.java b/src/com/owncloud/android/lib/resources/users/GetRemoteUserInfoOperation.java index 63ca3ca3..0f758ea3 100644 --- a/src/com/owncloud/android/lib/resources/users/GetRemoteUserInfoOperation.java +++ b/src/com/owncloud/android/lib/resources/users/GetRemoteUserInfoOperation.java @@ -86,14 +86,14 @@ public class GetRemoteUserInfoOperation extends RemoteOperation { userInfo.mEmail = respData.getString(NODE_EMAIL); // Result - result = new RemoteOperationResult(true, status, get.getResponseHeaders()); + result = new RemoteOperationResult(true, get); // Username in result.data ArrayList data = new ArrayList(); data.add(userInfo); result.setData(data); } else { - result = new RemoteOperationResult(false, status, get.getResponseHeaders()); + result = new RemoteOperationResult(false, get); String response = get.getResponseBodyAsString(); Log_OC.e(TAG, "Failed response while getting user information "); if (response != null) { diff --git a/src/com/owncloud/android/lib/resources/users/GetRemoteUserQuotaOperation.java b/src/com/owncloud/android/lib/resources/users/GetRemoteUserQuotaOperation.java index 548bc536..b821d3ef 100644 --- a/src/com/owncloud/android/lib/resources/users/GetRemoteUserQuotaOperation.java +++ b/src/com/owncloud/android/lib/resources/users/GetRemoteUserQuotaOperation.java @@ -107,14 +107,14 @@ public class GetRemoteUserQuotaOperation extends RemoteOperation { // Result - result = new RemoteOperationResult(true, status, get.getResponseHeaders()); + result = new RemoteOperationResult(true, get); //Quota data in data collection ArrayList data = new ArrayList(); data.add(new Quota(quotaFree, quotaUsed, quotaTotal, quotaRelative)); result.setData(data); } else { - result = new RemoteOperationResult(false, status, get.getResponseHeaders()); + result = new RemoteOperationResult(false, get); String response = get.getResponseBodyAsString(); Log_OC.e(TAG, "Failed response while getting user quota information "); if (response != null) {