Skip to content

Commit 4337c47

Browse files
committed
Added an optional parameter to the quota APIs to show the quota that may be inherited from a parent collection. #11987
1 parent 388af25 commit 4337c47

File tree

5 files changed

+41
-13
lines changed

5 files changed

+41
-13
lines changed

doc/sphinx-guides/source/api/native-api.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,7 +1250,8 @@ Collection Storage Quotas
12501250
12511251
curl -H "X-Dataverse-key:$API_TOKEN" "$SERVER_URL/api/dataverses/$ID/storage/quota"
12521252
1253-
Will output the storage quota allocated (in bytes), or a message indicating that the quota is not defined for the specific collection. The user identified by the API token must have the ``Edit`` permission on the collection.
1253+
Will output the storage quota allocated (in bytes), or a message indicating that the quota is not defined for the collection. The user identified by the API token must have the ``Edit`` permission on the collection.
1254+
With an optional query parameter ``showInherited=true`` it will show the applicable quota potentially defined on the nearest parent when the collection does not have a quota configured directly.
12541255

12551256
.. code-block::
12561257
@@ -1282,7 +1283,8 @@ Storage Quotas on Individual Datasets
12821283
12831284
curl -H "X-Dataverse-key:$API_TOKEN" "$SERVER_URL/api/datasets/$ID/storage/quota"
12841285
1285-
Will output the storage quota allocated (in bytes), or a message indicating that the quota is not defined for the specific collection. The user identified by the API token must have the ``Edit`` permission on the dataset.
1286+
Will output the storage quota allocated (in bytes), or a message indicating that the quota is not defined for this dataset. The user identified by the API token must have the ``Edit`` permission on the dataset.
1287+
With an optional query parameter ``showInherited=true`` it will show the applicable quota potentially defined on the nearest parent collection when the dataset does not have a quota configured directly.
12861288

12871289
.. code-block::
12881290

