Skip to content

Commit 92141d4

Browse files
committed
Some refactoring per suggestions during QA #11987
1 parent 2c7f928 commit 92141d4

8 files changed

Lines changed: 37 additions & 23 deletions

File tree

doc/sphinx-guides/source/admin/dataverses-datasets.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,8 @@ The effective store can be seen using::
271271

272272
curl http://$SERVER/api/datasets/$dataset-id/storageDriver
273273

274+
The output of the API will include the id, label, type (for example, "file" or "s3") as well as the support for direct download and upload.
275+
274276
To remove an assigned store, and allow the dataset to inherit the store from it's parent collection, use the following (only a superuser can do this) ::
275277

276278
curl -H "X-Dataverse-key: $API_TOKEN" -X DELETE http://$SERVER/api/datasets/$dataset-id/storageDriver

src/main/java/edu/harvard/iq/dataverse/DatasetServiceBean.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,7 @@ public int getDataFileCountByOwner(long id) {
11221122

11231123
/**
11241124
*
1125-
* @todo: consider moving the quota methods, from here and the DataverseServiceBean,
1125+
* @todo: consider moving the quota method, from here and the DataverseServiceBean,
11261126
* to DvObjectServiceBean.
11271127
*/
11281128
public void saveStorageQuota(Dataset target, Long allocation) {
@@ -1140,13 +1140,4 @@ public void saveStorageQuota(Dataset target, Long allocation) {
11401140
}
11411141
em.flush();
11421142
}
1143-
1144-
public void disableStorageQuota(StorageQuota storageQuota) {
1145-
if (storageQuota != null && storageQuota.getAllocation() != null) {
1146-
storageQuota.setAllocation(null);
1147-
em.merge(storageQuota);
1148-
em.flush();
1149-
}
1150-
}
1151-
11521143
}

