Skip to content

Commit

Permalink
Merge pull request #14 from nextcloud/quota
Browse files Browse the repository at this point in the history
added quota read to detect limit/unlimited/unknown/not-computed
  • Loading branch information
AndyScherzinger authored Aug 31, 2016
2 parents 0eb972a + 4a680f9 commit 7d2acf4
Showing 1 changed file with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -37,24 +38,29 @@
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;

/**
* Gets a logged in user's quota information (free, used, total and quota).
*
* @author marcello
* @author Andy Scherzinger
*/
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() {
Expand All @@ -69,6 +75,10 @@ public long getTotal() {
return mTotal;
}

public long getQuota() {
return mQuota;
}

public double getRelative() {
return mRelative;
}
Expand All @@ -84,6 +94,21 @@ 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/";

Expand Down Expand Up @@ -114,12 +139,20 @@ protected RemoteOperationResult run(OwnCloudClient client) {
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 = quota.getLong(NODE_QUOTA);
} catch (JSONException e) {
Log_OC.i(TAG, "Legacy server in use < Nextcloud 9.0.54");
quotaValue = SPACE_UNKNOWN;
}

// Result
result = new RemoteOperationResult(true, status, get.getResponseHeaders());

// Quota data in data collection
ArrayList<Object> 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());
Expand Down

0 comments on commit 7d2acf4

Please sign in to comment.