From 20f668aac320c59c32e1ae147fe77077cb3fcf7b Mon Sep 17 00:00:00 2001 From: frabacche Date: Thu, 16 Nov 2023 17:05:50 +0100 Subject: [PATCH] CST-12406 instroduce constants first implementation and test fixes --- .../org/dspace/qaevent/QANotifyPatterns.java | 29 ++++++ .../script/OpenaireEventsImportIT.java | 84 +++++++++------- .../dspace/app/rest/LDNInboxControllerIT.java | 3 +- .../app/rest/QAEventRestRepositoryIT.java | 99 ++++++++++--------- .../app/rest/QASourceRestRepositoryIT.java | 55 +++++------ .../app/rest/QATopicRestRepositoryIT.java | 94 ++++++++++-------- dspace/config/spring/api/qaevents.xml | 32 ++++-- 7 files changed, 229 insertions(+), 167 deletions(-) create mode 100644 dspace-api/src/main/java/org/dspace/qaevent/QANotifyPatterns.java diff --git a/dspace-api/src/main/java/org/dspace/qaevent/QANotifyPatterns.java b/dspace-api/src/main/java/org/dspace/qaevent/QANotifyPatterns.java new file mode 100644 index 000000000000..bc0d8dc1b830 --- /dev/null +++ b/dspace-api/src/main/java/org/dspace/qaevent/QANotifyPatterns.java @@ -0,0 +1,29 @@ +/** + * The contents of this file are subject to the license and copyright + * detailed in the LICENSE and NOTICE files at the root of the source + * tree and available online at + * + * http://www.dspace.org/license/ + */ +package org.dspace.qaevent; + +/** + * Constants for Quality Assurance configurations to be used into cfg and xml spring. + * + * @author Francesco Bacchelli (francesco.bacchelli at 4science.it) + * + */ +public class QANotifyPatterns { + public static final String TOPIC_ENRICH_MORE_PROJECT = "ENRICH/MORE/PROJECT"; + public static final String TOPIC_ENRICH_MISSING_PROJECT = "ENRICH/MISSING/PROJECT"; + public static final String TOPIC_ENRICH_MISSING_ABSTRACT = "ENRICH/MISSING/ABSTRACT"; + public static final String TOPIC_ENRICH_MORE_REVIEW = "ENRICH/MORE/REVIEW"; + public static final String TOPIC_ENRICH_MORE_ENDORSEMENT = "ENRICH/MORE/ENDORSEMENT"; + public static final String TOPIC_ENRICH_MORE_PID = "ENRICH/MORE/PID"; + public static final String TOPIC_ENRICH_MISSING_PID = "ENRICH/MISSING/PID"; + + /** + * Default constructor + */ + private QANotifyPatterns() { } +} diff --git a/dspace-api/src/test/java/org/dspace/qaevent/script/OpenaireEventsImportIT.java b/dspace-api/src/test/java/org/dspace/qaevent/script/OpenaireEventsImportIT.java index e6cf0e3dd8d7..8f2b4b874a44 100644 --- a/dspace-api/src/test/java/org/dspace/qaevent/script/OpenaireEventsImportIT.java +++ b/dspace-api/src/test/java/org/dspace/qaevent/script/OpenaireEventsImportIT.java @@ -47,6 +47,7 @@ import org.dspace.content.QAEvent; import org.dspace.matcher.QASourceMatcher; import org.dspace.matcher.QATopicMatcher; +import org.dspace.qaevent.QANotifyPatterns; import org.dspace.qaevent.QATopic; import org.dspace.qaevent.service.BrokerClientFactory; import org.dspace.qaevent.service.QAEventService; @@ -57,6 +58,7 @@ import org.junit.Before; import org.junit.Test; + /** * Integration tests for {@link OpenaireEventsImport}. * @@ -171,11 +173,11 @@ public void testManyEventsImportFromFile() throws Exception { ); List topicList = qaEventService.findAllTopicsBySource(context, OPENAIRE_SOURCE, 0, 20); - assertThat(topicList, hasItem(QATopicMatcher.with("ENRICH/MORE/PROJECT", 1L))); - assertThat(topicList, hasItem(QATopicMatcher.with("ENRICH/MORE/PID", 1L))); - assertThat(topicList, hasItem(QATopicMatcher.with("ENRICH/MISSING/PID", 1L))); - assertThat(topicList, hasItem(QATopicMatcher.with("ENRICH/MISSING/PROJECT", 1L))); - assertThat(topicList, hasItem(QATopicMatcher.with("ENRICH/MISSING/ABSTRACT", 1L))); + assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MORE_PROJECT, 1L))); + assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MORE_PID, 1L))); + assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID, 1L))); + assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MISSING_PROJECT, 1L))); + assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT, 1L))); String projectMessage = "{\"projects[0].acronym\":\"PAThs\",\"projects[0].code\":\"687567\"," + "\"projects[0].funder\":\"EC\",\"projects[0].fundingProgram\":\"H2020\"," @@ -183,18 +185,21 @@ public void testManyEventsImportFromFile() throws Exception { + "\"projects[0].openaireId\":\"40|corda__h2020::6e32f5eb912688f2424c68b851483ea4\"," + "\"projects[0].title\":\"Tracking Papyrus and Parchment Paths\"}"; - assertThat(qaEventService.findEventsByTopicAndPage(context, OPENAIRE_SOURCE, "ENRICH/MORE/PROJECT", 0, 20), + assertThat(qaEventService.findEventsByTopicAndPage(context, OPENAIRE_SOURCE, + QANotifyPatterns.TOPIC_ENRICH_MORE_PROJECT, 0, 20), contains( pendingOpenaireEventWith("oai:www.openstarts.units.it:123456789/99998", firstItem, "Egypt, crossroad of translations and literary interweavings", projectMessage, - "ENRICH/MORE/PROJECT", 1.00d))); + QANotifyPatterns.TOPIC_ENRICH_MORE_PROJECT, 1.00d))); String abstractMessage = "{\"abstracts[0]\":\"Missing Abstract\"}"; - assertThat(qaEventService.findEventsByTopicAndPage(context, OPENAIRE_SOURCE, "ENRICH/MISSING/ABSTRACT", 0, 20), + assertThat(qaEventService.findEventsByTopicAndPage(context, OPENAIRE_SOURCE, + QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT, 0, 20), contains( - pendingOpenaireEventWith("oai:www.openstarts.units.it:123456789/99999", secondItem, "Test Publication", - abstractMessage, "ENRICH/MISSING/ABSTRACT", 1.00d))); + pendingOpenaireEventWith("oai:www.openstarts.units.it:123456789/99999", + secondItem, "Test Publication", + abstractMessage, QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT, 1.00d))); verifyNoInteractions(mockBrokerClient); @@ -229,16 +234,17 @@ public void testManyEventsImportFromFileWithUnknownHandle() throws Exception { assertThat(qaEventService.findAllSources(context, 0, 20), hasItem(QASourceMatcher.with(OPENAIRE_SOURCE, 3L))); List topicList = qaEventService.findAllTopicsBySource(context, OPENAIRE_SOURCE, 0, 20); - assertThat(topicList, hasItem(QATopicMatcher.with("ENRICH/MISSING/ABSTRACT", 1L))); - assertThat(topicList, hasItem(QATopicMatcher.with("ENRICH/MISSING/PROJECT", 1L))); - assertThat(topicList, hasItem(QATopicMatcher.with("ENRICH/MORE/PID", 1L))); + assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT, 1L))); + assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MISSING_PROJECT, 1L))); + assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MORE_PID, 1L))); String abstractMessage = "{\"abstracts[0]\":\"Missing Abstract\"}"; - assertThat(qaEventService.findEventsByTopicAndPage(context, OPENAIRE_SOURCE, "ENRICH/MISSING/ABSTRACT", 0, 20), + assertThat(qaEventService.findEventsByTopicAndPage(context, OPENAIRE_SOURCE, + QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT, 0, 20), contains( pendingOpenaireEventWith("oai:www.openstarts.units.it:123456789/99999", item, "Test Publication", - abstractMessage, "ENRICH/MISSING/ABSTRACT", 1.00d))); + abstractMessage, QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT, 1.00d))); verifyNoInteractions(mockBrokerClient); @@ -269,14 +275,15 @@ public void testManyEventsImportFromFileWithUnknownTopic() throws Exception { assertThat(qaEventService.findAllSources(context, 0, 20), hasItem(QASourceMatcher.with(OPENAIRE_SOURCE, 1L))); assertThat(qaEventService.findAllTopicsBySource(context, OPENAIRE_SOURCE, 0, 20), - contains(QATopicMatcher.with("ENRICH/MISSING/ABSTRACT", 1L))); + contains(QATopicMatcher.with(org.dspace.qaevent.QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT, 1L))); String abstractMessage = "{\"abstracts[0]\":\"Missing Abstract\"}"; - assertThat(qaEventService.findEventsByTopicAndPage(context, OPENAIRE_SOURCE, "ENRICH/MISSING/ABSTRACT", 0, 20), + assertThat(qaEventService.findEventsByTopicAndPage(context, OPENAIRE_SOURCE, + QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT, 0, 20), contains( pendingOpenaireEventWith("oai:www.openstarts.units.it:123456789/999991", secondItem, "Test Publication 2", - abstractMessage, "ENRICH/MISSING/ABSTRACT", 1.00d))); + abstractMessage, org.dspace.qaevent.QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT, 1.00d))); verifyNoInteractions(mockBrokerClient); @@ -345,11 +352,11 @@ public void testImportFromOpenaireBroker() throws Exception { assertThat(qaEventService.findAllSources(context, 0, 20), hasItem(QASourceMatcher.with(OPENAIRE_SOURCE, 6L))); List topicList = qaEventService.findAllTopicsBySource(context, OPENAIRE_SOURCE, 0, 20); - assertThat(topicList, hasItem(QATopicMatcher.with("ENRICH/MORE/PROJECT", 1L))); - assertThat(topicList, hasItem(QATopicMatcher.with("ENRICH/MORE/PID", 1L))); - assertThat(topicList, hasItem(QATopicMatcher.with("ENRICH/MISSING/PID", 1L))); - assertThat(topicList, hasItem(QATopicMatcher.with("ENRICH/MISSING/PROJECT", 1L))); - assertThat(topicList, hasItem(QATopicMatcher.with("ENRICH/MISSING/ABSTRACT", 2L))); + assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MORE_PROJECT, 1L))); + assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MORE_PID, 1L))); + assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID, 1L))); + assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MISSING_PROJECT, 1L))); + assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT, 2L))); String projectMessage = "{\"projects[0].acronym\":\"PAThs\",\"projects[0].code\":\"687567\"," + "\"projects[0].funder\":\"EC\",\"projects[0].fundingProgram\":\"H2020\"," @@ -357,22 +364,23 @@ public void testImportFromOpenaireBroker() throws Exception { + "\"projects[0].openaireId\":\"40|corda__h2020::6e32f5eb912688f2424c68b851483ea4\"," + "\"projects[0].title\":\"Tracking Papyrus and Parchment Paths\"}"; - assertThat(qaEventService.findEventsByTopicAndPage(context, OPENAIRE_SOURCE, "ENRICH/MORE/PROJECT", 0, 20), + assertThat(qaEventService.findEventsByTopicAndPage(context, OPENAIRE_SOURCE, + QANotifyPatterns.TOPIC_ENRICH_MORE_PROJECT, 0, 20), contains( pendingOpenaireEventWith("oai:www.openstarts.units.it:123456789/99998", firstItem, "Egypt, crossroad of translations and literary interweavings", projectMessage, - "ENRICH/MORE/PROJECT", 1.00d))); + QANotifyPatterns.TOPIC_ENRICH_MORE_PROJECT, 1.00d))); String abstractMessage = "{\"abstracts[0]\":\"Missing Abstract\"}"; List eventList = qaEventService.findEventsByTopicAndPage(context, OPENAIRE_SOURCE, - "ENRICH/MISSING/ABSTRACT", 0, 20); + QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT, 0, 20); assertThat(eventList, hasItem( pendingOpenaireEventWith("oai:www.openstarts.units.it:123456789/99999", secondItem, "Test Publication", - abstractMessage, "ENRICH/MISSING/ABSTRACT", 1.00d))); + abstractMessage, QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT, 1.00d))); assertThat(eventList, hasItem( pendingOpenaireEventWith("oai:www.openstarts.units.it:123456789/999991", thirdItem, "Test Publication 2", - abstractMessage, "ENRICH/MISSING/ABSTRACT", 1.00d))); + abstractMessage, QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT, 1.00d))); verify(mockBrokerClient).listSubscriptions(openaireURL, "user@test.com"); verify(mockBrokerClient).downloadEvents(eq(openaireURL), eq("sub1"), any()); @@ -454,15 +462,17 @@ public void testImportFromOpenaireBrokerWithErrorDuringEventsDownload() throws E assertThat(qaEventService.findAllSources(context, 0, 20), hasItem(QASourceMatcher.with(OPENAIRE_SOURCE, 6L))); List topicList = qaEventService.findAllTopicsBySource(context, OPENAIRE_SOURCE, 0, 20); - assertThat(topicList, hasItem(QATopicMatcher.with("ENRICH/MORE/PROJECT", 1L))); - assertThat(topicList, hasItem(QATopicMatcher.with("ENRICH/MISSING/PID", 1L))); - assertThat(topicList, hasItem(QATopicMatcher.with("ENRICH/MORE/PID", 1L))); - assertThat(topicList, hasItem(QATopicMatcher.with("ENRICH/MISSING/PROJECT", 1L))); - assertThat(topicList, hasItem(QATopicMatcher.with("ENRICH/MISSING/ABSTRACT", 2L))); - - assertThat(qaEventService.findEventsByTopicAndPage(context, OPENAIRE_SOURCE, "ENRICH/MORE/PROJECT", 0, 20), + assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MORE_PROJECT, 1L))); + assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID, 1L))); + assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MORE_PID, 1L))); + assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MISSING_PROJECT, 1L))); + assertThat(topicList, hasItem(QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT, 2L))); + + assertThat(qaEventService.findEventsByTopicAndPage(context, OPENAIRE_SOURCE, + QANotifyPatterns.TOPIC_ENRICH_MORE_PROJECT, 0, 20), hasSize(1)); - assertThat(qaEventService.findEventsByTopicAndPage(context, OPENAIRE_SOURCE, "ENRICH/MISSING/ABSTRACT", 0, 20), + assertThat(qaEventService.findEventsByTopicAndPage(context, OPENAIRE_SOURCE, + QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT, 0, 20), hasSize(2)); verify(mockBrokerClient).listSubscriptions(openaireURL, "user@test.com"); @@ -489,7 +499,7 @@ public void testImportFromFileEventMoreReview() throws Exception { ScriptLauncher.handleScript(args, ScriptLauncher.getConfig(kernelImpl), handler, kernelImpl); assertThat(qaEventService.findAllTopicsBySource(context, OPENAIRE_SOURCE, 0, 20), contains( - QATopicMatcher.with("ENRICH/MORE/REVIEW", 1L))); + QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MORE_REVIEW, 1L))); assertThat(qaEventService.findAllSources(context, 0, 20), hasItem(QASourceMatcher.with(OPENAIRE_SOURCE, 1L))); diff --git a/dspace-server-webapp/src/test/java/org/dspace/app/rest/LDNInboxControllerIT.java b/dspace-server-webapp/src/test/java/org/dspace/app/rest/LDNInboxControllerIT.java index 86b7c2118cf2..9be10d2d503f 100644 --- a/dspace-server-webapp/src/test/java/org/dspace/app/rest/LDNInboxControllerIT.java +++ b/dspace-server-webapp/src/test/java/org/dspace/app/rest/LDNInboxControllerIT.java @@ -36,6 +36,7 @@ import org.dspace.content.Item; import org.dspace.matcher.QASourceMatcher; import org.dspace.matcher.QATopicMatcher; +import org.dspace.qaevent.QANotifyPatterns; import org.dspace.qaevent.service.QAEventService; import org.dspace.services.ConfigurationService; import org.dspace.utils.DSpace; @@ -134,7 +135,7 @@ public void ldnInboxAnnounceReviewTest() throws Exception { assertThat(qaEventService.findAllSources(context, 0, 20), hasItem(QASourceMatcher.with(COAR_NOTIFY, 1L))); assertThat(qaEventService.findAllTopicsBySource(context, COAR_NOTIFY, 0, 20), contains( - QATopicMatcher.with("ENRICH/MORE/REVIEW", 1L))); + QATopicMatcher.with(QANotifyPatterns.TOPIC_ENRICH_MORE_REVIEW, 1L))); } diff --git a/dspace-server-webapp/src/test/java/org/dspace/app/rest/QAEventRestRepositoryIT.java b/dspace-server-webapp/src/test/java/org/dspace/app/rest/QAEventRestRepositoryIT.java index aacf30b61b9f..62b62544363b 100644 --- a/dspace-server-webapp/src/test/java/org/dspace/app/rest/QAEventRestRepositoryIT.java +++ b/dspace-server-webapp/src/test/java/org/dspace/app/rest/QAEventRestRepositoryIT.java @@ -48,6 +48,7 @@ import org.dspace.content.QAEvent; import org.dspace.content.QAEventProcessed; import org.dspace.eperson.EPerson; +import org.dspace.qaevent.QANotifyPatterns; import org.dspace.qaevent.dao.QAEventsDao; import org.hamcrest.Matchers; import org.junit.Test; @@ -81,17 +82,17 @@ public void findOneTest() throws Exception { parentCommunity = CommunityBuilder.createCommunity(context).withName("Parent Community").build(); Collection col1 = CollectionBuilder.createCollection(context, parentCommunity).withName("Collection 1").build(); QAEvent event1 = QAEventBuilder.createTarget(context, col1, "Science and Freedom") - .withTopic("ENRICH/MISSING/PID") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID) .withMessage("{\"pids[0].type\":\"doi\",\"pids[0].value\":\"10.2307/2144300\"}").build(); QAEvent event2 = QAEventBuilder.createTarget(context, col1, "Science and Freedom 4") - .withTopic("ENRICH/MISSING/ABSTRACT") + .withTopic(org.dspace.qaevent.QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT) .withMessage("{\"abstracts[0]\": \"Descrizione delle caratteristiche...\"}").build(); EPerson anotherSubmitter = EPersonBuilder.createEPerson(context).withEmail("another-submitter@example.com") .withPassword(password).build(); context.setCurrentUser(anotherSubmitter); QAEvent event3 = QAEventBuilder.createTarget(context, col1, "Science and Freedom") .withSource(COAR_NOTIFY) - .withTopic("ENRICH/MORE/REVIEW") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MORE_REVIEW) .withMessage("{\"abstracts[0]\": \"Descrizione delle caratteristiche...\"}").build(); context.restoreAuthSystemState(); String authToken = getAuthToken(admin.getEmail(), password); @@ -117,10 +118,10 @@ public void findOneWithProjectionTest() throws Exception { parentCommunity = CommunityBuilder.createCommunity(context).withName("Parent Community").build(); Collection col1 = CollectionBuilder.createCollection(context, parentCommunity).withName("Collection 1").build(); QAEvent event1 = QAEventBuilder.createTarget(context, col1, "Science and Freedom") - .withTopic("ENRICH/MISSING/PID") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID) .withMessage("{\"pids[0].type\":\"doi\",\"pids[0].value\":\"10.2307/2144300\"}").build(); QAEvent event5 = QAEventBuilder.createTarget(context, col1, "Science and Freedom 5") - .withTopic("ENRICH/MISSING/PROJECT") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PROJECT) .withMessage( "{\"projects[0].acronym\":\"PAThs\"," + "\"projects[0].code\":\"687567\"," @@ -151,7 +152,7 @@ public void findOneUnauthorizedTest() throws Exception { parentCommunity = CommunityBuilder.createCommunity(context).withName("Parent Community").build(); Collection col1 = CollectionBuilder.createCollection(context, parentCommunity).withName("Collection 1").build(); QAEvent event1 = QAEventBuilder.createTarget(context, col1, "Science and Freedom") - .withTopic("ENRICH/MISSING/PID") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID) .withMessage("{\"pids[0].type\":\"doi\",\"pids[0].value\":\"10.2307/2144300\"}").build(); context.restoreAuthSystemState(); getClient().perform(get("/api/integration/qualityassuranceevents/" + event1.getEventId())) @@ -164,14 +165,14 @@ public void findOneForbiddenTest() throws Exception { parentCommunity = CommunityBuilder.createCommunity(context).withName("Parent Community").build(); Collection col1 = CollectionBuilder.createCollection(context, parentCommunity).withName("Collection 1").build(); QAEvent event1 = QAEventBuilder.createTarget(context, col1, "Science and Freedom") - .withTopic("ENRICH/MISSING/PID") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID) .withMessage("{\"pids[0].type\":\"doi\",\"pids[0].value\":\"10.2307/2144300\"}").build(); EPerson anotherSubmitter = EPersonBuilder.createEPerson(context).withEmail("another_submitter@example.com") .build(); context.setCurrentUser(anotherSubmitter); QAEvent event2 = QAEventBuilder.createTarget(context, col1, "Science and Freedom") .withSource(COAR_NOTIFY) - .withTopic("ENRICH/MORE/REVIEW") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MORE_REVIEW) .withMessage("{\"href\":\"https://doi.org/10.2307/2144300\"}").build(); context.restoreAuthSystemState(); String authToken = getAuthToken(eperson.getEmail(), password); @@ -190,12 +191,12 @@ public void findByTopicAndTargetTest() throws Exception { Item item = ItemBuilder.createItem(context, col1).withTitle("Tracking Papyrus and Parchment Paths") .build(); QAEvent event1 = QAEventBuilder.createTarget(context, item) - .withTopic("ENRICH/MISSING/PID") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID) .withMessage("{\"pids[0].type\":\"doi\",\"pids[0].value\":\"10.2307/2144300\"}") .build(); QAEvent event2 = QAEventBuilder.createTarget(context, item) .withSource(COAR_NOTIFY) - .withTopic("ENRICH/MORE/REVIEW") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MORE_REVIEW) .withMessage("{\"href\":\"https://doi.org/10.2307/2144301\"}").build(); EPerson anotherSubmitter = EPersonBuilder.createEPerson(context).withEmail("another-submitter@example.com") .withPassword(password).build(); @@ -203,7 +204,7 @@ public void findByTopicAndTargetTest() throws Exception { // this event is related to a new item not submitted by eperson QAEvent event3 = QAEventBuilder.createTarget(context, col1, "Science and Freedom") .withSource(COAR_NOTIFY) - .withTopic("ENRICH/MORE/REVIEW") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MORE_REVIEW) .withMessage("{\"href\":\"https://doi.org/10.2307/2144300\"}").build(); context.restoreAuthSystemState(); String authToken = getAuthToken(admin.getEmail(), password); @@ -305,45 +306,45 @@ public void findByTopicPaginatedTest() throws Exception { parentCommunity = CommunityBuilder.createCommunity(context).withName("Parent Community").build(); Collection col1 = CollectionBuilder.createCollection(context, parentCommunity).withName("Collection 1").build(); QAEvent event1 = QAEventBuilder.createTarget(context, col1, "Science and Freedom") - .withTopic("ENRICH/MISSING/PID") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID) .withMessage("{\"pids[0].type\":\"doi\",\"pids[0].value\":\"10.2307/2144300\"}").build(); QAEvent event2 = QAEventBuilder.createTarget(context, col1, "Science and Freedom 2") - .withTopic("ENRICH/MISSING/PID") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID) .withMessage("{\"pids[0].type\":\"doi\",\"pids[0].value\":\"10.2307/2144301\"}").build(); QAEvent event3 = QAEventBuilder.createTarget(context, col1, "Science and Freedom 3") - .withTopic("ENRICH/MISSING/PID") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID) .withMessage("{\"pids[0].type\":\"doi\",\"pids[0].value\":\"10.2307/2144302\"}").build(); QAEvent event4 = QAEventBuilder.createTarget(context, col1, "Science and Freedom 4") - .withTopic("ENRICH/MISSING/PID") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID) .withMessage("{\"pids[0].type\":\"pmc\",\"pids[0].value\":\"2144303\"}").build(); QAEvent event5 = QAEventBuilder.createTarget(context, col1, "Science and Freedom 5") - .withTopic("ENRICH/MISSING/PID") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID) .withMessage("{\"pids[0].type\":\"pmid\",\"pids[0].value\":\"2144304\"}").build(); QAEvent event6 = QAEventBuilder.createTarget(context, col1, "Science and Freedom") .withSource(COAR_NOTIFY) - .withTopic("ENRICH/MISSING/PID") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID) .withMessage("{\"pids[0].type\":\"doi\",\"pids[0].value\":\"10.2307/2144300\"}").build(); QAEvent event7 = QAEventBuilder.createTarget(context, col1, "Science and Freedom 2") .withSource(COAR_NOTIFY) - .withTopic("ENRICH/MISSING/PID") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID) .withMessage("{\"pids[0].type\":\"doi\",\"pids[0].value\":\"10.2307/2144301\"}").build(); QAEvent event8 = QAEventBuilder.createTarget(context, col1, "Science and Freedom 3") .withSource(COAR_NOTIFY) - .withTopic("ENRICH/MISSING/PID") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID) .withMessage("{\"pids[0].type\":\"doi\",\"pids[0].value\":\"10.2307/2144302\"}").build(); QAEvent event9 = QAEventBuilder.createTarget(context, col1, "Science and Freedom 4") .withSource(COAR_NOTIFY) - .withTopic("ENRICH/MISSING/PID") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID) .withMessage("{\"pids[0].type\":\"pmc\",\"pids[0].value\":\"2144303\"}").build(); QAEvent event10 = QAEventBuilder.createTarget(context, col1, "Science and Freedom 5") .withSource(COAR_NOTIFY) - .withTopic("ENRICH/MISSING/PID") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID) .withMessage("{\"pids[0].type\":\"pmid\",\"pids[0].value\":\"2144304\"}").build(); context.setCurrentUser(admin); // this event will be related to an item submitted by the admin QAEvent event11 = QAEventBuilder.createTarget(context, col1, "Science and Freedom 5") .withSource(COAR_NOTIFY) - .withTopic("ENRICH/MISSING/PID") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID) .withMessage("{\"pids[0].type\":\"pmid\",\"pids[0].value\":\"2144304\"}").build(); context.restoreAuthSystemState(); @@ -597,16 +598,16 @@ public void findByTopicUnauthorizedTest() throws Exception { parentCommunity = CommunityBuilder.createCommunity(context).withName("Parent Community").build(); Collection col1 = CollectionBuilder.createCollection(context, parentCommunity).withName("Collection 1").build(); QAEvent event1 = QAEventBuilder.createTarget(context, col1, "Science and Freedom") - .withTopic("ENRICH/MISSING/PID") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID) .withMessage("{\"pids[0].type\":\"doi\",\"pids[0].value\":\"10.2307/2144300\"}").build(); QAEvent event2 = QAEventBuilder.createTarget(context, col1, "Science and Freedom 2") - .withTopic("ENRICH/MISSING/PID") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID) .withMessage("{\"pids[0].type\":\"doi\",\"pids[0].value\":\"10.2307/2144301\"}").build(); QAEvent event3 = QAEventBuilder.createTarget(context, col1, "Science and Freedom 3") - .withTopic("ENRICH/MORE/PID") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MORE_PID) .withMessage("{\"pids[0].type\":\"pmid\",\"pids[0].value\":\"10.2307/2144302\"}").build(); QAEvent event4 = QAEventBuilder.createTarget(context, col1, "Science and Freedom 4") - .withTopic("ENRICH/MISSING/ABSTRACT") + .withTopic(org.dspace.qaevent.QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT) .withMessage("{\"abstracts[0]\": \"Descrizione delle caratteristiche...\"}").build(); context.restoreAuthSystemState(); getClient() @@ -622,16 +623,16 @@ public void findByTopicBadRequestTest() throws Exception { parentCommunity = CommunityBuilder.createCommunity(context).withName("Parent Community").build(); Collection col1 = CollectionBuilder.createCollection(context, parentCommunity).withName("Collection 1").build(); QAEvent event1 = QAEventBuilder.createTarget(context, col1, "Science and Freedom") - .withTopic("ENRICH/MISSING/PID") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID) .withMessage("{\"pids[0].type\":\"doi\",\"pids[0].value\":\"10.2307/2144300\"}").build(); QAEvent event2 = QAEventBuilder.createTarget(context, col1, "Science and Freedom 2") - .withTopic("ENRICH/MISSING/PID") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID) .withMessage("{\"pids[0].type\":\"doi\",\"pids[0].value\":\"10.2307/2144301\"}").build(); QAEvent event3 = QAEventBuilder.createTarget(context, col1, "Science and Freedom 3") - .withTopic("ENRICH/MORE/PID") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MORE_PID) .withMessage("{\"pids[0].type\":\"pmid\",\"pids[0].value\":\"10.2307/2144302\"}").build(); QAEvent event4 = QAEventBuilder.createTarget(context, col1, "Science and Freedom 4") - .withTopic("ENRICH/MISSING/ABSTRACT") + .withTopic(org.dspace.qaevent.QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT) .withMessage("{\"abstracts[0]\": \"Descrizione delle caratteristiche...\"}").build(); context.restoreAuthSystemState(); String adminToken = getAuthToken(admin.getEmail(), password); @@ -657,7 +658,7 @@ public void recordDecisionTest() throws Exception { Item funding = ItemBuilder.createItem(context, colFunding).withTitle("Tracking Papyrus and Parchment Paths") .build(); QAEvent eventProjectBound = QAEventBuilder.createTarget(context, col1, "Science and Freedom with project") - .withTopic("ENRICH/MISSING/PROJECT") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PROJECT) .withMessage( "{\"projects[0].acronym\":\"PAThs\"," + "\"projects[0].code\":\"687567\"," @@ -673,7 +674,7 @@ public void recordDecisionTest() throws Exception { .build(); QAEvent eventProjectNoBound = QAEventBuilder .createTarget(context, col1, "Science and Freedom with unrelated project") - .withTopic("ENRICH/MISSING/PROJECT") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PROJECT) .withMessage( "{\"projects[0].acronym\":\"NEW\"," + "\"projects[0].code\":\"123456\"," @@ -684,24 +685,24 @@ public void recordDecisionTest() throws Exception { + "\"projects[0].title\":\"A new project\"}") .build(); QAEvent eventMissingPID1 = QAEventBuilder.createTarget(context, col1, "Science and Freedom") - .withTopic("ENRICH/MISSING/PID") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID) .withMessage("{\"pids[0].type\":\"doi\",\"pids[0].value\":\"10.2307/2144300\"}").build(); QAEvent eventMissingPID2 = QAEventBuilder.createTarget(context, col1, "Science and Freedom 2") - .withTopic("ENRICH/MISSING/PID") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID) .withMessage("{\"pids[0].type\":\"doi\",\"pids[0].value\":\"10.2307/2144301\"}").build(); QAEvent eventMissingUnknownPID = QAEventBuilder.createTarget(context, col1, "Science and Freedom URN PID") - .withTopic("ENRICH/MISSING/PID") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID) .withMessage( "{\"pids[0].type\":\"urn\",\"pids[0].value\":\"http://thesis2.sba.units.it/store/handle/item/12937\"}") .build(); QAEvent eventMorePID = QAEventBuilder.createTarget(context, col1, "Science and Freedom 3") - .withTopic("ENRICH/MORE/PID") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MORE_PID) .withMessage("{\"pids[0].type\":\"pmid\",\"pids[0].value\":\"2144302\"}").build(); QAEvent eventAbstract = QAEventBuilder.createTarget(context, col1, "Science and Freedom 4") - .withTopic("ENRICH/MISSING/ABSTRACT") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT) .withMessage("{\"abstracts[0]\": \"An abstract to add...\"}").build(); QAEvent eventAbstractToDiscard = QAEventBuilder.createTarget(context, col1, "Science and Freedom 7") - .withTopic("ENRICH/MISSING/ABSTRACT") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT) .withMessage("{\"abstracts[0]\": \"Abstract to discard...\"}").build(); context.restoreAuthSystemState(); // prepare the different patches for our decisions @@ -834,7 +835,7 @@ public void setRelatedTest() throws Exception { Collection colFunding = CollectionBuilder.createCollection(context, parentCommunity) .withName("Collection Fundings").build(); QAEvent event = QAEventBuilder.createTarget(context, col1, "Science and Freedom 5") - .withTopic("ENRICH/MISSING/PROJECT") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PROJECT) .withMessage( "{\"projects[0].acronym\":\"PAThs\"," + "\"projects[0].code\":\"687567\"," @@ -883,7 +884,7 @@ public void unsetRelatedTest() throws Exception { Item funding = ItemBuilder.createItem(context, colFunding).withTitle("Tracking Papyrus and Parchment Paths") .build(); QAEvent event = QAEventBuilder.createTarget(context, col1, "Science and Freedom 5") - .withTopic("ENRICH/MISSING/PROJECT") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PROJECT) .withMessage( "{\"projects[0].acronym\":\"PAThs\"," + "\"projects[0].code\":\"687567\"," @@ -926,7 +927,7 @@ public void setInvalidRelatedTest() throws Exception { Collection colFunding = CollectionBuilder.createCollection(context, parentCommunity) .withName("Collection Fundings").build(); QAEvent event = QAEventBuilder.createTarget(context, col1, "Science and Freedom") - .withTopic("ENRICH/MISSING/PID") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID) .withMessage("{\"pids[0].type\":\"doi\",\"pids[0].value\":\"10.2307/2144300\"}").build(); Item funding = ItemBuilder.createItem(context, colFunding).withTitle("Tracking Papyrus and Parchment Paths") .build(); @@ -954,10 +955,10 @@ public void deleteItemWithEventTest() throws Exception { parentCommunity = CommunityBuilder.createCommunity(context).withName("Parent Community").build(); Collection col1 = CollectionBuilder.createCollection(context, parentCommunity).withName("Collection 1").build(); QAEvent event1 = QAEventBuilder.createTarget(context, col1, "Science and Freedom") - .withTopic("ENRICH/MISSING/PID") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID) .withMessage("{\"pids[0].type\":\"doi\",\"pids[0].value\":\"10.2307/2144300\"}").build(); QAEvent event2 = QAEventBuilder.createTarget(context, col1, "Science and Freedom 2") - .withTopic("ENRICH/MISSING/PID") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID) .withMessage("{\"pids[0].type\":\"doi\",\"pids[0].value\":\"10.2307/2144301\"}").build(); context.restoreAuthSystemState(); String authToken = getAuthToken(admin.getEmail(), password); @@ -1000,7 +1001,7 @@ public void testEventDeletion() throws Exception { .build(); QAEvent event = QAEventBuilder.createTarget(context, col1, "Science and Freedom") - .withTopic("ENRICH/MISSING/PID") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID) .withMessage("{\"pids[0].type\":\"doi\",\"pids[0].value\":\"10.2307/2144300\"}") .build(); @@ -1044,7 +1045,7 @@ public void createQAEventsAndAcceptAutomaticallyByScoreAndFilterTest() throws Ex QAEventBuilder.createTarget(context, item) .withSource(COAR_NOTIFY) .withTrust(0.8) - .withTopic("ENRICH/MORE/REVIEW") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MORE_REVIEW) .withMessage("{\"abstracts[0]\": \"https://doi.org/10.3214/987654\"}") .build(); @@ -1071,7 +1072,7 @@ public void createQAEventsAndIgnoreAutomaticallyByScoreAndFilterTest() throws Ex QAEventBuilder.createTarget(context, item) .withSource(COAR_NOTIFY) .withTrust(0.4) - .withTopic("ENRICH/MORE/REVIEW") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MORE_REVIEW) .withMessage("{\"abstracts[0]\": \"https://doi.org/10.3214/987654\"}") .build(); @@ -1097,7 +1098,7 @@ public void createQAEventsAndRejectAutomaticallyByScoreAndFilterTest() throws Ex QAEventBuilder.createTarget(context, item) .withSource(COAR_NOTIFY) .withTrust(0.3) - .withTopic("ENRICH/MORE/REVIEW") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MORE_REVIEW) .withMessage("{\"abstracts[0]\": \"https://doi.org/10.3214/987654\"}") .build(); @@ -1123,7 +1124,7 @@ public void createQAEventsAndDoNothingScoreNotInRangTest() throws Exception { QAEventBuilder.createTarget(context, item) .withSource(COAR_NOTIFY) .withTrust(0.7) - .withTopic("ENRICH/MORE/REVIEW") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MORE_REVIEW) .withMessage("{\"abstracts[0]\": \"https://doi.org/10.3214/987654\"}") .build(); @@ -1151,7 +1152,7 @@ public void createQAEventsAndDoNothingFilterNotCompatibleWithItemTest() throws E QAEventBuilder.createTarget(context, item) .withSource(COAR_NOTIFY) .withTrust(0.8) - .withTopic("ENRICH/MORE/REVIEW") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MORE_REVIEW) .withMessage("{\"abstracts[0]\": \"https://doi.org/10.3214/987654\"}") .build(); diff --git a/dspace-server-webapp/src/test/java/org/dspace/app/rest/QASourceRestRepositoryIT.java b/dspace-server-webapp/src/test/java/org/dspace/app/rest/QASourceRestRepositoryIT.java index 745c42497385..40aca902e30f 100644 --- a/dspace-server-webapp/src/test/java/org/dspace/app/rest/QASourceRestRepositoryIT.java +++ b/dspace-server-webapp/src/test/java/org/dspace/app/rest/QASourceRestRepositoryIT.java @@ -97,17 +97,16 @@ public void testFindAll() throws Exception { matchQASourceEntry("test-source-2", 0)))) .andExpect(jsonPath("$.page.size", is(20))) .andExpect(jsonPath("$.page.totalElements", is(4))); + + // check with our eperson submitter + authToken = getAuthToken(eperson.getEmail(), password); getClient(authToken).perform(get("/api/integration/qualityassurancesources")) .andExpect(status().isOk()) .andExpect(content().contentType(contentType)) .andExpect(jsonPath("$._embedded.qualityassurancesources", contains( - matchQASourceEntry("coar-notify", 2), - matchQASourceEntry("openaire", 0), - matchQASourceEntry("test-source", 0), - matchQASourceEntry("test-source-2", 0)))) + matchQASourceEntry("coar-notify", 3)))) .andExpect(jsonPath("$.page.size", is(20))) - .andExpect(jsonPath("$.page.totalElements", is(4))); - + .andExpect(jsonPath("$.page.totalElements", is(1))); } @Test @@ -130,16 +129,16 @@ public void testFindOne() throws Exception { context.turnOffAuthorisationSystem(); - createEvent("openaire", "TOPIC/OPENAIRE/1", "Title 1"); - createEvent("openaire", "TOPIC/OPENAIRE/2", "Title 2"); - createEvent("openaire", "TOPIC/OPENAIRE/2", "Title 3"); + createEvent(QAEvent.OPENAIRE_SOURCE, "TOPIC/OPENAIRE/1", "Title 1"); + createEvent(QAEvent.OPENAIRE_SOURCE, "TOPIC/OPENAIRE/2", "Title 2"); + createEvent(QAEvent.OPENAIRE_SOURCE, "TOPIC/OPENAIRE/2", "Title 3"); createEvent("test-source", "TOPIC/TEST/1", "Title 4"); createEvent("test-source", "TOPIC/TEST/1", "Title 5"); - createEvent("coar-notify", "TOPIC", "Title 7"); + createEvent(QAEvent.COAR_NOTIFY, "TOPIC", "Title 7"); context.setCurrentUser(eperson); - createEvent("coar-notify", "TOPIC", "Title 8"); - createEvent("coar-notify", "TOPIC", "Title 9"); + createEvent(QAEvent.COAR_NOTIFY, "TOPIC", "Title 8"); + createEvent(QAEvent.COAR_NOTIFY, "TOPIC", "Title 9"); context.setCurrentUser(null); context.restoreAuthSystemState(); @@ -172,8 +171,8 @@ public void testFindOne() throws Exception { getClient(authToken).perform(get("/api/integration/qualityassurancesources/openaire")) .andExpect(status().isForbidden()); getClient(authToken).perform(get("/api/integration/qualityassurancesources/unknown-test-source")) - .andExpect(status().isNotFound()); - // the eperson will see only 2 events in coar-notify as 1 is related ot an item was submitted by other + .andExpect(status().isForbidden()); + // the eperson will see only 2 events in coar-notify as 1 is related to an item was submitted by other getClient(authToken).perform(get("/api/integration/qualityassurancesources/coar-notify")) .andExpect(status().isOk()) .andExpect(content().contentType(contentType)) @@ -203,7 +202,7 @@ public void testFindOneUnauthorized() throws Exception { context.turnOffAuthorisationSystem(); - createEvent("openaire", "TOPIC/OPENAIRE/1", "Title 1"); + createEvent(QAEvent.OPENAIRE_SOURCE, "TOPIC/OPENAIRE/1", "Title 1"); createEvent("test-source", "TOPIC/TEST/1", "Title 4"); context.restoreAuthSystemState(); @@ -221,17 +220,17 @@ public void testFindAllByTarget() throws Exception { Collection col = CollectionBuilder.createCollection(context, com).withName("Test collection").build(); Item target1 = ItemBuilder.createItem(context, col).withTitle("Test item1").build(); Item target2 = ItemBuilder.createItem(context, col).withTitle("Test item2").build(); - createEvent("openaire", "TOPIC/OPENAIRE/1", target1); - createEvent("openaire", "TOPIC/OPENAIRE/2", target1); + createEvent(QAEvent.OPENAIRE_SOURCE, "TOPIC/OPENAIRE/1", target1); + createEvent(QAEvent.OPENAIRE_SOURCE, "TOPIC/OPENAIRE/2", target1); createEvent("test-source", "TOPIC/TEST/1", target1); createEvent("test-source", "TOPIC/TEST/1", target2); context.setCurrentUser(eperson); Item target3 = ItemBuilder.createItem(context, col).withTitle("Test item3").build(); context.setCurrentUser(null); - createEvent("coar-notify", "TOPIC", target3); - createEvent("coar-notify", "TOPIC", target3); - createEvent("coar-notify", "TOPIC", target2); + createEvent(QAEvent.COAR_NOTIFY, "TOPIC", target3); + createEvent(QAEvent.COAR_NOTIFY, "TOPIC2", target3); + createEvent(QAEvent.COAR_NOTIFY, "TOPIC", target2); context.restoreAuthSystemState(); String authToken = getAuthToken(admin.getEmail(), password); @@ -240,7 +239,7 @@ public void testFindAllByTarget() throws Exception { target1.getID().toString())) .andExpect(status().isOk()).andExpect(content().contentType(contentType)) .andExpect(jsonPath("$._embedded.qualityassurancesources", - contains(matchQASourceEntry("openaire:" + target1.getID().toString(), 2), + contains(matchQASourceEntry(QAEvent.OPENAIRE_SOURCE + ":" + target1.getID().toString(), 2), matchQASourceEntry("test-source:" + target1.getID().toString(), 1)))) .andExpect(jsonPath("$.page.size", is(20))) .andExpect(jsonPath("$.page.totalElements", is(2))); @@ -251,7 +250,7 @@ public void testFindAllByTarget() throws Exception { .andExpect(status().isOk()).andExpect(content().contentType(contentType)) .andExpect(jsonPath("$._embedded.qualityassurancesources", contains( - matchQASourceEntry("coar-notify:" + target2.getID().toString(), 1), + matchQASourceEntry(QAEvent.COAR_NOTIFY + ":" + target2.getID().toString(), 1), matchQASourceEntry("test-source:" + target2.getID().toString(), 1)))) .andExpect(jsonPath("$.page.size", is(20))) .andExpect(jsonPath("$.page.totalElements", is(2))); @@ -260,7 +259,7 @@ public void testFindAllByTarget() throws Exception { target3.getID().toString())) .andExpect(status().isOk()).andExpect(content().contentType(contentType)) .andExpect(jsonPath("$._embedded.qualityassurancesources", - contains(matchQASourceEntry("coar-notify:" + target3.getID().toString(), 2)))) + contains(matchQASourceEntry("coar-notify:" + target3.getID().toString(), 2)))) .andExpect(jsonPath("$.page.size", is(20))) .andExpect(jsonPath("$.page.totalElements", is(1))); @@ -277,7 +276,7 @@ public void testFindAllByTarget() throws Exception { target2.getID().toString())) .andExpect(status().isOk()) .andExpect(jsonPath("$.page.size", is(20))) - .andExpect(jsonPath("$.page.totalElements", is(0))); + .andExpect(jsonPath("$.page.totalElements", is(1))); getClient(authToken) .perform(get("/api/integration/qualityassurancesources/search/byTarget").param("target", target3.getID().toString())) @@ -296,8 +295,8 @@ public void testFindByTargetBadRequest() throws Exception { Collection col = CollectionBuilder.createCollection(context, com).withName("Test collection").build(); Item target1 = ItemBuilder.createItem(context, col).withTitle("Test item1").build(); Item target2 = ItemBuilder.createItem(context, col).withTitle("Test item2").build(); - createEvent("openaire", "TOPIC/OPENAIRE/1", target1); - createEvent("openaire", "TOPIC/OPENAIRE/2", target1); + createEvent(QAEvent.OPENAIRE_SOURCE, "TOPIC/OPENAIRE/1", target1); + createEvent(QAEvent.OPENAIRE_SOURCE, "TOPIC/OPENAIRE/2", target1); createEvent("test-source", "TOPIC/TEST/1", target1); createEvent("test-source", "TOPIC/TEST/1", target2); @@ -318,8 +317,8 @@ public void testFindByTargetUnauthorized() throws Exception { Collection col = CollectionBuilder.createCollection(context, com).withName("Test collection").build(); Item target1 = ItemBuilder.createItem(context, col).withTitle("Test item1").build(); Item target2 = ItemBuilder.createItem(context, col).withTitle("Test item2").build(); - createEvent("openaire", "TOPIC/OPENAIRE/1", target1); - createEvent("openaire", "TOPIC/OPENAIRE/2", target1); + createEvent(QAEvent.OPENAIRE_SOURCE, "TOPIC/OPENAIRE/1", target1); + createEvent(QAEvent.OPENAIRE_SOURCE, "TOPIC/OPENAIRE/2", target1); createEvent("test-source", "TOPIC/TEST/1", target1); createEvent("test-source", "TOPIC/TEST/1", target2); diff --git a/dspace-server-webapp/src/test/java/org/dspace/app/rest/QATopicRestRepositoryIT.java b/dspace-server-webapp/src/test/java/org/dspace/app/rest/QATopicRestRepositoryIT.java index eeda2f6dfcc1..f4e2f73e9fe9 100644 --- a/dspace-server-webapp/src/test/java/org/dspace/app/rest/QATopicRestRepositoryIT.java +++ b/dspace-server-webapp/src/test/java/org/dspace/app/rest/QATopicRestRepositoryIT.java @@ -25,6 +25,7 @@ import org.dspace.content.Collection; import org.dspace.content.Item; import org.dspace.content.QAEvent; +import org.dspace.qaevent.QANotifyPatterns; import org.dspace.services.ConfigurationService; import org.hamcrest.Matchers; import org.junit.Test; @@ -49,16 +50,16 @@ public void findAllNotImplementedTest() throws Exception { .build(); Collection col1 = CollectionBuilder.createCollection(context, parentCommunity).withName("Collection 1").build(); QAEventBuilder.createTarget(context, col1, "Science and Freedom") - .withTopic("ENRICH/MISSING/PID") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID) .withMessage("{\"pids[0].type\":\"doi\",\"pids[0].value\":\"10.2307/2144300\"}").build(); QAEventBuilder.createTarget(context, col1, "Science and Freedom 2") - .withTopic("ENRICH/MISSING/PID") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID) .withMessage("{\"pids[0].type\":\"doi\",\"pids[0].value\":\"10.2307/2144301\"}").build(); QAEventBuilder.createTarget(context, col1, "Science and Freedom 3") - .withTopic("ENRICH/MORE/PID") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MORE_PID) .withMessage("{\"pids[0].type\":\"pmid\",\"pids[0].value\":\"10.2307/2144302\"}").build(); QAEventBuilder.createTarget(context, col1, "Science and Freedom 4") - .withTopic("ENRICH/MISSING/ABSTRACT") + .withTopic(org.dspace.qaevent.QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT) .withMessage( "{\"abstracts[0]\": \"Descrizione delle caratteristiche...\"}") .build(); @@ -78,16 +79,16 @@ public void findOneTest() throws Exception { .build(); Collection col1 = CollectionBuilder.createCollection(context, parentCommunity).withName("Collection 1").build(); QAEventBuilder.createTarget(context, col1, "Science and Freedom") - .withTopic("ENRICH/MISSING/PID") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID) .withMessage("{\"pids[0].type\":\"doi\",\"pids[0].value\":\"10.2307/2144300\"}").build(); QAEventBuilder.createTarget(context, col1, "Science and Freedom 2") - .withTopic("ENRICH/MISSING/PID") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID) .withMessage("{\"pids[0].type\":\"doi\",\"pids[0].value\":\"10.2307/2144301\"}").build(); QAEventBuilder.createTarget(context, col1, "Science and Freedom 3") - .withTopic("ENRICH/MORE/PID") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MORE_PID) .withMessage("{\"pids[0].type\":\"pmid\",\"pids[0].value\":\"10.2307/2144302\"}").build(); QAEventBuilder.createTarget(context, col1, "Science and Freedom 4") - .withTopic("ENRICH/MISSING/ABSTRACT") + .withTopic(org.dspace.qaevent.QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT) .withMessage( "{\"test\": \"Test...\"}") .build(); @@ -101,13 +102,16 @@ public void findOneTest() throws Exception { String authToken = getAuthToken(admin.getEmail(), password); getClient(authToken).perform(get("/api/integration/qualityassurancetopics/openaire:ENRICH!MISSING!PID")) .andExpect(status().isOk()) - .andExpect(jsonPath("$", QATopicMatcher.matchQATopicEntry("ENRICH/MISSING/PID", 2))); + .andExpect(jsonPath("$", + QATopicMatcher.matchQATopicEntry(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID, 2))); getClient(authToken).perform(get("/api/integration/qualityassurancetopics/openaire:ENRICH!MISSING!ABSTRACT")) .andExpect(status().isOk()) - .andExpect(jsonPath("$", QATopicMatcher.matchQATopicEntry("ENRICH/MISSING/ABSTRACT", 1))); + .andExpect(jsonPath("$", + QATopicMatcher.matchQATopicEntry(QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT, 1))); getClient(authToken).perform(get("/api/integration/qualityassurancetopics/test-source:TOPIC!TEST")) .andExpect(status().isOk()) - .andExpect(jsonPath("$", QATopicMatcher.matchQATopicEntry("test-source", "TOPIC/TEST", 1))); + .andExpect(jsonPath("$", + QATopicMatcher.matchQATopicEntry("test-source", "TOPIC/TEST", 1))); } @Test @@ -120,7 +124,7 @@ public void findOneNotFoundTest() throws Exception { .build(); Collection col1 = CollectionBuilder.createCollection(context, parentCommunity).withName("Collection 1").build(); QAEventBuilder.createTarget(context, col1, "Science and Freedom") - .withTopic("ENRICH/MISSING/PID") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID) .withMessage("{\"pids[0].type\":\"doi\",\"pids[0].value\":\"10.2307/2144300\"}").build(); context.restoreAuthSystemState(); String authToken = getAuthToken(admin.getEmail(), password); @@ -144,7 +148,7 @@ public void findOneUnauthorizedTest() throws Exception { .build(); Collection col1 = CollectionBuilder.createCollection(context, parentCommunity).withName("Collection 1").build(); QAEventBuilder.createTarget(context, col1, "Science and Freedom") - .withTopic("ENRICH/MISSING/PID").build(); + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID).build(); context.restoreAuthSystemState(); getClient().perform(get("/api/integration/qualityassurancetopics/openaire:ENRICH!MISSING!PID")) .andExpect(status().isUnauthorized()); @@ -160,7 +164,7 @@ public void findOneForbiddenTest() throws Exception { .build(); Collection col1 = CollectionBuilder.createCollection(context, parentCommunity).withName("Collection 1").build(); QAEventBuilder.createTarget(context, col1, "Science and Freedom") - .withTopic("ENRICH/MISSING/PID").build(); + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID).build(); context.restoreAuthSystemState(); String authToken = getAuthToken(eperson.getEmail(), password); getClient(authToken).perform(get("/api/integration/qualityassurancetopics/openaire:ENRICH!MISSING!PID")) @@ -179,16 +183,16 @@ public void findBySourceTest() throws Exception { .build(); Collection col1 = CollectionBuilder.createCollection(context, parentCommunity).withName("Collection 1").build(); QAEventBuilder.createTarget(context, col1, "Science and Freedom") - .withTopic("ENRICH/MISSING/PID") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID) .withMessage("{\"pids[0].type\":\"doi\",\"pids[0].value\":\"10.2307/2144300\"}").build(); QAEventBuilder.createTarget(context, col1, "Science and Freedom 2") - .withTopic("ENRICH/MISSING/PID") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID) .withMessage("{\"pids[0].type\":\"doi\",\"pids[0].value\":\"10.2307/2144301\"}").build(); QAEventBuilder.createTarget(context, col1, "Science and Freedom 3") - .withTopic("ENRICH/MORE/PID") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MORE_PID) .withMessage("{\"pids[0].type\":\"pmid\",\"pids[0].value\":\"10.2307/2144302\"}").build(); QAEventBuilder.createTarget(context, col1, "Science and Freedom 4") - .withTopic("ENRICH/MISSING/ABSTRACT") + .withTopic(org.dspace.qaevent.QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT) .withMessage( "{\"abstracts[0]\": \"Descrizione delle caratteristiche...\"}") .build(); @@ -211,9 +215,10 @@ public void findBySourceTest() throws Exception { .andExpect(status().isOk()) .andExpect(content().contentType(contentType)) .andExpect(jsonPath("$._embedded.qualityassurancetopics", - Matchers.containsInAnyOrder(QATopicMatcher.matchQATopicEntry("ENRICH/MISSING/PID", 2), - QATopicMatcher.matchQATopicEntry("ENRICH/MISSING/ABSTRACT", 1), - QATopicMatcher.matchQATopicEntry("ENRICH/MORE/PID", 1)))) + Matchers.containsInAnyOrder( + QATopicMatcher.matchQATopicEntry(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID, 2), + QATopicMatcher.matchQATopicEntry(QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT, 1), + QATopicMatcher.matchQATopicEntry(QANotifyPatterns.TOPIC_ENRICH_MORE_PID, 1)))) .andExpect(jsonPath("$.page.size", is(20))).andExpect(jsonPath("$.page.totalElements", is(3))); getClient(authToken).perform(get("/api/integration/qualityassurancetopics/search/bySource") .param("source", "test-source")) @@ -242,16 +247,16 @@ public void findBySourcePaginationTest() throws Exception { //create collection Collection col1 = CollectionBuilder.createCollection(context, parentCommunity).withName("Collection 1").build(); QAEventBuilder.createTarget(context, col1, "Science and Freedom") - .withTopic("ENRICH/MISSING/PID") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID) .withMessage("{\"pids[0].type\":\"doi\",\"pids[0].value\":\"10.2307/2144300\"}").build(); QAEventBuilder.createTarget(context, col1, "Science and Freedom 2") - .withTopic("ENRICH/MISSING/PID") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID) .withMessage("{\"pids[0].type\":\"doi\",\"pids[0].value\":\"10.2307/2144301\"}").build(); QAEventBuilder.createTarget(context, col1, "Science and Freedom 3") - .withTopic("ENRICH/MORE/PID") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MORE_PID) .withMessage("{\"pids[0].type\":\"pmid\",\"pids[0].value\":\"10.2307/2144302\"}").build(); QAEventBuilder.createTarget(context, col1, "Science and Freedom 4") - .withTopic("ENRICH/MISSING/ABSTRACT") + .withTopic(org.dspace.qaevent.QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT) .withMessage( "{\"abstracts[0]\": \"Descrizione delle caratteristiche...\"}") .build(); @@ -301,7 +306,7 @@ public void findBySourceUnauthorizedTest() throws Exception { .build(); Collection col1 = CollectionBuilder.createCollection(context, parentCommunity).withName("Collection 1").build(); QAEventBuilder.createTarget(context, col1, "Science and Freedom") - .withTopic("ENRICH/MISSING/PID").build(); + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID).build(); context.restoreAuthSystemState(); getClient().perform(get("/api/integration/qualityassurancetopics/search/bySource") .param("source", "openaire")) @@ -316,7 +321,7 @@ public void findBySourceForbiddenTest() throws Exception { .build(); Collection col1 = CollectionBuilder.createCollection(context, parentCommunity).withName("Collection 1").build(); QAEventBuilder.createTarget(context, col1, "Science and Freedom") - .withTopic("ENRICH/MISSING/PID").build(); + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID).build(); context.restoreAuthSystemState(); String authToken = getAuthToken(eperson.getEmail(), password); getClient(authToken).perform(get("/api/integration/qualityassurancetopics/search/bySource") @@ -337,12 +342,12 @@ public void findByTargetTest() throws Exception { Item item1 = ItemBuilder.createItem(context, col1).withTitle("Science and Freedom").build(); Item item2 = ItemBuilder.createItem(context, col1).withTitle("Science and Freedom 2").build(); QAEventBuilder.createTarget(context, item1) - .withSource("openaire") - .withTopic("ENRICH/MISSING/PID") + .withSource(QAEvent.OPENAIRE_SOURCE) + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID) .withMessage("{\"pids[0].type\":\"doi\",\"pids[0].value\":\"10.2307/2144300\"}").build(); QAEventBuilder.createTarget(context, item1) - .withSource("openaire") - .withTopic("ENRICH/MISSING/ABSTRACT") + .withSource(QAEvent.OPENAIRE_SOURCE) + .withTopic(org.dspace.qaevent.QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT) .withMessage( "{\"abstracts[0]\": \"Descrizione delle caratteristiche...\"}") .build(); @@ -355,24 +360,26 @@ public void findByTargetTest() throws Exception { .withSource("test-source") .build(); QAEventBuilder.createTarget(context, item2) - .withTopic("ENRICH/MISSING/PID") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID) .withMessage("{\"pids[0].type\":\"doi\",\"pids[0].value\":\"10.2307/2144301\"}").build(); QAEventBuilder.createTarget(context, item2) - .withTopic("ENRICH/MISSING/PID") + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID) .withMessage("{\"pids[0].type\":\"pmid\",\"pids[0].value\":\"2144301\"}").build(); context.restoreAuthSystemState(); String authToken = getAuthToken(admin.getEmail(), password); getClient(authToken).perform(get("/api/integration/qualityassurancetopics/search/byTarget") .param("target", item1.getID().toString()) - .param("source", "openaire")) + .param("source", QAEvent.OPENAIRE_SOURCE)) .andExpect(status().isOk()) .andExpect(content().contentType(contentType)) .andExpect(jsonPath("$._embedded.qualityassurancetopics", Matchers.containsInAnyOrder( - QATopicMatcher.matchQATopicEntry("openaire", "ENRICH/MISSING/PID", + QATopicMatcher.matchQATopicEntry(QAEvent.OPENAIRE_SOURCE, + QANotifyPatterns.TOPIC_ENRICH_MISSING_PID, item1.getID().toString(), 1), - QATopicMatcher.matchQATopicEntry("openaire", "ENRICH/MISSING/ABSTRACT", - item1.getID().toString(), 1)))) + QATopicMatcher.matchQATopicEntry(QAEvent.OPENAIRE_SOURCE, + QANotifyPatterns.TOPIC_ENRICH_MISSING_ABSTRACT, + item1.getID().toString(), 1)))) .andExpect(jsonPath("$.page.size", is(20))).andExpect(jsonPath("$.page.totalElements", is(2))); getClient(authToken).perform(get("/api/integration/qualityassurancetopics/search/byTarget") .param("target", item2.getID().toString()) @@ -381,12 +388,13 @@ public void findByTargetTest() throws Exception { .andExpect(content().contentType(contentType)) .andExpect(jsonPath("$._embedded.qualityassurancetopics", Matchers.containsInAnyOrder( - QATopicMatcher.matchQATopicEntry("openaire", "ENRICH/MISSING/PID", + QATopicMatcher.matchQATopicEntry(QAEvent.OPENAIRE_SOURCE, + QANotifyPatterns.TOPIC_ENRICH_MISSING_PID, item2.getID().toString(), 2)))) .andExpect(jsonPath("$.page.size", is(20))).andExpect(jsonPath("$.page.totalElements", is(1))); getClient(authToken).perform(get("/api/integration/qualityassurancetopics/search/byTarget") .param("target", UUID.randomUUID().toString()) - .param("source", "openaire")) + .param("source", QAEvent.OPENAIRE_SOURCE)) .andExpect(status().isOk()) .andExpect(content().contentType(contentType)) .andExpect(jsonPath("$._embedded.qualityassurancetopics").doesNotExist()) @@ -410,10 +418,10 @@ public void findByTargetUnauthorizedTest() throws Exception { Collection col1 = CollectionBuilder.createCollection(context, parentCommunity).withName("Collection 1").build(); Item item1 = ItemBuilder.createItem(context, col1).withTitle("Science and Freedom").build(); QAEventBuilder.createTarget(context, item1) - .withTopic("ENRICH/MISSING/PID").build(); + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID).build(); context.restoreAuthSystemState(); getClient().perform(get("/api/integration/qualityassurancetopics/search/byTarget") - .param("source", "openaire") + .param("source", QAEvent.OPENAIRE_SOURCE) .param("target", item1.getID().toString())) .andExpect(status().isUnauthorized()); } @@ -427,7 +435,7 @@ public void findByTargetForbiddenTest() throws Exception { Collection col1 = CollectionBuilder.createCollection(context, parentCommunity).withName("Collection 1").build(); Item item1 = ItemBuilder.createItem(context, col1).withTitle("Science and Freedom").build(); QAEventBuilder.createTarget(context, item1) - .withTopic("ENRICH/MISSING/PID").build(); + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID).build(); context.restoreAuthSystemState(); String authToken = getAuthToken(eperson.getEmail(), password); getClient(authToken).perform(get("/api/integration/qualityassurancetopics/search/byTarget") @@ -446,7 +454,7 @@ public void findByTargetBadRequest() throws Exception { Item item1 = ItemBuilder.createItem(context, col1).withTitle("Science and Freedom").build(); QAEventBuilder.createTarget(context, item1) .withSource("test-source") - .withTopic("ENRICH/MISSING/PID").build(); + .withTopic(QANotifyPatterns.TOPIC_ENRICH_MISSING_PID).build(); context.restoreAuthSystemState(); String authToken = getAuthToken(eperson.getEmail(), password); getClient(authToken).perform(get("/api/integration/qualityassurancetopics/search/byTarget") diff --git a/dspace/config/spring/api/qaevents.xml b/dspace/config/spring/api/qaevents.xml index fd85fc8641f1..98e9e13ab4b9 100644 --- a/dspace/config/spring/api/qaevents.xml +++ b/dspace/config/spring/api/qaevents.xml @@ -23,13 +23,27 @@ - - - - - - - + + + + + + + + + + + + + + + + + + + + + @@ -100,7 +114,7 @@ AutomaticProcessingEvaluation implementation. Below you can find an example of configuration defining some thresholds rules for the coar-notify generated QAEvent to be approved, rejected and ignored --> - + -->