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

Use orcid not userid #67

Merged
merged 2 commits into from
Oct 26, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,17 @@ private Annotation parseToAnnotation(JsonNode response) throws JsonProcessingExc

public JsonApiWrapper updateAnnotation(String id, Annotation annotation, String userId,
String path, String prefix, String suffix) throws NoAnnotationFoundException, ForbiddenException, JsonProcessingException {
var result = repository.getAnnotationForUser(id, userId);
var user = getUserInformation(userId);
var result = repository.getAnnotationForUser(id, user.orcid());
if (result > 0) {
if (annotation.getOdsId() == null) {
annotation.withOdsId(id);
}
var user = getUserInformation(userId);
processAnnotation(annotation, user, true);
var response = annotationClient.updateAnnotation(prefix, suffix, annotation);
return formatResponse(response, path);
} else {
log.info("No active annotation with id: {} found for user: {}", id, userId);
log.info("No active annotation with id: {} found for user {} with orcid {}", id, userId, user.orcid());
throw new NoAnnotationFoundException(
"No active annotation with id: " + id + " was found for user");
}
Expand All @@ -159,7 +159,8 @@ public JsonApiWrapper getAnnotationVersions(String id, String path) throws NotFo
public boolean deleteAnnotation(String prefix, String suffix, String userId)
throws NoAnnotationFoundException {
var id = prefix + "/" + suffix;
var result = repository.getAnnotationForUser(id, userId);
var orcid = userService.getUser(userId).orcid();
var result = repository.getAnnotationForUser(id, orcid);
if (result > 0) {
annotationClient.deleteAnnotation(prefix, suffix);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,8 @@ void testUserHasNoOrcid() {
void testUpdateAnnotation() throws Exception {
// Given
var expected = givenAnnotationResponseSingleDataNode(ANNOTATION_PATH, ORCID);
given(repository.getAnnotationForUser(ID, USER_ID_TOKEN)).willReturn(1);

given(repository.getAnnotationForUser(ID, ORCID)).willReturn(1);
given(userService.getUser(USER_ID_TOKEN)).willReturn(givenUser());
var annotationRequest = givenAnnotationRequest().withOdsId(ID);
var annotationToKafkaRequest = givenAnnotationKafkaRequest(true).withDcTermsCreated(null)
.withOdsId(ID);
Expand All @@ -327,7 +327,8 @@ void testUpdateAnnotation() throws Exception {
@Test
void testUpdateAnnotationDoesNotExist() {
// Given
given(repository.getAnnotationForUser(ID, USER_ID_TOKEN)).willReturn(0);
given(userService.getUser(USER_ID_TOKEN)).willReturn(givenUser());
given(repository.getAnnotationForUser(ID, ORCID)).willReturn(0);

// Then
assertThrowsExactly(NoAnnotationFoundException.class,
Expand Down Expand Up @@ -417,7 +418,8 @@ private JsonNode givenMongoDBAnnotationResponse() throws JsonProcessingException
@Test
void testDeleteAnnotation() throws Exception {
// Given
given(repository.getAnnotationForUser(ID, USER_ID_TOKEN)).willReturn(1);
given(userService.getUser(USER_ID_TOKEN)).willReturn(givenUser());
given(repository.getAnnotationForUser(ID, ORCID)).willReturn(1);

// When
var result = service.deleteAnnotation(PREFIX, SUFFIX, USER_ID_TOKEN);
Expand All @@ -429,7 +431,8 @@ void testDeleteAnnotation() throws Exception {
@Test
void testDeleteAnnotationDoesNotExist() throws Exception {
// Given
given(repository.getAnnotationForUser(ID, USER_ID_TOKEN)).willReturn(0);
given(userService.getUser(USER_ID_TOKEN)).willReturn(givenUser());
given(repository.getAnnotationForUser(ID, ORCID)).willReturn(0);

// Then
assertThrowsExactly(NoAnnotationFoundException.class,
Expand Down
Loading