Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DD-1605 Implement several dd-dataverse-cli dataset commands #53

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions lib/src/main/java/nl/knaw/dans/lib/dataverse/DatasetApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,8 @@ public DataverseHttpResponse<DatasetPublicationResult> publish() throws IOExcept

/**
* @param updateType major or minor version update
* @param assureIsIndexed To make sure that indexing has already happened the `assureIsIndexed`
* is set to `true`, it will then cause Dataverse to fail fast if indexing is still pending.
* In this case the publish request will be retried a number of times.
* @param assureIsIndexed To make sure that indexing has already happened the `assureIsIndexed` is set to `true`, it will then cause Dataverse to fail fast if indexing is still pending. In this
* case the publish request will be retried a number of times.
* @return dataset publication result
* @throws IOException when I/O problems occur during the interaction with Dataverse
* @throws DataverseException when Dataverse fails to perform the request
Expand All @@ -155,7 +154,8 @@ public DataverseHttpResponse<DataMessage> publish(UpdateType updateType, boolean
httpClientWrapper.getConfig().getAwaitIndexingMaxNumberOfRetries(),
httpClientWrapper.getConfig().getAwaitIndexingMillisecondsBetweenRetries());
}
else return publishWithoutRetries(updateType, false);
else
return publishWithoutRetries(updateType, false);
}

private DataverseHttpResponse<DataMessage> publishWithoutRetries(UpdateType updateType, boolean assureIsIndexed) throws IOException, DataverseException {
Expand All @@ -172,15 +172,16 @@ private DataverseHttpResponse<DataMessage> publishWithRetriesForAwaitIndexing(Up
while (retryCount < awaitIndexingMaxNumberOfRetries) {
try {
return publishWithoutRetries(updateType, true);
} catch (DataverseException e) {
}
catch (DataverseException e) {
if (e.getStatus() != HttpStatus.SC_CONFLICT) {
log.error("Not an awaiting indexing status {}, rethrowing exception", e.getStatus());
throw e;
}
log.debug("Attempt to publish dataset failed because Dataset is awaiting indexing");
retryCount++;
log.debug("Retry count: {}", retryCount);
if(retryCount == awaitIndexingMaxNumberOfRetries) {
if (retryCount == awaitIndexingMaxNumberOfRetries) {
log.error("Max retries ({}) reached, stop trying to publish dataset", awaitIndexingMaxNumberOfRetries);
throw e;
}
Expand Down Expand Up @@ -446,7 +447,17 @@ public DataverseHttpResponse<RoleAssignmentReadOnly> assignRole(RoleAssignment r
return assignRole(httpClientWrapper.writeValueAsString(roleAssignment));
}

// TODO: https://guides.dataverse.org/en/latest/api/native-api.html#delete-role-assignment-from-a-dataset
/**
* @param roleAssignmentId Delete the assignment with this id
* @return A data information message
* @throws IOException when I/O problems occur during the interaction with Dataverse
* @throws DataverseException when Dataverse fails to perform the request
* @see <a href="https://guides.dataverse.org/en/latest/api/native-api.html#delete-role-assignment-from-a-dataset" target="_blank">Dataverse documentation</a>
*/
public DataverseHttpResponse<DataMessage> deleteRoleAssignment(int roleAssignmentId) throws IOException, DataverseException {
return httpClientWrapper.delete(subPath("assignments/" + roleAssignmentId), params(emptyMap()), DataMessage.class);
}

// TODO: https://guides.dataverse.org/en/latest/api/native-api.html#create-a-private-url-for-a-dataset
// TODO: https://guides.dataverse.org/en/latest/api/native-api.html#get-the-private-url-for-a-dataset
// TODO: https://guides.dataverse.org/en/latest/api/native-api.html#delete-the-private-url-from-a-dataset
Expand Down Expand Up @@ -478,7 +489,6 @@ public DataverseHttpResponse<FileList> addFile(Path file, FileMeta fileMeta) thr
return addFile(file, httpClientWrapper.writeValueAsString(fileMeta));
}


// TODO: https://guides.dataverse.org/en/latest/api/native-api.html#report-the-data-file-size-of-a-dataset
// TODO: https://guides.dataverse.org/en/latest/api/native-api.html#get-the-size-of-downloading-all-the-files-of-a-dataset-version

Expand All @@ -492,7 +502,6 @@ public DataverseHttpResponse<SubmitForReviewResult> submitForReview() throws IOE
return httpClientWrapper.post(subPath("submitForReview"), new StringEntity(""), params(emptyMap()), extraHeaders, SubmitForReviewResult.class);
}


// TODO: https://guides.dataverse.org/en/latest/api/native-api.html#return-a-dataset-to-author
// TODO: https://guides.dataverse.org/en/latest/api/native-api.html#link-a-dataset
// TODO: https://guides.dataverse.org/en/latest/api/native-api.html#dataset-locks
Expand Down
10 changes: 7 additions & 3 deletions lib/src/main/java/nl/knaw/dans/lib/dataverse/DataverseApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,15 @@ public DataverseHttpResponse<DataMessage> assignRole(RoleAssignment roleAssignme
return httpClientWrapper.postModelObjectAsJson(subPath.resolve("assignments"), roleAssignment, new HashMap<>(), new HashMap<>(), DataMessage.class);
}

/* https://guides.dataverse.org/en/latest/api/native-api.html#delete-role-assignment-from-a-dataverse-collection
/**
* @param roleAssignmentId Delete the assignment with this id
* @return A data information message
* @throws IOException when I/O problems occur during the interaction with Dataverse
* @throws DataverseException when Dataverse fails to perform the request
* @see <a href="https://guides.dataverse.org/en/latest/api/native-api.html#delete-role-assignment-from-a-dataverse-collection" target="_blank">Dataverse documentation</a>
*/
public DataverseHttpResponse<DataMessage> deleteRoleAssignment(int roleAssignmentId) throws IOException, DataverseException {
// TODO: implement
throw new UnsupportedOperationException();
return httpClientWrapper.delete(subPath.resolve("assignments/" + roleAssignmentId), DataMessage.class);
}

/**
Expand Down
Loading