Skip to content

Commit bcf5442

Browse files
committed
A quick experiment - adding the remaining quota and/or number of files limit to the /storageDriver API, if present.
1 parent 4c61b5e commit bcf5442

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

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

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
import static jakarta.ws.rs.core.Response.Status.BAD_REQUEST;
111111
import static jakarta.ws.rs.core.Response.Status.NOT_FOUND;
112112
import static jakarta.ws.rs.core.Response.Status.FORBIDDEN;
113+
import java.math.BigDecimal;
113114

114115
@Path("datasets")
115116
public class Datasets extends AbstractApiBean {
@@ -3662,7 +3663,37 @@ public Response getFileStore(@Context ContainerRequestContext crc, @PathParam("i
36623663
return error(Response.Status.NOT_FOUND, "No such dataset");
36633664
}
36643665

3665-
return ok(JsonPrinter.jsonStorageDriver(dataset.getEffectiveStorageDriverId(), dataset));
3666+
JsonObjectBuilder output = JsonPrinter.jsonStorageDriver(dataset.getEffectiveStorageDriverId(), dataset);
3667+
3668+
// Add optional elements - storage size and file count limits, if present:
3669+
3670+
Long storageSizeQuotaRemaining = null;
3671+
3672+
if (systemConfig.isStorageQuotasEnforced()) {
3673+
UploadSessionQuotaLimit uploadSessionQuota = fileService.getUploadSessionQuotaLimit(dataset);
3674+
if (uploadSessionQuota != null) {
3675+
storageSizeQuotaRemaining = uploadSessionQuota.getRemainingQuotaInBytes();
3676+
}
3677+
}
3678+
3679+
Integer numberOfFilesRemaining = null;
3680+
3681+
Integer effectiveFileCountLimit = dataset.getEffectiveDatasetFileCountLimit();
3682+
3683+
if (effectiveFileCountLimit != null) {
3684+
numberOfFilesRemaining = effectiveFileCountLimit - datasetService.getDataFileCountByOwner(dataset.getId());
3685+
}
3686+
3687+
if (storageSizeQuotaRemaining != null) {
3688+
output.add("storageQuotaRemaining", storageSizeQuotaRemaining);
3689+
}
3690+
3691+
if (numberOfFilesRemaining != null) {
3692+
output.add("numberOfFilesRemaining", numberOfFilesRemaining);
3693+
}
3694+
3695+
3696+
return ok(output);
36663697
}
36673698

36683699
@PUT

0 commit comments

Comments
 (0)