From 2326410d8d3681ebc36d656c3586acb60bbf9539 Mon Sep 17 00:00:00 2001 From: frabacche Date: Mon, 4 Mar 2024 09:14:24 +0100 Subject: [PATCH 1/5] move enqueueretry to POST --- .../org/dspace/app/rest/LDNMessageRestController.java | 11 ++++------- .../dspace/app/rest/LDNMessageRestControllerIT.java | 8 ++++---- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/LDNMessageRestController.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/LDNMessageRestController.java index 00f0f2b5289a..27f1549c8a0b 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/LDNMessageRestController.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/LDNMessageRestController.java @@ -31,10 +31,7 @@ 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.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; /** * Rest Controller for requesting the reprocessing of LDNMessageEntity @@ -43,7 +40,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); @@ -64,11 +61,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 findByItem(@PathVariable("id") String id) throws SQLException, AuthorizeException, JsonProcessingException { diff --git a/dspace-server-webapp/src/test/java/org/dspace/app/rest/LDNMessageRestControllerIT.java b/dspace-server-webapp/src/test/java/org/dspace/app/rest/LDNMessageRestControllerIT.java index 76356f871d58..3ae9619f5a47 100644 --- a/dspace-server-webapp/src/test/java/org/dspace/app/rest/LDNMessageRestControllerIT.java +++ b/dspace-server-webapp/src/test/java/org/dspace/app/rest/LDNMessageRestControllerIT.java @@ -55,7 +55,7 @@ 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")) + .perform(post("/api/ldn/messages/urn:uuid:668f26e0-2c8d-4117-a0d2-ee713523bcb4/enqueueretry")) .andExpect(status().isUnauthorized()); } @@ -63,7 +63,7 @@ public void findByItemUnAuthorizedTest() throws Exception { 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(get("/api/ldn/messages/urn:uuid:668f26e0-2c8d-4117-a0d2-ee713523bcb4/enqueueretry")) .andExpect(status().isForbidden()); } @@ -71,7 +71,7 @@ public void findByItemIsForbiddenTest() throws Exception { 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(get("/api/ldn/messages/urn:uuid:668f26e0-2c8d-4117-a0d2-ee713523bcb4/enqueueretry")) .andExpect(status().isNotFound()); } @@ -115,7 +115,7 @@ public void findByItemTest() throws Exception { String authToken = getAuthToken(admin.getEmail(), password); getClient(authToken) - .perform(get("/api/ldn/messages/enqueueretry/" + notification.getId())) + .perform(get("/api/ldn/messages/" + notification.getId() + "/enqueueretry")) .andExpect(status().isOk()) .andExpect(jsonPath("$.id", is(notification.getId()))) .andExpect(jsonPath("$.notificationId", is(notification.getId()))) From 8477eba2c81c1c46b58654f5b580e5bb6af31aba Mon Sep 17 00:00:00 2001 From: frabacche Date: Mon, 4 Mar 2024 10:17:43 +0100 Subject: [PATCH 2/5] checkstyle + IT class --- .../org/dspace/app/rest/LDNMessageRestController.java | 7 +++++-- .../dspace/app/rest/LDNMessageRestControllerIT.java | 10 +++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/LDNMessageRestController.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/LDNMessageRestController.java index 27f1549c8a0b..c359631cd418 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/LDNMessageRestController.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/LDNMessageRestController.java @@ -31,7 +31,10 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.*; +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; /** * Rest Controller for requesting the reprocessing of LDNMessageEntity @@ -40,7 +43,7 @@ */ @RestController @RequestMapping("/api/" + LDNMessageEntityRest.CATEGORY + "/" - + LDNMessageEntityRest.NAME_PLURALS + REGEX_REQUESTMAPPING_IDENTIFIER_AS_URN_UUID +"/enqueueretry") + + LDNMessageEntityRest.NAME_PLURALS + REGEX_REQUESTMAPPING_IDENTIFIER_AS_URN_UUID + "/enqueueretry") public class LDNMessageRestController implements InitializingBean { private static final Logger log = LogManager.getLogger(LDNMessageRestController.class); diff --git a/dspace-server-webapp/src/test/java/org/dspace/app/rest/LDNMessageRestControllerIT.java b/dspace-server-webapp/src/test/java/org/dspace/app/rest/LDNMessageRestControllerIT.java index 3ae9619f5a47..5d8f2d4ddee6 100644 --- a/dspace-server-webapp/src/test/java/org/dspace/app/rest/LDNMessageRestControllerIT.java +++ b/dspace-server-webapp/src/test/java/org/dspace/app/rest/LDNMessageRestControllerIT.java @@ -55,15 +55,15 @@ public class LDNMessageRestControllerIT extends AbstractControllerIntegrationTes @Test public void findByItemUnAuthorizedTest() throws Exception { getClient() - .perform(post("/api/ldn/messages/urn:uuid:668f26e0-2c8d-4117-a0d2-ee713523bcb4/enqueueretry")) - .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/urn:uuid:668f26e0-2c8d-4117-a0d2-ee713523bcb4/enqueueretry")) + .perform(post("/api/ldn/messages/urn:uuid:668f26e0-2c8d-4117-a0d2-ee713523bcb4/enqueueretry")) .andExpect(status().isForbidden()); } @@ -71,7 +71,7 @@ public void findByItemIsForbiddenTest() throws Exception { public void findByItemNotFoundTest() throws Exception { String authToken = getAuthToken(admin.getEmail(), password); getClient(authToken) - .perform(get("/api/ldn/messages/urn:uuid:668f26e0-2c8d-4117-a0d2-ee713523bcb4/enqueueretry")) + .perform(post("/api/ldn/messages/urn:uuid:668f26e0-2c8d-4117-a0d2-ee713523bcb4/enqueueretry")) .andExpect(status().isNotFound()); } @@ -115,7 +115,7 @@ public void findByItemTest() throws Exception { String authToken = getAuthToken(admin.getEmail(), password); getClient(authToken) - .perform(get("/api/ldn/messages/" + notification.getId() + "/enqueueretry")) + .perform(post("/api/ldn/messages/" + notification.getId() + "/enqueueretry")) .andExpect(status().isOk()) .andExpect(jsonPath("$.id", is(notification.getId()))) .andExpect(jsonPath("$.notificationId", is(notification.getId()))) From 993861a4a7fc154d9614ed3b90e8a97c2d6b0ff0 Mon Sep 17 00:00:00 2001 From: frabacche Date: Mon, 4 Mar 2024 10:33:07 +0100 Subject: [PATCH 3/5] checkstyle --- .../java/org/dspace/app/rest/LDNMessageRestControllerIT.java | 1 - 1 file changed, 1 deletion(-) diff --git a/dspace-server-webapp/src/test/java/org/dspace/app/rest/LDNMessageRestControllerIT.java b/dspace-server-webapp/src/test/java/org/dspace/app/rest/LDNMessageRestControllerIT.java index 5d8f2d4ddee6..a3001f6019ad 100644 --- a/dspace-server-webapp/src/test/java/org/dspace/app/rest/LDNMessageRestControllerIT.java +++ b/dspace-server-webapp/src/test/java/org/dspace/app/rest/LDNMessageRestControllerIT.java @@ -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; From f2683da032b54a0d5748e242245bff9b2ae48f4a Mon Sep 17 00:00:00 2001 From: frabacche Date: Mon, 4 Mar 2024 11:15:34 +0100 Subject: [PATCH 4/5] javadocs, refactor item cast to item search --- .../src/main/java/org/dspace/app/ldn/dao/LDNMessageDao.java | 6 ++++++ .../dspace/app/ldn/service/impl/LDNMessageServiceImpl.java | 3 +-- .../indexobject/LDNMessageEntityIndexFactoryImpl.java | 4 ++-- .../app/rest/converter/LDNMessageEntityConverter.java | 4 +++- .../org/dspace/app/rest/model/LDNMessageEntityRest.java | 6 ++++-- 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/dspace-api/src/main/java/org/dspace/app/ldn/dao/LDNMessageDao.java b/dspace-api/src/main/java/org/dspace/app/ldn/dao/LDNMessageDao.java index 50e89e830770..fcbb485acacc 100644 --- a/dspace-api/src/main/java/org/dspace/app/ldn/dao/LDNMessageDao.java +++ b/dspace-api/src/main/java/org/dspace/app/ldn/dao/LDNMessageDao.java @@ -66,5 +66,11 @@ public List findAllMessagesByItem( public List 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 findMessagesToBeReprocessed(Context context) throws SQLException; } diff --git a/dspace-api/src/main/java/org/dspace/app/ldn/service/impl/LDNMessageServiceImpl.java b/dspace-api/src/main/java/org/dspace/app/ldn/service/impl/LDNMessageServiceImpl.java index a41b81ef675d..193d8cebaf52 100644 --- a/dspace-api/src/main/java/org/dspace/app/ldn/service/impl/LDNMessageServiceImpl.java +++ b/dspace-api/src/main/java/org/dspace/app/ldn/service/impl/LDNMessageServiceImpl.java @@ -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); diff --git a/dspace-api/src/main/java/org/dspace/discovery/indexobject/LDNMessageEntityIndexFactoryImpl.java b/dspace-api/src/main/java/org/dspace/discovery/indexobject/LDNMessageEntityIndexFactoryImpl.java index bea06439c844..7edb9438ada9 100644 --- a/dspace-api/src/main/java/org/dspace/discovery/indexobject/LDNMessageEntityIndexFactoryImpl.java +++ b/dspace-api/src/main/java/org/dspace/discovery/indexobject/LDNMessageEntityIndexFactoryImpl.java @@ -89,12 +89,12 @@ 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(); + 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")); diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/converter/LDNMessageEntityConverter.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/converter/LDNMessageEntityConverter.java index 62840e12f98b..1c0783aec4d9 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/converter/LDNMessageEntityConverter.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/converter/LDNMessageEntityConverter.java @@ -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 diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/model/LDNMessageEntityRest.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/model/LDNMessageEntityRest.java index 4399db5476ae..336f2c63c343 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/model/LDNMessageEntityRest.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/model/LDNMessageEntityRest.java @@ -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 { From c3ab2a1dfa5f2cd9747b09041be2a99bbffc0ea9 Mon Sep 17 00:00:00 2001 From: frabacche Date: Mon, 4 Mar 2024 11:47:54 +0100 Subject: [PATCH 5/5] check item linked to ldnMessage before storing a new solr document --- .../indexobject/LDNMessageEntityIndexFactoryImpl.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dspace-api/src/main/java/org/dspace/discovery/indexobject/LDNMessageEntityIndexFactoryImpl.java b/dspace-api/src/main/java/org/dspace/discovery/indexobject/LDNMessageEntityIndexFactoryImpl.java index 7edb9438ada9..60312e1b3bb8 100644 --- a/dspace-api/src/main/java/org/dspace/discovery/indexobject/LDNMessageEntityIndexFactoryImpl.java +++ b/dspace-api/src/main/java/org/dspace/discovery/indexobject/LDNMessageEntityIndexFactoryImpl.java @@ -89,6 +89,9 @@ 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)); + 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"));