From 25bba85ee1026c3801c0573f9c0a82ac713f2d7a Mon Sep 17 00:00:00 2001 From: davigonz Date: Wed, 6 Jun 2018 13:20:12 +0200 Subject: [PATCH] Implement get quota with new architecture and refactoring --- .../android/lib/common/OwnCloudClient.java | 2 +- .../{methods => http}/HttpBaseMethod.java | 2 +- .../lib/common/http/HttpConstants.java | 126 ++++++++++++++++++ .../nonwebdav/GetMethod.java | 3 +- .../nonwebdav/HttpMethod.java | 4 +- .../{methods => http}/webdav/DavMethod.java | 4 +- .../webdav/PropfindMethod.java | 6 +- .../files/ExistenceCheckRemoteOperation.java | 2 +- .../users/GetRemoteUserInfoOperation.java | 8 +- .../users/GetRemoteUserQuotaOperation.java | 2 +- 10 files changed, 139 insertions(+), 20 deletions(-) rename src/com/owncloud/android/lib/common/{methods => http}/HttpBaseMethod.java (87%) create mode 100644 src/com/owncloud/android/lib/common/http/HttpConstants.java rename src/com/owncloud/android/lib/common/{methods => http}/nonwebdav/GetMethod.java (86%) rename src/com/owncloud/android/lib/common/{methods => http}/nonwebdav/HttpMethod.java (74%) rename src/com/owncloud/android/lib/common/{methods => http}/webdav/DavMethod.java (79%) rename src/com/owncloud/android/lib/common/{methods => http}/webdav/PropfindMethod.java (87%) diff --git a/src/com/owncloud/android/lib/common/OwnCloudClient.java b/src/com/owncloud/android/lib/common/OwnCloudClient.java index ece9f228..901261f9 100644 --- a/src/com/owncloud/android/lib/common/OwnCloudClient.java +++ b/src/com/owncloud/android/lib/common/OwnCloudClient.java @@ -35,7 +35,7 @@ import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory.OwnCloudAnonymousCredentials; import com.owncloud.android.lib.common.interceptors.HttpInterceptor; import com.owncloud.android.lib.common.interceptors.UserAgentInterceptor; -import com.owncloud.android.lib.common.methods.HttpBaseMethod; +import com.owncloud.android.lib.common.http.HttpBaseMethod; import com.owncloud.android.lib.common.network.RedirectionPath; import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.resources.status.OwnCloudVersion; diff --git a/src/com/owncloud/android/lib/common/methods/HttpBaseMethod.java b/src/com/owncloud/android/lib/common/http/HttpBaseMethod.java similarity index 87% rename from src/com/owncloud/android/lib/common/methods/HttpBaseMethod.java rename to src/com/owncloud/android/lib/common/http/HttpBaseMethod.java index cac3c62c..224e5eba 100644 --- a/src/com/owncloud/android/lib/common/methods/HttpBaseMethod.java +++ b/src/com/owncloud/android/lib/common/http/HttpBaseMethod.java @@ -1,4 +1,4 @@ -package com.owncloud.android.lib.common.methods; +package com.owncloud.android.lib.common.http; import okhttp3.Request; import okhttp3.Response; diff --git a/src/com/owncloud/android/lib/common/http/HttpConstants.java b/src/com/owncloud/android/lib/common/http/HttpConstants.java new file mode 100644 index 00000000..b1235f86 --- /dev/null +++ b/src/com/owncloud/android/lib/common/http/HttpConstants.java @@ -0,0 +1,126 @@ +package com.owncloud.android.lib.common.http; + +public class HttpConstants { + + /** + * 1xx Informational + */ + + // 100 Continue (HTTP/1.1 - RFC 2616) + public static final int HTTP_CONTINUE = 100; + // 101 Switching Protocols (HTTP/1.1 - RFC 2616) + public static final int HTTP_SWITCHING_PROTOCOLS = 101; + // 102 Processing (WebDAV - RFC 2518) + public static final int HTTP_PROCESSING = 102; + + /** + * 2xx Success + */ + + // 200 OK (HTTP/1.0 - RFC 1945) + public static final int HTTP_OK = 200; + // 201 Created (HTTP/1.0 - RFC 1945) + public static final int HTTP_CREATED = 201; + // 202 Accepted (HTTP/1.0 - RFC 1945) + public static final int HTTP_ACCEPTED = 202; + // 203 Non Authoritative Information (HTTP/1.1 - RFC 2616) + public static final int HTTP_NON_AUTHORITATIVE_INFORMATION = 203; + // 204 No Content (HTTP/1.0 - RFC 1945) + public static final int HTTP_NO_CONTENT = 204; + // 205 Reset Content (HTTP/1.1 - RFC 2616) + public static final int HTTP_RESET_CONTENT = 205; + // 206 Partial Content (HTTP/1.1 - RFC 2616) + public static final int HTTP_PARTIAL_CONTENT = 206; + //207 Multi-Status (WebDAV - RFC 2518) or 207 Partial Update OK (HTTP/1.1 - draft-ietf-http-v11-spec-rev-01?) + public static final int HTTP_MULTI_STATUS = 207; + + /** + * 3xx Redirection + */ + + // 300 Mutliple Choices (HTTP/1.1 - RFC 2616) + public static final int HTTP_MULTIPLE_CHOICES = 300; + // 301 Moved Permanently (HTTP/1.0 - RFC 1945) + public static final int HTTP_MOVED_PERMANENTLY = 301; + // 302 Moved Temporarily (Sometimes Found) (HTTP/1.0 - RFC 1945) + public static final int HTTP_MOVED_TEMPORARILY = 302; + // 303 See Other (HTTP/1.1 - RFC 2616) + public static final int HTTP_SEE_OTHER = 303; + // 304 Not Modified (HTTP/1.0 - RFC 1945) + public static final int HTTP_NOT_MODIFIED = 304; + // 305 Use Proxy (HTTP/1.1 - RFC 2616) + public static final int HTTP_USE_PROXY = 305; + // 307 Temporary Redirect (HTTP/1.1 - RFC 2616) + public static final int HTTP_TEMPORARY_REDIRECT = 307; + + /** + * 4xx Client Error + */ + + // 400 Bad Request (HTTP/1.1 - RFC 2616) + public static final int HTTP_BAD_REQUEST = 400; + // 401 Unauthorized (HTTP/1.0 - RFC 1945) + public static final int HTTP_UNAUTHORIZED = 401; + // 402 Payment Required (HTTP/1.1 - RFC 2616) + public static final int HTTP_PAYMENT_REQUIRED = 402; + // 403 Forbidden (HTTP/1.0 - RFC 1945) + public static final int HTTP_FORBIDDEN = 403; + // 404 Not Found (HTTP/1.0 - RFC 1945) + public static final int HTTP_NOT_FOUND = 404; + // 405 Method Not Allowed (HTTP/1.1 - RFC 2616) + public static final int HTTP_METHOD_NOT_ALLOWED = 405; + // 406 Not Acceptable (HTTP/1.1 - RFC 2616) + public static final int HTTP_NOT_ACCEPTABLE = 406; + // 407 Proxy Authentication Required (HTTP/1.1 - RFC 2616) + public static final int HTTP_PROXY_AUTHENTICATION_REQUIRED = 407; + // 408 Request Timeout (HTTP/1.1 - RFC 2616) + public static final int HTTP_REQUEST_TIMEOUT = 408; + // 409 Conflict (HTTP/1.1 - RFC 2616) + public static final int HTTP_CONFLICT = 409; + // 410 Gone (HTTP/1.1 - RFC 2616) + public static final int HTTP_GONE = 410; + // 411 Length Required (HTTP/1.1 - RFC 2616) + public static final int HTTP_LENGTH_REQUIRED = 411; + // 412 Precondition Failed (HTTP/1.1 - RFC 2616) + public static final int HTTP_PRECONDITION_FAILED = 412; + // 413 Request Entity Too Large (HTTP/1.1 - RFC 2616) + public static final int HTTP_REQUEST_TOO_LONG = 413; + // 414 Request-URI Too Long (HTTP/1.1 - RFC 2616) + public static final int HTTP_REQUEST_URI_TOO_LONG = 414; + // 415 Unsupported Media Type (HTTP/1.1 - RFC 2616) + public static final int HTTP_UNSUPPORTED_MEDIA_TYPE = 415; + // 416 Requested Range Not Satisfiable (HTTP/1.1 - RFC 2616) + public static final int HTTP_REQUESTED_RANGE_NOT_SATISFIABLE = 416; + // 417 Expectation Failed (HTTP/1.1 - RFC 2616) + public static final int HTTP_EXPECTATION_FAILED = 417; + // 419 Insufficient Space on Resource (WebDAV - draft-ietf-webdav-protocol-05?) + // or 419 Proxy Reauthentication Required (HTTP/1.1 drafts?) + public static final int HTTP_INSUFFICIENT_SPACE_ON_RESOURCE = 419; + // 420 Method Failure (WebDAV - draft-ietf-webdav-protocol-05?) + public static final int HTTP_METHOD_FAILURE = 420; + // 422 Unprocessable Entity (WebDAV - RFC 2518) + public static final int HTTP_UNPROCESSABLE_ENTITY = 422; + // 423 Locked (WebDAV - RFC 2518) + public static final int HTTP_LOCKED = 423; + // 424 Failed Dependency (WebDAV - RFC 2518) + public static final int HTTP_FAILED_DEPENDENCY = 424; + + /** + * 5xx Client Error + */ + + // 500 Server Error (HTTP/1.0 - RFC 1945) + public static final int HTTP_INTERNAL_SERVER_ERROR = 500; + // 501 Not Implemented (HTTP/1.0 - RFC 1945) + public static final int HTTP_NOT_IMPLEMENTED = 501; + // 502 Bad Gateway (HTTP/1.0 - RFC 1945) + public static final int HTTP_BAD_GATEWAY = 502; + // 503 Service Unavailable (HTTP/1.0 - RFC 1945) + public static final int HTTP_SERVICE_UNAVAILABLE = 503; + // 504 Gateway Timeout (HTTP/1.1 - RFC 2616) + public static final int HTTP_GATEWAY_TIMEOUT = 504; + // 505 HTTP Version Not Supported (HTTP/1.1 - RFC 2616) + public static final int HTTP_HTTP_VERSION_NOT_SUPPORTED = 505; + // 507 Insufficient Storage (WebDAV - RFC 2518) + public static final int HTTP_INSUFFICIENT_STORAGE = 507; +} \ No newline at end of file diff --git a/src/com/owncloud/android/lib/common/methods/nonwebdav/GetMethod.java b/src/com/owncloud/android/lib/common/http/nonwebdav/GetMethod.java similarity index 86% rename from src/com/owncloud/android/lib/common/methods/nonwebdav/GetMethod.java rename to src/com/owncloud/android/lib/common/http/nonwebdav/GetMethod.java index 6a297764..385582b6 100644 --- a/src/com/owncloud/android/lib/common/methods/nonwebdav/GetMethod.java +++ b/src/com/owncloud/android/lib/common/http/nonwebdav/GetMethod.java @@ -1,10 +1,9 @@ -package com.owncloud.android.lib.common.methods.nonwebdav; +package com.owncloud.android.lib.common.http.nonwebdav; import java.io.IOException; import okhttp3.OkHttpClient; import okhttp3.Request; -import okhttp3.Response; public class GetMethod extends HttpMethod { diff --git a/src/com/owncloud/android/lib/common/methods/nonwebdav/HttpMethod.java b/src/com/owncloud/android/lib/common/http/nonwebdav/HttpMethod.java similarity index 74% rename from src/com/owncloud/android/lib/common/methods/nonwebdav/HttpMethod.java rename to src/com/owncloud/android/lib/common/http/nonwebdav/HttpMethod.java index 4c6f5e2c..79640bcf 100644 --- a/src/com/owncloud/android/lib/common/methods/nonwebdav/HttpMethod.java +++ b/src/com/owncloud/android/lib/common/http/nonwebdav/HttpMethod.java @@ -1,6 +1,6 @@ -package com.owncloud.android.lib.common.methods.nonwebdav; +package com.owncloud.android.lib.common.http.nonwebdav; -import com.owncloud.android.lib.common.methods.HttpBaseMethod; +import com.owncloud.android.lib.common.http.HttpBaseMethod; import okhttp3.OkHttpClient; import okhttp3.Request; diff --git a/src/com/owncloud/android/lib/common/methods/webdav/DavMethod.java b/src/com/owncloud/android/lib/common/http/webdav/DavMethod.java similarity index 79% rename from src/com/owncloud/android/lib/common/methods/webdav/DavMethod.java rename to src/com/owncloud/android/lib/common/http/webdav/DavMethod.java index 09d87d5d..ba142d4f 100644 --- a/src/com/owncloud/android/lib/common/methods/webdav/DavMethod.java +++ b/src/com/owncloud/android/lib/common/http/webdav/DavMethod.java @@ -1,6 +1,6 @@ -package com.owncloud.android.lib.common.methods.webdav; +package com.owncloud.android.lib.common.http.webdav; -import com.owncloud.android.lib.common.methods.HttpBaseMethod; +import com.owncloud.android.lib.common.http.HttpBaseMethod; import at.bitfire.dav4android.DavOCResource; import at.bitfire.dav4android.DavResource; diff --git a/src/com/owncloud/android/lib/common/methods/webdav/PropfindMethod.java b/src/com/owncloud/android/lib/common/http/webdav/PropfindMethod.java similarity index 87% rename from src/com/owncloud/android/lib/common/methods/webdav/PropfindMethod.java rename to src/com/owncloud/android/lib/common/http/webdav/PropfindMethod.java index a21cc494..c90401a8 100644 --- a/src/com/owncloud/android/lib/common/methods/webdav/PropfindMethod.java +++ b/src/com/owncloud/android/lib/common/http/webdav/PropfindMethod.java @@ -1,12 +1,8 @@ -package com.owncloud.android.lib.common.methods.webdav; - -import com.owncloud.android.lib.common.network.WebdavUtils; +package com.owncloud.android.lib.common.http.webdav; import java.io.IOException; -import java.util.ArrayList; import java.util.Set; -import at.bitfire.dav4android.DavOCResource; import at.bitfire.dav4android.DavResource; import at.bitfire.dav4android.PropertyUtils; import at.bitfire.dav4android.exception.DavException; diff --git a/src/com/owncloud/android/lib/resources/files/ExistenceCheckRemoteOperation.java b/src/com/owncloud/android/lib/resources/files/ExistenceCheckRemoteOperation.java index 1dd82b22..8c905305 100644 --- a/src/com/owncloud/android/lib/resources/files/ExistenceCheckRemoteOperation.java +++ b/src/com/owncloud/android/lib/resources/files/ExistenceCheckRemoteOperation.java @@ -25,7 +25,7 @@ package com.owncloud.android.lib.resources.files; import com.owncloud.android.lib.common.OwnCloudClient; -import com.owncloud.android.lib.common.methods.webdav.PropfindMethod; +import com.owncloud.android.lib.common.http.webdav.PropfindMethod; import com.owncloud.android.lib.common.network.RedirectionPath; import com.owncloud.android.lib.common.network.WebdavUtils; import com.owncloud.android.lib.common.operations.RemoteOperation; diff --git a/src/com/owncloud/android/lib/resources/users/GetRemoteUserInfoOperation.java b/src/com/owncloud/android/lib/resources/users/GetRemoteUserInfoOperation.java index 987c29dc..f906a346 100644 --- a/src/com/owncloud/android/lib/resources/users/GetRemoteUserInfoOperation.java +++ b/src/com/owncloud/android/lib/resources/users/GetRemoteUserInfoOperation.java @@ -25,15 +25,13 @@ package com.owncloud.android.lib.resources.users; import java.util.ArrayList; - -import org.apache.commons.httpclient.HttpStatus; import org.json.JSONObject; - import com.owncloud.android.lib.common.OwnCloudClient; +import com.owncloud.android.lib.common.http.HttpConstants; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.utils.Log_OC; -import com.owncloud.android.lib.common.methods.nonwebdav.GetMethod; +import com.owncloud.android.lib.common.http.nonwebdav.GetMethod; import okhttp3.Request; @@ -116,7 +114,7 @@ public class GetRemoteUserInfoOperation extends RemoteOperation { } private boolean isSuccess(int status) { - return (status == HttpStatus.SC_OK); + return (status == HttpConstants.HTTP_OK); } public static class UserInfo { diff --git a/src/com/owncloud/android/lib/resources/users/GetRemoteUserQuotaOperation.java b/src/com/owncloud/android/lib/resources/users/GetRemoteUserQuotaOperation.java index 2109efb4..0ae91a43 100644 --- a/src/com/owncloud/android/lib/resources/users/GetRemoteUserQuotaOperation.java +++ b/src/com/owncloud/android/lib/resources/users/GetRemoteUserQuotaOperation.java @@ -188,4 +188,4 @@ public class GetRemoteUserQuotaOperation extends RemoteOperation { ); } } -} +} \ No newline at end of file