src/main/java/edu/harvard/iq/dataverse/api/Datasets.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6170,9 +6170,9 @@ public Response updateLicense(@Context ContainerRequestContext crc,
61706170
@GET
61716171
@AuthRequired
61726172
@Path("{identifier}/storage/quota")
6173-
public Response getDatasetQuota(@Context ContainerRequestContext crc, @PathParam("identifier") String dvIdtf) throws WrappedResponse {
6173+
public Response getDatasetQuota(@Context ContainerRequestContext crc, @PathParam("identifier") String dvIdtf, @QueryParam("showInherited") boolean showInherited) throws WrappedResponse {
61746174
try {
6175-
Long bytesAllocated = execCommand(new GetDatasetQuotaCommand(createDataverseRequest(getRequestUser(crc)), findDatasetOrDie(dvIdtf)));
6175+
Long bytesAllocated = execCommand(new GetDatasetQuotaCommand(createDataverseRequest(getRequestUser(crc)), findDatasetOrDie(dvIdtf), showInherited));
61766176
if (bytesAllocated != null) {
61776177
return ok(MessageFormat.format(BundleUtil.getStringFromBundle("dataset.storage.quota.allocation"),bytesAllocated));
61786178
}

src/main/java/edu/harvard/iq/dataverse/api/Dataverses.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,9 +1236,9 @@ public Response getStorageSize(@Context ContainerRequestContext crc, @PathParam(
12361236
@GET
12371237
@AuthRequired
12381238
@Path("{identifier}/storage/quota")
1239-
public Response getCollectionQuota(@Context ContainerRequestContext crc, @PathParam("identifier") String dvIdtf) throws WrappedResponse {
1239+
public Response getCollectionQuota(@Context ContainerRequestContext crc, @PathParam("identifier") String dvIdtf, @QueryParam("showInherited") boolean showInherited) throws WrappedResponse {
12401240
try {
1241-
Long bytesAllocated = execCommand(new GetCollectionQuotaCommand(createDataverseRequest(getRequestUser(crc)), findDataverseOrDie(dvIdtf)));
1241+
Long bytesAllocated = execCommand(new GetCollectionQuotaCommand(createDataverseRequest(getRequestUser(crc)), findDataverseOrDie(dvIdtf), showInherited));
12421242
if (bytesAllocated != null) {
12431243
return ok(MessageFormat.format(BundleUtil.getStringFromBundle("dataverse.storage.quota.allocation"),bytesAllocated));
12441244
}

src/main/java/edu/harvard/iq/dataverse/engine/command/impl/GetCollectionQuotaCommand.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,30 @@ public class GetCollectionQuotaCommand extends AbstractCommand<Long> {
2323
private static final Logger logger = Logger.getLogger(GetCollectionQuotaCommand.class.getCanonicalName());
2424

2525
private final Dataverse dataverse;
26+
private final boolean inherited;
2627

27-
public GetCollectionQuotaCommand(DataverseRequest aRequest, Dataverse target) {
28+
public GetCollectionQuotaCommand(DataverseRequest aRequest, Dataverse target, boolean inherited) {
2829
super(aRequest, target);
2930
dataverse = target;
31+
this.inherited = inherited;
3032
}
3133

3234
@Override
3335
public Long execute(CommandContext ctxt) throws CommandException {
3436

35-
if (dataverse != null && dataverse.getStorageQuota() != null) {
36-
return dataverse.getStorageQuota().getAllocation();
37+
if (dataverse != null) {
38+
39+
if (dataverse.getStorageQuota() != null) {
40+
return dataverse.getStorageQuota().getAllocation();
41+
} else if (inherited) {
42+
Dataverse uptree = dataverse;
43+
while (uptree.getStorageQuota() == null && uptree.getOwner() != null) {
44+
uptree = uptree.getOwner();
45+
if (uptree.getStorageQuota() != null) {
46+
return uptree.getStorageQuota().getAllocation();
47+
}
48+
}
49+
}
3750
}
3851

3952
return null;

src/main/java/edu/harvard/iq/dataverse/engine/command/impl/GetDatasetQuotaCommand.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package edu.harvard.iq.dataverse.engine.command.impl;
22

33
import edu.harvard.iq.dataverse.Dataset;
4+
import edu.harvard.iq.dataverse.DvObjectContainer;
45
import edu.harvard.iq.dataverse.authorization.Permission;
56
import edu.harvard.iq.dataverse.engine.command.AbstractCommand;
67
import edu.harvard.iq.dataverse.engine.command.CommandContext;
@@ -23,19 +24,31 @@ public class GetDatasetQuotaCommand extends AbstractCommand<Long> {
2324
private static final Logger logger = Logger.getLogger(GetDatasetQuotaCommand.class.getCanonicalName());
2425

2526
private final Dataset dataset;
27+
private final boolean inherited;
2628

27-
public GetDatasetQuotaCommand(DataverseRequest aRequest, Dataset target) {
29+
public GetDatasetQuotaCommand(DataverseRequest aRequest, Dataset target, boolean inherited) {
2830
super(aRequest, target);
2931
dataset = target;
32+
this.inherited = inherited;
3033
}
3134

3235
@Override
3336
public Long execute(CommandContext ctxt) throws CommandException {
3437

35-
if (dataset != null && dataset.getStorageQuota() != null) {
36-
return dataset.getStorageQuota().getAllocation();
38+
if (dataset != null) {
39+
if (dataset.getStorageQuota() != null) {
40+
return dataset.getStorageQuota().getAllocation();
41+
} else if (inherited) {
42+
DvObjectContainer uptree = dataset;
43+
while (uptree.getStorageQuota() == null && uptree.getOwner() != null) {
44+
uptree = uptree.getOwner();
45+
if (uptree.getStorageQuota() != null) {
46+
return uptree.getStorageQuota().getAllocation();
47+
}
48+
}
49+
}
3750
}
38-
51+
3952
return null;
4053
}
4154

0 commit comments

Comments
 (0)