diff --git a/dspace-api/src/main/java/org/dspace/app/nbevent/NBEntityOpenaireMetadataAction.java b/dspace-api/src/main/java/org/dspace/app/nbevent/NBEntityOpenaireMetadataAction.java
index e16c18edd0..926160aa48 100644
--- a/dspace-api/src/main/java/org/dspace/app/nbevent/NBEntityOpenaireMetadataAction.java
+++ b/dspace-api/src/main/java/org/dspace/app/nbevent/NBEntityOpenaireMetadataAction.java
@@ -109,7 +109,8 @@ public class NBEntityOpenaireMetadataAction implements NBAction {
link(context, item, relatedItem);
} else {
- Collection collection = collectionService.retrieveCollectionByEntityType(context, item, entityType);
+ Collection collection = collectionService.retrieveCollectionWithSubmitByEntityType(context,
+ item, entityType);
if (collection == null) {
throw new IllegalStateException("No collection found by entity type: " + collection);
}
diff --git a/dspace-api/src/main/java/org/dspace/app/nbevent/NBEventActionServiceImpl.java b/dspace-api/src/main/java/org/dspace/app/nbevent/NBEventActionServiceImpl.java
index 9ebd796a80..a14dcf5b22 100644
--- a/dspace-api/src/main/java/org/dspace/app/nbevent/NBEventActionServiceImpl.java
+++ b/dspace-api/src/main/java/org/dspace/app/nbevent/NBEventActionServiceImpl.java
@@ -101,7 +101,8 @@ public class NBEventActionServiceImpl implements NBEventActionService {
* Make acknowledgement to the configured urls for the event status.
*/
private void makeAcknowledgement(String eventId, String source, String status) {
- String[] ackwnoledgeCallbacks = configurationService.getArrayProperty(source + "-nbevents.acknowledge-url");
+ String[] ackwnoledgeCallbacks = configurationService
+ .getArrayProperty("nbevents." + source + ".acknowledge-url");
if (ackwnoledgeCallbacks != null) {
for (String ackwnoledgeCallback : ackwnoledgeCallbacks) {
if (StringUtils.isNotBlank(ackwnoledgeCallback)) {
diff --git a/dspace-api/src/main/java/org/dspace/app/nbevent/NBOpenaireMetadataMapAction.java b/dspace-api/src/main/java/org/dspace/app/nbevent/NBOpenaireMetadataMapAction.java
index 216f44a2d5..c5909de962 100644
--- a/dspace-api/src/main/java/org/dspace/app/nbevent/NBOpenaireMetadataMapAction.java
+++ b/dspace-api/src/main/java/org/dspace/app/nbevent/NBOpenaireMetadataMapAction.java
@@ -51,6 +51,10 @@ public class NBOpenaireMetadataMapAction implements NBAction {
@Override
public void applyCorrection(Context context, Item item, Item relatedItem, NBMessageDTO message) {
+ if (relatedItem != null) {
+ throw new IllegalArgumentException("NBOpenaireMetadataMapAction does not support related item");
+ }
+
if (!(message instanceof OpenaireMessageDTO)) {
throw new IllegalArgumentException("Unsupported message type: " + message.getClass());
}
diff --git a/dspace-api/src/main/java/org/dspace/app/nbevent/NBOpenaireSimpleMetadataAction.java b/dspace-api/src/main/java/org/dspace/app/nbevent/NBOpenaireSimpleMetadataAction.java
index f08b3f7db4..8666353f8a 100644
--- a/dspace-api/src/main/java/org/dspace/app/nbevent/NBOpenaireSimpleMetadataAction.java
+++ b/dspace-api/src/main/java/org/dspace/app/nbevent/NBOpenaireSimpleMetadataAction.java
@@ -52,6 +52,11 @@ public class NBOpenaireSimpleMetadataAction implements NBAction {
@Override
public void applyCorrection(Context context, Item item, Item relatedItem, NBMessageDTO message) {
+
+ if (relatedItem != null) {
+ throw new IllegalArgumentException("NBOpenaireSimpleMetadataAction does not support related item");
+ }
+
try {
itemService.addMetadata(context, item, metadataSchema, metadataElement, metadataQualifier, null,
((OpenaireMessageDTO) message).getAbstracts());
diff --git a/dspace-api/src/main/java/org/dspace/app/nbevent/OpenaireEventsRunnable.java b/dspace-api/src/main/java/org/dspace/app/nbevent/OpenaireEventsRunnable.java
index 4969267d94..e2b66cd749 100644
--- a/dspace-api/src/main/java/org/dspace/app/nbevent/OpenaireEventsRunnable.java
+++ b/dspace-api/src/main/java/org/dspace/app/nbevent/OpenaireEventsRunnable.java
@@ -33,8 +33,28 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * Implementation of {@link DSpaceRunnable} to perfom a NBEvents import from file.
- *
+ * Implementation of {@link DSpaceRunnable} to perfom a NBEvents import from a
+ * json file. The JSON file contains an array of JSON Events, where each event
+ * has the following structure
+ *
+ *
+ * {
+ * "originalId": "oai:www.openstarts.units.it:10077/21838",
+ * "title": "Egypt, crossroad of translations and literary interweavings",
+ * "topic": "ENRICH/MORE/PROJECT",
+ * "trust": 1.0,
+ * "message": {
+ * "projects[0].acronym": "PAThs",
+ * "projects[0].code": "687567",
+ * "projects[0].funder": "EC",
+ * "projects[0].fundingProgram": "H2020",
+ * "projects[0].jurisdiction": "EU",
+ * "projects[0].openaireId": "40|corda__h2020::6e32f5eb912688f2424c68b851483ea4",
+ * "projects[0].title": "Tracking Papyrus and Parchment Paths"
+ * }
+ * }
+ *
+ *
* @author Alessandro Martelli (alessandro.martelli at 4science.it)
*
*/
@@ -76,7 +96,7 @@ public class OpenaireEventsRunnable extends DSpaceRunnable i
}
@Override
- public Collection retrieveCollectionByEntityType(Context context, Item item, String entityType)
- throws SQLException {
+ public Collection retrieveCollectionWithSubmitByEntityType(Context context, Item item,
+ String entityType) throws SQLException {
Collection ownCollection = item.getOwningCollection();
- return retrieveCollectionByEntityType(context, ownCollection.getCommunities(), entityType);
+ return retrieveWithSubmitCollectionByEntityType(context, ownCollection.getCommunities(), entityType);
}
- private Collection retrieveCollectionByEntityType(Context context, List communities, String entityType) {
+ private Collection retrieveWithSubmitCollectionByEntityType(Context context, List communities,
+ String entityType) {
for (Community community : communities) {
- Collection collection = retrieveCollectionByCommunityAndEntityType(context, community, entityType);
+ Collection collection = retrieveCollectionWithSubmitByCommunityAndEntityType(context, community,
+ entityType);
if (collection != null) {
return collection;
}
@@ -1035,17 +1037,17 @@ public class CollectionServiceImpl extends DSpaceObjectServiceImpl i
for (Community community : communities) {
List parentCommunities = community.getParentCommunities();
- Collection collection = retrieveCollectionByEntityType(context, parentCommunities, entityType);
+ Collection collection = retrieveWithSubmitCollectionByEntityType(context, parentCommunities, entityType);
if (collection != null) {
return collection;
}
}
- return retrieveCollectionByCommunityAndEntityType(context, null, entityType);
+ return retrieveCollectionWithSubmitByCommunityAndEntityType(context, null, entityType);
}
@Override
- public Collection retrieveCollectionByCommunityAndEntityType(Context context, Community community,
+ public Collection retrieveCollectionWithSubmitByCommunityAndEntityType(Context context, Community community,
String entityType) {
context.turnOffAuthorisationSystem();
List collections;
@@ -1060,7 +1062,8 @@ public class CollectionServiceImpl extends DSpaceObjectServiceImpl i
}
if (community != null) {
for (Community subCommunity : community.getSubcommunities()) {
- Collection collection = retrieveCollectionByCommunityAndEntityType(context, subCommunity, entityType);
+ Collection collection = retrieveCollectionWithSubmitByCommunityAndEntityType(context,
+ subCommunity, entityType);
if (collection != null) {
return collection;
}
diff --git a/dspace-api/src/main/java/org/dspace/content/NBEvent.java b/dspace-api/src/main/java/org/dspace/content/NBEvent.java
index a029d1f3e3..b53aef2815 100644
--- a/dspace-api/src/main/java/org/dspace/content/NBEvent.java
+++ b/dspace-api/src/main/java/org/dspace/content/NBEvent.java
@@ -13,9 +13,9 @@ import java.security.NoSuchAlgorithmException;
import java.util.Date;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
-import org.dspace.app.nbevent.RawJsonDeserializer;
import org.dspace.app.nbevent.service.dto.NBMessageDTO;
import org.dspace.app.nbevent.service.dto.OpenaireMessageDTO;
+import org.dspace.util.RawJsonDeserializer;
/**
* This class represent the notification broker data as loaded in our solr
@@ -173,7 +173,8 @@ public class NBEvent {
/*
* DTO constructed via Jackson use empty constructor. In this case, the eventId
- * must be compute on the get method
+ * must be compute on the get method. This method create a signature based on
+ * the event fields and store it in the eventid attribute.
*/
private void computedEventId() throws NoSuchAlgorithmException, UnsupportedEncodingException {
MessageDigest digester = MessageDigest.getInstance("MD5");
diff --git a/dspace-api/src/main/java/org/dspace/content/service/CollectionService.java b/dspace-api/src/main/java/org/dspace/content/service/CollectionService.java
index 07d4d113b7..5460fcb4e5 100644
--- a/dspace-api/src/main/java/org/dspace/content/service/CollectionService.java
+++ b/dspace-api/src/main/java/org/dspace/content/service/CollectionService.java
@@ -422,13 +422,14 @@ public interface CollectionService
* @return the first collection in the community or its descending
* that support the provided entityType
*/
- public Collection retrieveCollectionByCommunityAndEntityType(Context context, Community community,
+ public Collection retrieveCollectionWithSubmitByCommunityAndEntityType(Context context, Community community,
String entityType);
/**
- * Retrieve the close collection to the item that support the provided
- * entityType. Close mean the collection that can be reach with the minimum
- * steps starting from the item (owningCollection, brothers collections, etc)
+ * Retrieve the close collection to the item for which the current user has
+ * 'submit' privileges that support the provided entityType. Close mean the
+ * collection that can be reach with the minimum steps starting from the item
+ * (owningCollection, brothers collections, etc)
*
* @param context the DSpace context
* @param item the item from where the search start
@@ -436,7 +437,7 @@ public interface CollectionService
* @return the first collection in the community or its descending
* that support the provided entityType
*/
- public Collection retrieveCollectionByEntityType(Context context, Item item, String entityType)
+ public Collection retrieveCollectionWithSubmitByEntityType(Context context, Item item, String entityType)
throws SQLException;
/**
diff --git a/dspace-api/src/main/java/org/dspace/app/nbevent/RawJsonDeserializer.java b/dspace-api/src/main/java/org/dspace/util/RawJsonDeserializer.java
similarity index 97%
rename from dspace-api/src/main/java/org/dspace/app/nbevent/RawJsonDeserializer.java
rename to dspace-api/src/main/java/org/dspace/util/RawJsonDeserializer.java
index 475cc44a7d..baadf0d283 100644
--- a/dspace-api/src/main/java/org/dspace/app/nbevent/RawJsonDeserializer.java
+++ b/dspace-api/src/main/java/org/dspace/util/RawJsonDeserializer.java
@@ -5,7 +5,7 @@
*
* http://www.dspace.org/license/
*/
-package org.dspace.app.nbevent;
+package org.dspace.util;
import java.io.IOException;
diff --git a/dspace-api/src/test/java/org/dspace/util/RawJsonDeserializerTest.java b/dspace-api/src/test/java/org/dspace/util/RawJsonDeserializerTest.java
new file mode 100644
index 0000000000..e1e6e246b9
--- /dev/null
+++ b/dspace-api/src/test/java/org/dspace/util/RawJsonDeserializerTest.java
@@ -0,0 +1,58 @@
+/**
+ * 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.util;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import org.junit.Test;
+
+/**
+ * Unit tests for {@link RawJsonDeserializer}.
+ *
+ * @author Luca Giamminonni (luca.giamminonni at 4science.it)
+ *
+ */
+public class RawJsonDeserializerTest {
+
+ private String json = ""
+ + "{"
+ + " \"attribute\": {"
+ + " \"firstField\":\"value\","
+ + " \"secondField\": 1"
+ + " }"
+ + "}";
+
+ @Test
+ public void testDeserialization() throws JsonMappingException, JsonProcessingException {
+
+ ObjectMapper mapper = new ObjectMapper();
+
+ DeserializationTestClass object = mapper.readValue(json, DeserializationTestClass.class);
+ assertThat(object, notNullValue());
+ assertThat(object.getAttribute(), is("{\"firstField\":\"value\",\"secondField\":1}"));
+
+ }
+
+ private static class DeserializationTestClass {
+
+ @JsonDeserialize(using = RawJsonDeserializer.class)
+ private String attribute;
+
+ public String getAttribute() {
+ return attribute;
+ }
+
+ }
+
+}
diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/NBEventRestController.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/NBEventRestController.java
index 1245c3854e..f7bb4b2e48 100644
--- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/NBEventRestController.java
+++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/NBEventRestController.java
@@ -15,11 +15,11 @@ import java.util.UUID;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import org.apache.commons.lang3.StringUtils;
import org.dspace.app.nbevent.service.NBEventService;
import org.dspace.app.rest.converter.ConverterService;
import org.dspace.app.rest.exception.UnprocessableEntityException;
import org.dspace.app.rest.model.ItemRest;
+import org.dspace.app.rest.model.NBEventRest;
import org.dspace.app.rest.model.hateoas.ItemResource;
import org.dspace.app.rest.utils.ContextUtil;
import org.dspace.app.rest.utils.Utils;
@@ -47,7 +47,8 @@ import org.springframework.web.bind.annotation.RestController;
* "/api/integration/nbevents/{nbeventid}/related"
*/
@RestController
-@RequestMapping("/api/integration/nbevents" + REGEX_REQUESTMAPPING_IDENTIFIER_AS_STRING_VERSION_STRONG + "/related")
+@RequestMapping("/api/" + NBEventRest.CATEGORY + "/nbevents" + REGEX_REQUESTMAPPING_IDENTIFIER_AS_STRING_VERSION_STRONG
+ + "/related")
public class NBEventRestController {
@Autowired
protected Utils utils;
@@ -87,8 +88,6 @@ public class NBEventRestController {
if (nbevent.getRelated() != null) {
throw new UnprocessableEntityException("The nb event with ID: " + nbeventId + " already has " +
"a related item");
- } else if (!StringUtils.endsWith(nbevent.getTopic(), "/PROJECT")) {
- return ControllerUtils.toEmptyResponse(HttpStatus.BAD_REQUEST);
}
Item relatedItem = itemService.find(context, relatedItemUUID);
diff --git a/dspace/config/dspace.cfg b/dspace/config/dspace.cfg
index f91352a33a..d497a3fd03 100644
--- a/dspace/config/dspace.cfg
+++ b/dspace/config/dspace.cfg
@@ -1631,7 +1631,7 @@ include = ${module_dir}/healthcheck.cfg
include = ${module_dir}/irus-statistics.cfg
include = ${module_dir}/oai.cfg
include = ${module_dir}/openaire-client.cfg
-include = ${module_dir}/oaire-nbevents.cfg
+include = ${module_dir}/nbevents.cfg
include = ${module_dir}/rdf.cfg
include = ${module_dir}/rest.cfg
include = ${module_dir}/iiif.cfg
diff --git a/dspace/config/modules/nbevents.cfg b/dspace/config/modules/nbevents.cfg
new file mode 100644
index 0000000000..d2b5dd12f9
--- /dev/null
+++ b/dspace/config/modules/nbevents.cfg
@@ -0,0 +1,21 @@
+#---------------------------------------------------------------#
+#-------OAIRE Notification Broker Events CONFIGURATIONS---------#
+#---------------------------------------------------------------#
+# Configuration properties used by data correction service #
+#---------------------------------------------------------------#
+nbevents.solr.server = ${solr.server}/${solr.multicorePrefix}nbevent
+# A POST to these url(s) will be done to notify oaire of decision taken for each nbevents
+nbevents.openaire.acknowledge-url = https://beta.api-broker.openaire.eu/feedback/events
+#nbevents.openaire.acknowledge-url
+
+# The list of the supported events incoming from openaire (see also dspace/config/spring/api/nbevents.xml)
+# add missing abstract suggestion
+nbevents.openaire.import.topic = ENRICH/MISSING/ABSTRACT
+# add missing publication id suggestion
+nbevents.openaire.import.topic = ENRICH/MISSING/PID
+# add more publication id suggestion
+nbevents.openaire.import.topic = ENRICH/MORE/PID
+# add missing project suggestion
+nbevents.openaire.import.topic = ENRICH/MISSING/PROJECT
+# add more project suggestion
+nbevents.openaire.import.topic = ENRICH/MORE/PROJECT
\ No newline at end of file
diff --git a/dspace/config/modules/oaire-nbevents.cfg b/dspace/config/modules/oaire-nbevents.cfg
deleted file mode 100644
index 993a637a18..0000000000
--- a/dspace/config/modules/oaire-nbevents.cfg
+++ /dev/null
@@ -1,14 +0,0 @@
-#---------------------------------------------------------------#
-#-------OAIRE Notification Broker Events CONFIGURATIONS---------#
-#---------------------------------------------------------------#
-# Configuration properties used by data correction service #
-#---------------------------------------------------------------#
-oaire-nbevents.solr.server = ${solr.server}/${solr.multicorePrefix}nbevent
-# A POST to these url(s) will be done to notify oaire of decision taken for each nbevents
-openaire-nbevents.acknowledge-url = https://beta.api-broker.openaire.eu/feedback/events
-#openaire-nbevents.acknowledge-url =
-oaire-nbevents.import.topic = ENRICH/MISSING/ABSTRACT
-oaire-nbevents.import.topic = ENRICH/MISSING/PID
-oaire-nbevents.import.topic = ENRICH/MORE/PID
-oaire-nbevents.import.topic = ENRICH/MISSING/PROJECT
-oaire-nbevents.import.topic = ENRICH/MORE/PROJECT
\ No newline at end of file
diff --git a/dspace/config/spring/api/nbevents.xml b/dspace/config/spring/api/nbevents.xml
index 8cb039c39f..90acf62b18 100644
--- a/dspace/config/spring/api/nbevents.xml
+++ b/dspace/config/spring/api/nbevents.xml
@@ -18,8 +18,8 @@
+
@@ -50,6 +52,7 @@
+