Skip to content

Commit

Permalink
Merge pull request #437 from 4Science/coar-notify-7-part-two-refactor…
Browse files Browse the repository at this point in the history
…-enqueue-plus

move ldn message enqueueretry to POST
  • Loading branch information
frabacche authored Mar 4, 2024
2 parents e65d766 + c3ab2a1 commit 3f3d862
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,11 @@ public List<LDNMessageEntity> findAllMessagesByItem(
public List<LDNMessageEntity> findAllRelatedMessagesByItem(
Context context, LDNMessageEntity msg, Item item, String... relatedTypes) throws SQLException;

/**
*
* @param context
* @return the list of messages in need to be reprocessed - with queue_status as QUEUE_STATUS_QUEUED_FOR_RETRY
* @throws SQLException
*/
public List<LDNMessageEntity> findMessagesToBeReprocessed(Context context) throws SQLException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,7 @@ private long ipToLong(InetAddress ip) {

@Override
public void update(Context context, LDNMessageEntity ldnMessage) throws SQLException {
// CST-12126 then LDNMessageService.update() when the origin is set != null,
// move the queue_status from UNTRUSTED to QUEUED
// move the queue_status from UNTRUSTED to QUEUED if origin is a known NotifyService
if (ldnMessage.getOrigin() != null &&
LDNMessageEntity.QUEUE_STATUS_UNTRUSTED.compareTo(ldnMessage.getQueueStatus()) == 0) {
ldnMessage.setQueueStatus(LDNMessageEntity.QUEUE_STATUS_QUEUED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,15 @@ public SolrInputDocument buildDocument(Context context, IndexableLDNNotification
doc.addField("queue_status_s", LDNMessageEntity.getQueueStatus(ldnMessage));
addFacetIndex(doc, "queue_status", String.valueOf(ldnMessage.getQueueStatus()),
LDNMessageEntity.getQueueStatus(ldnMessage));
Item item = (Item) ldnMessage.getObject();
if (ldnMessage.getObject() == null || ldnMessage.getObject().getID() == null) {
throw new SQLException("ldnMessage " + ldnMessage.getID() + " is linked to no Item.");
}
Item item = itemService.findByIdOrLegacyId(context, ldnMessage.getObject().getID().toString());
if (item != null) {
addFacetIndex(doc, "object", item.getID().toString(), itemService.getMetadata(item, "dc.title"));
addFacetIndex(doc, "relateditem", item.getID().toString(), itemService.getMetadata(item, "dc.title"));
}
item = (Item) ldnMessage.getContext();
item = itemService.findByIdOrLegacyId(context, ldnMessage.getContext().getID().toString());
if (item != null) {
addFacetIndex(doc, "context", item.getID().toString(), itemService.getMetadata(item, "dc.title"));
addFacetIndex(doc, "relateditem", item.getID().toString(), itemService.getMetadata(item, "dc.title"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

Expand All @@ -43,7 +43,7 @@
*/
@RestController
@RequestMapping("/api/" + LDNMessageEntityRest.CATEGORY + "/"
+ LDNMessageEntityRest.NAME_PLURALS + "/enqueueretry" + REGEX_REQUESTMAPPING_IDENTIFIER_AS_URN_UUID)
+ LDNMessageEntityRest.NAME_PLURALS + REGEX_REQUESTMAPPING_IDENTIFIER_AS_URN_UUID + "/enqueueretry")
public class LDNMessageRestController implements InitializingBean {

private static final Logger log = LogManager.getLogger(LDNMessageRestController.class);
Expand All @@ -64,11 +64,11 @@ public class LDNMessageRestController implements InitializingBean {
public void afterPropertiesSet() {
discoverableEndpointsService.register(this,
List.of(Link.of("/api/" + LDNMessageEntityRest.CATEGORY + "/"
+ LDNMessageEntityRest.NAME_PLURALS + "/enqueueretry/{id}",
+ LDNMessageEntityRest.NAME_PLURALS + "{id}/enqueueretry",
"enqueueretry")));
}

@GetMapping(produces = "application/json")
@PostMapping(produces = "application/json")
@PreAuthorize("hasAuthority('ADMIN')")
public ResponseEntity<String> findByItem(@PathVariable("id") String id)
throws SQLException, AuthorizeException, JsonProcessingException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
import org.dspace.content.DSpaceObject;
import org.dspace.discovery.IndexableObject;
import org.springframework.stereotype.Component;
/*

/**
* Converter to translate between {@link LDNMessageEntity} and {@link LDNMessageEntityRest} representations.
* @author Stefano Maffei (stefano.maffei at 4science.com)
*/
@Component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
import java.util.UUID;

import org.dspace.app.rest.RestResourceController;
/*
* @author Stefano Maffei (stefano.maffei at 4science.com)

/**
* The LDN Message REST resource.
* @author Stefano Maffei (stefano.maffei at 4science.com)
*/
@SuppressWarnings("serial")
public class LDNMessageEntityRest extends BaseObjectRest<String> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
Expand Down Expand Up @@ -55,23 +54,23 @@ public class LDNMessageRestControllerIT extends AbstractControllerIntegrationTes
@Test
public void findByItemUnAuthorizedTest() throws Exception {
getClient()
.perform(get("/api/ldn/messages/enqueueretry/urn:uuid:668f26e0-2c8d-4117-a0d2-ee713523bcb4"))
.andExpect(status().isUnauthorized());
.perform(post("/api/ldn/messages/urn:uuid:668f26e0-2c8d-4117-a0d2-ee713523bcb4/enqueueretry"))
.andExpect(status().isUnauthorized());
}

@Test
public void findByItemIsForbiddenTest() throws Exception {
String authToken = getAuthToken(eperson.getEmail(), password);
getClient(authToken)
.perform(get("/api/ldn/messages/enqueueretry/urn:uuid:668f26e0-2c8d-4117-a0d2-ee713523bcb4"))
.perform(post("/api/ldn/messages/urn:uuid:668f26e0-2c8d-4117-a0d2-ee713523bcb4/enqueueretry"))
.andExpect(status().isForbidden());
}

@Test
public void findByItemNotFoundTest() throws Exception {
String authToken = getAuthToken(admin.getEmail(), password);
getClient(authToken)
.perform(get("/api/ldn/messages/enqueueretry/urn:uuid:668f26e0-2c8d-4117-a0d2-ee713523bcb4"))
.perform(post("/api/ldn/messages/urn:uuid:668f26e0-2c8d-4117-a0d2-ee713523bcb4/enqueueretry"))
.andExpect(status().isNotFound());
}

Expand Down Expand Up @@ -115,7 +114,7 @@ public void findByItemTest() throws Exception {

String authToken = getAuthToken(admin.getEmail(), password);
getClient(authToken)
.perform(get("/api/ldn/messages/enqueueretry/" + notification.getId()))
.perform(post("/api/ldn/messages/" + notification.getId() + "/enqueueretry"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.id", is(notification.getId())))
.andExpect(jsonPath("$.notificationId", is(notification.getId())))
Expand Down

0 comments on commit 3f3d862

Please sign in to comment.