src/main/java/edu/harvard/iq/dataverse/DataverseServiceBean.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1307,7 +1307,12 @@ static String getBaseSchemaStringFromFile(String pathToJsonFile) {
13071307
" },\n" +
13081308
" \"required\": [\"datasetVersion\"]\n" +
13091309
"}\n";
1310-
1310+
1311+
/**
1312+
*
1313+
* @todo: consider moving these quota methods, and the DatasetServiceBean
1314+
* equivalent to DvObjectServiceBean.
1315+
*/
13111316
public void saveStorageQuota(Dataverse target, Long allocation) {
13121317
StorageQuota storageQuota = target.getStorageQuota();
13131318

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6182,11 +6182,17 @@ public Response getDatasetQuota(@Context ContainerRequestContext crc, @PathParam
61826182
}
61836183
}
61846184

6185-
@POST
6185+
@PUT
61866186
@AuthRequired
6187-
@Path("{identifier}/storage/quota/{bytesAllocated}")
6188-
public Response setDatasetQuota(@Context ContainerRequestContext crc, @PathParam("identifier") String dvIdtf, @PathParam("bytesAllocated") Long bytesAllocated) throws WrappedResponse {
6187+
@Path("{identifier}/storage/quota")
6188+
public Response setDatasetQuota(@Context ContainerRequestContext crc, @PathParam("identifier") String dvIdtf, String value) throws WrappedResponse {
61896189
try {
6190+
Long bytesAllocated;
6191+
try {
6192+
bytesAllocated = Long.parseLong(value);
6193+
} catch (NumberFormatException nfe){
6194+
return error(Status.BAD_REQUEST, value + " is not a valid number of bytes");
6195+
}
61906196
execCommand(new SetDatasetQuotaCommand(createDataverseRequest(getRequestUser(crc)), findDatasetOrDie(dvIdtf), bytesAllocated));
61916197
return ok(BundleUtil.getStringFromBundle("dataset.storage.quota.updated"));
61926198
} catch (WrappedResponse ex) {

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,11 +1248,17 @@ public Response getCollectionQuota(@Context ContainerRequestContext crc, @PathPa
12481248
}
12491249
}
12501250

1251-
@POST
1251+
@PUT
12521252
@AuthRequired
1253-
@Path("{identifier}/storage/quota/{bytesAllocated}")
1254-
public Response setCollectionQuota(@Context ContainerRequestContext crc, @PathParam("identifier") String dvIdtf, @PathParam("bytesAllocated") Long bytesAllocated) throws WrappedResponse {
1253+
@Path("{identifier}/storage/quota")
1254+
public Response setCollectionQuota(@Context ContainerRequestContext crc, @PathParam("identifier") String dvIdtf, String value) throws WrappedResponse {
12551255
try {
1256+
Long bytesAllocated;
1257+
try {
1258+
bytesAllocated = Long.parseLong(value);
1259+
} catch (NumberFormatException nfe){
1260+
return error(Status.BAD_REQUEST, value + " is not a valid number of bytes");
1261+
}
12561262
execCommand(new SetCollectionQuotaCommand(createDataverseRequest(getRequestUser(crc)), findDataverseOrDie(dvIdtf), bytesAllocated));
12571263
return ok(BundleUtil.getStringFromBundle("dataverse.storage.quota.updated"));
12581264
} catch (WrappedResponse ex) {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public void executeImpl(CommandContext ctxt) throws CommandException {
4848
if (storageQuota != null && storageQuota.getAllocation() != null) {
4949
// The method below, in dataverseServiceBean, can be used to delete
5050
// quotas defined on either of the DvObjectContainer classes:
51+
targetDataset.setStorageQuota(null);
52+
storageQuota.setDefinitionPoint(null);
5153
ctxt.dataverses().disableStorageQuota(storageQuota);
5254
}
5355
// ... and if no quota was enabled on the dataset - nothing to do = success

src/test/java/edu/harvard/iq/dataverse/api/FilesIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3278,7 +3278,7 @@ public void testCollectionStorageQuotas() {
32783278
assertEquals(BundleUtil.getStringFromBundle("dataverse.storage.quota.notdefined"), JsonPath.from(checkQuotaResponse.body().asString()).getString("data.message"));
32793279

32803280
// Set quota to 1K:
3281-
Response setQuotaResponse = UtilIT.setCollectionQuota(dataverseAlias, 1024, apiToken);
3281+
Response setQuotaResponse = UtilIT.setCollectionQuota(dataverseAlias, Long.valueOf(1024), apiToken);
32823282
setQuotaResponse.then().assertThat().statusCode(OK.getStatusCode());
32833283
assertEquals(BundleUtil.getStringFromBundle("dataverse.storage.quota.updated"), JsonPath.from(setQuotaResponse.body().asString()).getString("data.message"));
32843284

@@ -3402,7 +3402,7 @@ public void testDatasetStorageQuotas() {
34023402
assertEquals(BundleUtil.getStringFromBundle("dataset.storage.quota.notdefined"), JsonPath.from(checkQuotaResponse.body().asString()).getString("data.message"));
34033403

34043404
// Set quota to 1K:
3405-
Response setQuotaResponse = UtilIT.setDatasetQuota(datasetId.toString(), 1024, apiToken);
3405+
Response setQuotaResponse = UtilIT.setDatasetQuota(datasetId.toString(), Long.valueOf(1024), apiToken);
34063406
setQuotaResponse.then().assertThat().statusCode(OK.getStatusCode());
34073407
assertEquals(BundleUtil.getStringFromBundle("dataset.storage.quota.updated"), JsonPath.from(setQuotaResponse.body().asString()).getString("data.message"));
34083408

src/test/java/edu/harvard/iq/dataverse/api/UtilIT.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3689,10 +3689,11 @@ static Response checkCollectionQuota(String collectionId, String apiToken) {
36893689
.get("/api/dataverses/" + collectionId + "/storage/quota");
36903690
}
36913691

3692-
static Response setCollectionQuota(String collectionId, long allocatedSize, String apiToken) {
3692+
static Response setCollectionQuota(String collectionId, Long allocatedSize, String apiToken) {
36933693
Response response = given()
36943694
.header(API_TOKEN_HTTP_HEADER, apiToken)
3695-
.post("/api/dataverses/" + collectionId + "/storage/quota/" + allocatedSize);
3695+
.body(allocatedSize.toString())
3696+
.put("/api/dataverses/" + collectionId + "/storage/quota");
36963697
return response;
36973698
}
36983699

@@ -3715,10 +3716,11 @@ static Response checkDatasetQuota(String datasetId, String apiToken) {
37153716
.get("/api/datasets/" + datasetId + "/storage/quota");
37163717
}
37173718

3718-
static Response setDatasetQuota(String datasetId, long allocatedSize, String apiToken) {
3719+
static Response setDatasetQuota(String datasetId, Long allocatedSize, String apiToken) {
37193720
Response response = given()
37203721
.header(API_TOKEN_HTTP_HEADER, apiToken)
3721-
.post("/api/datasets/" + datasetId + "/storage/quota/" + allocatedSize);
3722+
.body(allocatedSize.toString())
3723+
.put("/api/datasets/" + datasetId + "/storage/quota");
37223724
return response;
37233725
}
37243726

0 commit comments

Comments
 (0)