From 7a3bfbde5519d8912c63bb92cccca8d426df5e1e Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Wed, 31 Aug 2016 00:48:57 +0200 Subject: [PATCH 1/2] added quota read to detect limit/unlimited/unknown/not-computed --- .../users/RemoteGetUserQuotaOperation.java | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/com/owncloud/android/lib/resources/users/RemoteGetUserQuotaOperation.java b/src/com/owncloud/android/lib/resources/users/RemoteGetUserQuotaOperation.java index 379c1af4d..dc54a54b2 100644 --- a/src/com/owncloud/android/lib/resources/users/RemoteGetUserQuotaOperation.java +++ b/src/com/owncloud/android/lib/resources/users/RemoteGetUserQuotaOperation.java @@ -37,6 +37,7 @@ import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.NameValuePair; import org.apache.commons.httpclient.methods.GetMethod; +import org.json.JSONException; import org.json.JSONObject; import java.util.ArrayList; @@ -47,14 +48,15 @@ public class RemoteGetUserQuotaOperation extends RemoteOperation { static public class Quota { - private long mFree, mUsed, mTotal; + private long mFree, mUsed, mTotal, mQuota; private double mRelative; - public Quota(long free, long used, long total, double relative) { + public Quota(long free, long used, long total, double relative, long quota) { mFree = free; mUsed = used; mTotal = total; mRelative = relative; + mQuota = quota; } public long getFree() { @@ -69,6 +71,10 @@ public long getTotal() { return mTotal; } + public long getQuota() { + return mQuota; + } + public double getRelative() { return mRelative; } @@ -84,6 +90,15 @@ public double getRelative() { private static final String NODE_QUOTA_TOTAL = "total"; private static final String NODE_QUOTA_RELATIVE = "relative"; + /** Quota return value for a not computed space value. */ + public static final long SPACE_NOT_COMPUTED = -1; + + /** Quota return value for unknown space value. */ + public static final long SPACE_UNKNOWN = -2; + + /** Quota return value for unlimited space. */ + public static final long SPACE_UNLIMITED = -3; + // OCS Route private static final String OCS_ROUTE = "/ocs/v1.php/cloud/users/"; @@ -113,13 +128,20 @@ protected RemoteOperationResult run(OwnCloudClient client) { final Long quotaFree = quota.getLong(NODE_QUOTA_FREE); final Long quotaUsed = quota.getLong(NODE_QUOTA_USED); final Long quotaTotal = quota.getLong(NODE_QUOTA_TOTAL); + Long quotaValue; + try { + quotaValue = Long.valueOf(quota.getLong(NODE_QUOTA)); + } catch (JSONException e) { + // quota value only present in NC 9.0.54+ + quotaValue = SPACE_UNKNOWN; + } final Double quotaRelative = quota.getDouble(NODE_QUOTA_RELATIVE); // Result result = new RemoteOperationResult(true, status, get.getResponseHeaders()); // Quota data in data collection ArrayList data = new ArrayList<>(); - data.add(new Quota(quotaFree, quotaUsed, quotaTotal, quotaRelative)); + data.add(new Quota(quotaFree, quotaUsed, quotaTotal, quotaRelative, quotaValue)); result.setData(data); } else { result = new RemoteOperationResult(false, status, get.getResponseHeaders()); From 4a680f9364fb3fdb0b9f7423c3b376c58a81c1a9 Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Wed, 31 Aug 2016 15:05:22 +0200 Subject: [PATCH 2/2] slight reformatting of code + logging in case of fallback due to missing server side feature support --- .../users/RemoteGetUserQuotaOperation.java | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/com/owncloud/android/lib/resources/users/RemoteGetUserQuotaOperation.java b/src/com/owncloud/android/lib/resources/users/RemoteGetUserQuotaOperation.java index dc54a54b2..7952ffd01 100644 --- a/src/com/owncloud/android/lib/resources/users/RemoteGetUserQuotaOperation.java +++ b/src/com/owncloud/android/lib/resources/users/RemoteGetUserQuotaOperation.java @@ -1,6 +1,7 @@ /* Nextcloud Android Library is available under MIT license * * Copyright (C) 2016 Nextcloud + * Copyright (C) 2016 Andy Scherzinger * Copyright (C) 2015 ownCloud Inc. * Copyright (C) 2015 Bartosz Przybylski * Copyright (C) 2014 Marcello Steiner @@ -43,7 +44,10 @@ import java.util.ArrayList; /** + * Gets a logged in user's quota information (free, used, total and quota). + * * @author marcello + * @author Andy Scherzinger */ public class RemoteGetUserQuotaOperation extends RemoteOperation { @@ -90,14 +94,20 @@ public double getRelative() { private static final String NODE_QUOTA_TOTAL = "total"; private static final String NODE_QUOTA_RELATIVE = "relative"; - /** Quota return value for a not computed space value. */ + /** + * Quota return value for a not computed space value. + */ public static final long SPACE_NOT_COMPUTED = -1; - /** Quota return value for unknown space value. */ - public static final long SPACE_UNKNOWN = -2; + /** + * Quota return value for unknown space value. + */ + public static final long SPACE_UNKNOWN = -2; - /** Quota return value for unlimited space. */ - public static final long SPACE_UNLIMITED = -3; + /** + * Quota return value for unlimited space. + */ + public static final long SPACE_UNLIMITED = -3; // OCS Route private static final String OCS_ROUTE = "/ocs/v1.php/cloud/users/"; @@ -128,17 +138,18 @@ protected RemoteOperationResult run(OwnCloudClient client) { final Long quotaFree = quota.getLong(NODE_QUOTA_FREE); final Long quotaUsed = quota.getLong(NODE_QUOTA_USED); final Long quotaTotal = quota.getLong(NODE_QUOTA_TOTAL); + final Double quotaRelative = quota.getDouble(NODE_QUOTA_RELATIVE); Long quotaValue; try { - quotaValue = Long.valueOf(quota.getLong(NODE_QUOTA)); + quotaValue = quota.getLong(NODE_QUOTA); } catch (JSONException e) { - // quota value only present in NC 9.0.54+ + Log_OC.i(TAG, "Legacy server in use < Nextcloud 9.0.54"); quotaValue = SPACE_UNKNOWN; } - final Double quotaRelative = quota.getDouble(NODE_QUOTA_RELATIVE); // Result result = new RemoteOperationResult(true, status, get.getResponseHeaders()); + // Quota data in data collection ArrayList data = new ArrayList<>(); data.add(new Quota(quotaFree, quotaUsed, quotaTotal, quotaRelative, quotaValue));