mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
CST-10635 split Openaire and Coar messages
This commit is contained in:
@@ -9,6 +9,7 @@ package org.dspace.app.ldn.action;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.dspace.app.ldn.model.Notification;
|
||||
@@ -17,10 +18,17 @@ import org.dspace.content.QAEvent;
|
||||
import org.dspace.content.service.ItemService;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.qaevent.service.QAEventService;
|
||||
import org.dspace.qaevent.service.dto.NotifyMessageDTO;
|
||||
import org.dspace.services.ConfigurationService;
|
||||
import org.dspace.web.ContextUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
|
||||
/**
|
||||
* Implementation for LDN Correction Action. It creates a QA Event according to the LDN Message received *
|
||||
* @author Francesco Bacchelli (francesco.bacchelli at 4science.it)
|
||||
*
|
||||
*/
|
||||
public class LDNCorrectionAction implements LDNAction {
|
||||
|
||||
private static final Logger log = LogManager.getLogger(LDNEmailAction.class);
|
||||
@@ -39,27 +47,29 @@ public class LDNCorrectionAction implements LDNAction {
|
||||
ActionStatus result = ActionStatus.ABORT;
|
||||
Context context = ContextUtil.obtainCurrentRequestContext();
|
||||
String itemName = itemService.getName(item);
|
||||
String value = "";
|
||||
QAEvent qaEvent = null;
|
||||
if (notification.getObject().getIetfCiteAs() != null) {
|
||||
value = notification.getObject().getIetfCiteAs();
|
||||
qaEvent = new QAEvent(QAEvent.COAR_NOTIFY,
|
||||
if (notification.getObject() != null) {
|
||||
String citeAs = notification.getObject().getIetfCiteAs();
|
||||
if (citeAs == null || citeAs.isEmpty()) {
|
||||
citeAs = notification.getObject().getId();
|
||||
}
|
||||
NotifyMessageDTO message = new NotifyMessageDTO();
|
||||
message.setHref(citeAs);
|
||||
message.setRelationship(notification.getObject().getAsRelationship());
|
||||
if (notification.getOrigin() != null) {
|
||||
message.setServiceId(notification.getOrigin().getId());
|
||||
message.setServiceName(notification.getOrigin().getInbox());
|
||||
}
|
||||
Gson gson = new Gson();
|
||||
// "oai:www.dspace.org:" + item.getHandle(),
|
||||
qaEvent = new QAEvent(QAEvent.COAR_NOTIFY_SOURCE,
|
||||
notification.getObject().getId(), item.getID().toString(), itemName,
|
||||
this.getQaEventTopic(), 1d,
|
||||
"{\"abstracts[0]\": \"" + value + "\"}"
|
||||
, new Date());
|
||||
} else if (notification.getObject().getAsRelationship() != null) {
|
||||
String type = notification.getObject().getAsRelationship();
|
||||
value = notification.getObject().getAsObject();
|
||||
qaEvent = new QAEvent(QAEvent.COAR_NOTIFY,
|
||||
notification.getObject().getId(), item.getID().toString(), itemName,
|
||||
this.getQaEventTopic(), 1d,
|
||||
"{\"pids[0].value\":\"" + value + "\"," +
|
||||
"\"pids[0].type\":\"" + type + "\"}"
|
||||
gson.toJson(message)
|
||||
, new Date());
|
||||
qaEventService.store(context, qaEvent);
|
||||
result = ActionStatus.CONTINUE;
|
||||
}
|
||||
qaEventService.store(context, qaEvent);
|
||||
result = ActionStatus.CONTINUE;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@@ -22,7 +22,6 @@ import org.apache.commons.lang.time.DateUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.dspace.app.ldn.LDNMessageEntity;
|
||||
import org.dspace.app.ldn.LDNQueueExtractor;
|
||||
import org.dspace.app.ldn.LDNRouter;
|
||||
import org.dspace.app.ldn.NotifyServiceEntity;
|
||||
import org.dspace.app.ldn.dao.LDNMessageDao;
|
||||
@@ -38,6 +37,7 @@ import org.dspace.handle.service.HandleService;
|
||||
import org.dspace.services.ConfigurationService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of {@link LDNMessageService}
|
||||
*
|
||||
@@ -58,7 +58,7 @@ public class LDNMessageServiceImpl implements LDNMessageService {
|
||||
@Autowired(required = true)
|
||||
private LDNRouter ldnRouter;
|
||||
|
||||
private static final Logger log = org.apache.logging.log4j.LogManager.getLogger(LDNQueueExtractor.class);
|
||||
private static final Logger log = org.apache.logging.log4j.LogManager.getLogger(LDNMessageServiceImpl.class);
|
||||
|
||||
protected LDNMessageServiceImpl() {
|
||||
|
||||
|
@@ -13,6 +13,7 @@ import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Date;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import org.dspace.qaevent.service.dto.NotifyMessageDTO;
|
||||
import org.dspace.qaevent.service.dto.OpenaireMessageDTO;
|
||||
import org.dspace.qaevent.service.dto.QAMessageDTO;
|
||||
import org.dspace.util.RawJsonDeserializer;
|
||||
@@ -21,6 +22,7 @@ import org.dspace.util.RawJsonDeserializer;
|
||||
* This class represent the Quality Assurance broker data as loaded in our solr
|
||||
* qaevent core
|
||||
*
|
||||
* @author Andrea Bollini (andrea.bollini at 4science.it)
|
||||
*/
|
||||
public class QAEvent {
|
||||
public static final char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e',
|
||||
@@ -30,7 +32,7 @@ public class QAEvent {
|
||||
public static final String DISCARDED = "discarded";
|
||||
|
||||
public static final String OPENAIRE_SOURCE = "openaire";
|
||||
public static final String COAR_NOTIFY = "coar-notify";
|
||||
public static final String COAR_NOTIFY_SOURCE = "coar-notify";
|
||||
|
||||
private String source;
|
||||
|
||||
@@ -195,13 +197,18 @@ public class QAEvent {
|
||||
}
|
||||
|
||||
public Class<? extends QAMessageDTO> getMessageDtoClass() {
|
||||
Class<? extends QAMessageDTO> result = null;
|
||||
switch (getSource()) {
|
||||
case OPENAIRE_SOURCE:
|
||||
case COAR_NOTIFY:
|
||||
return OpenaireMessageDTO.class;
|
||||
result = OpenaireMessageDTO.class;
|
||||
break;
|
||||
case COAR_NOTIFY_SOURCE:
|
||||
result = NotifyMessageDTO.class;
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown event's source: " + getSource());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,82 @@
|
||||
/**
|
||||
* 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.action;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Map;
|
||||
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.content.service.ItemService;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.qaevent.QualityAssuranceAction;
|
||||
import org.dspace.qaevent.service.dto.QAMessageDTO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* Implementation of {@link QualityAssuranceAction} that add a specific metadata on the given
|
||||
* item based on the child class implementation.
|
||||
*
|
||||
* @author Francesco Bacchelli (francesco.bacchelli at 4science.it)
|
||||
*
|
||||
*/
|
||||
public abstract class AMetadataMapAction implements QualityAssuranceAction {
|
||||
public static final String DEFAULT = "default";
|
||||
|
||||
private Map<String, String> types;
|
||||
@Autowired
|
||||
private ItemService itemService;
|
||||
|
||||
public void setItemService(ItemService itemService) {
|
||||
this.itemService = itemService;
|
||||
}
|
||||
|
||||
public Map<String, String> getTypes() {
|
||||
return types;
|
||||
}
|
||||
|
||||
public void setTypes(Map<String, String> types) {
|
||||
this.types = types;
|
||||
}
|
||||
|
||||
public abstract String extractMetadataType(QAMessageDTO message);
|
||||
public abstract String extractMetadataValue(QAMessageDTO message);
|
||||
|
||||
/**
|
||||
* Apply the correction on one metadata field of the given item based on the
|
||||
* openaire message type.
|
||||
*/
|
||||
@Override
|
||||
public void applyCorrection(Context context, Item item, Item relatedItem, QAMessageDTO message) {
|
||||
|
||||
try {
|
||||
String targetMetadata = types.get(extractMetadataType(message));
|
||||
if (targetMetadata == null) {
|
||||
targetMetadata = types.get(DEFAULT);
|
||||
}
|
||||
String[] metadata = splitMetadata(targetMetadata);
|
||||
itemService.addMetadata(context, item, metadata[0], metadata[1], metadata[2], null,
|
||||
extractMetadataValue(message));
|
||||
itemService.update(context, item);
|
||||
} catch (SQLException | AuthorizeException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public String[] splitMetadata(String metadata) {
|
||||
String[] result = new String[3];
|
||||
String[] split = metadata.split("\\.");
|
||||
result[0] = split[0];
|
||||
result[1] = split[1];
|
||||
if (split.length == 3) {
|
||||
result[2] = split[2];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
@@ -0,0 +1,65 @@
|
||||
/**
|
||||
* 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.action;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.content.service.ItemService;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.qaevent.QualityAssuranceAction;
|
||||
import org.dspace.qaevent.service.dto.QAMessageDTO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* Abstract class for Simple metadata action.
|
||||
*
|
||||
* @author Francesco Bacchelli (francesco.bacchelli at 4science.it)
|
||||
*
|
||||
*/
|
||||
public abstract class ASimpleMetadataAction implements QualityAssuranceAction {
|
||||
private String metadata;
|
||||
private String metadataSchema;
|
||||
private String metadataElement;
|
||||
private String metadataQualifier;
|
||||
@Autowired
|
||||
private ItemService itemService;
|
||||
|
||||
public void setItemService(ItemService itemService) {
|
||||
this.itemService = itemService;
|
||||
}
|
||||
|
||||
public String getMetadata() {
|
||||
return metadata;
|
||||
}
|
||||
|
||||
public void setMetadata(String metadata) {
|
||||
this.metadata = metadata;
|
||||
String[] split = metadata.split("\\.");
|
||||
this.metadataSchema = split[0];
|
||||
this.metadataElement = split[1];
|
||||
if (split.length == 3) {
|
||||
this.metadataQualifier = split[2];
|
||||
}
|
||||
}
|
||||
|
||||
public abstract String extractMetadataValue(QAMessageDTO message);
|
||||
|
||||
@Override
|
||||
public void applyCorrection(Context context, Item item, Item relatedItem, QAMessageDTO message) {
|
||||
try {
|
||||
String metadataValue = extractMetadataValue(message);
|
||||
itemService.addMetadata(context, item, metadataSchema, metadataElement, metadataQualifier, null,
|
||||
metadataValue);
|
||||
itemService.update(context, item);
|
||||
} catch (SQLException | AuthorizeException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* 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.action;
|
||||
|
||||
import org.dspace.qaevent.service.dto.NotifyMessageDTO;
|
||||
import org.dspace.qaevent.service.dto.QAMessageDTO;
|
||||
|
||||
/**
|
||||
* Openaire Implementation {@link AMetadataMapAction}
|
||||
*
|
||||
* @author Francesco Bacchelli (francesco.bacchelli at 4science.it)
|
||||
*
|
||||
*/
|
||||
public class QANotifyMetadataMapAction extends AMetadataMapAction {
|
||||
|
||||
@Override
|
||||
public String extractMetadataType(QAMessageDTO message) {
|
||||
return ((NotifyMessageDTO)message).getRelationship();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String extractMetadataValue(QAMessageDTO message) {
|
||||
return ((NotifyMessageDTO)message).getHref();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* 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.action;
|
||||
|
||||
import org.dspace.qaevent.QualityAssuranceAction;
|
||||
import org.dspace.qaevent.service.dto.NotifyMessageDTO;
|
||||
import org.dspace.qaevent.service.dto.QAMessageDTO;
|
||||
|
||||
/**
|
||||
* Implementation of {@link QualityAssuranceAction} that add a simple metadata to the given
|
||||
* item.
|
||||
*
|
||||
* @author Francesco Bacchelli (francesco.bacchelli at 4science.it)
|
||||
*
|
||||
*/
|
||||
public class QANotifySimpleMetadataAction extends ASimpleMetadataAction {
|
||||
|
||||
public String extractMetadataValue(QAMessageDTO message) {
|
||||
return ((NotifyMessageDTO) message).getHref();
|
||||
}
|
||||
}
|
@@ -7,80 +7,25 @@
|
||||
*/
|
||||
package org.dspace.qaevent.action;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Map;
|
||||
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.content.service.ItemService;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.qaevent.QualityAssuranceAction;
|
||||
import org.dspace.qaevent.service.dto.OpenaireMessageDTO;
|
||||
import org.dspace.qaevent.service.dto.QAMessageDTO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* Implementation of {@link QualityAssuranceAction} that add a specific metadata on the given
|
||||
* item based on the OPENAIRE message type.
|
||||
*
|
||||
* @author Andrea Bollini (andrea.bollini at 4science.it)
|
||||
* Openaire Implementation {@link AMetadataMapAction}
|
||||
*
|
||||
* @author Francesco Bacchelli (francesco.bacchelli at 4science.it)
|
||||
*
|
||||
*/
|
||||
public class QAOpenaireMetadataMapAction implements QualityAssuranceAction {
|
||||
public static final String DEFAULT = "default";
|
||||
public class QAOpenaireMetadataMapAction extends AMetadataMapAction {
|
||||
|
||||
private Map<String, String> types;
|
||||
@Autowired
|
||||
private ItemService itemService;
|
||||
|
||||
public void setItemService(ItemService itemService) {
|
||||
this.itemService = itemService;
|
||||
}
|
||||
|
||||
public Map<String, String> getTypes() {
|
||||
return types;
|
||||
}
|
||||
|
||||
public void setTypes(Map<String, String> types) {
|
||||
this.types = types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the correction on one metadata field of the given item based on the
|
||||
* openaire message type.
|
||||
*/
|
||||
@Override
|
||||
public void applyCorrection(Context context, Item item, Item relatedItem, QAMessageDTO message) {
|
||||
|
||||
if (!(message instanceof OpenaireMessageDTO)) {
|
||||
throw new IllegalArgumentException("Unsupported message type: " + message.getClass());
|
||||
}
|
||||
|
||||
OpenaireMessageDTO openaireMessage = (OpenaireMessageDTO) message;
|
||||
|
||||
try {
|
||||
String targetMetadata = types.get(openaireMessage.getType());
|
||||
if (targetMetadata == null) {
|
||||
targetMetadata = types.get(DEFAULT);
|
||||
}
|
||||
String[] metadata = splitMetadata(targetMetadata);
|
||||
itemService.addMetadata(context, item, metadata[0], metadata[1], metadata[2], null,
|
||||
openaireMessage.getValue());
|
||||
itemService.update(context, item);
|
||||
} catch (SQLException | AuthorizeException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
public String extractMetadataType(QAMessageDTO message) {
|
||||
return ((OpenaireMessageDTO)message).getType();
|
||||
}
|
||||
|
||||
public String[] splitMetadata(String metadata) {
|
||||
String[] result = new String[3];
|
||||
String[] split = metadata.split("\\.");
|
||||
result[0] = split[0];
|
||||
result[1] = split[1];
|
||||
if (split.length == 3) {
|
||||
result[2] = split[2];
|
||||
}
|
||||
return result;
|
||||
@Override
|
||||
public String extractMetadataValue(QAMessageDTO message) {
|
||||
return ((OpenaireMessageDTO)message).getValue();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -7,16 +7,9 @@
|
||||
*/
|
||||
package org.dspace.qaevent.action;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.content.service.ItemService;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.qaevent.QualityAssuranceAction;
|
||||
import org.dspace.qaevent.service.dto.OpenaireMessageDTO;
|
||||
import org.dspace.qaevent.service.dto.QAMessageDTO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* Implementation of {@link QualityAssuranceAction} that add a simple metadata to the given
|
||||
@@ -25,40 +18,9 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
* @author Andrea Bollini (andrea.bollini at 4science.it)
|
||||
*
|
||||
*/
|
||||
public class QAOpenaireSimpleMetadataAction implements QualityAssuranceAction {
|
||||
private String metadata;
|
||||
private String metadataSchema;
|
||||
private String metadataElement;
|
||||
private String metadataQualifier;
|
||||
@Autowired
|
||||
private ItemService itemService;
|
||||
public class QAOpenaireSimpleMetadataAction extends ASimpleMetadataAction {
|
||||
|
||||
public void setItemService(ItemService itemService) {
|
||||
this.itemService = itemService;
|
||||
}
|
||||
|
||||
public String getMetadata() {
|
||||
return metadata;
|
||||
}
|
||||
|
||||
public void setMetadata(String metadata) {
|
||||
this.metadata = metadata;
|
||||
String[] split = metadata.split("\\.");
|
||||
this.metadataSchema = split[0];
|
||||
this.metadataElement = split[1];
|
||||
if (split.length == 3) {
|
||||
this.metadataQualifier = split[2];
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyCorrection(Context context, Item item, Item relatedItem, QAMessageDTO message) {
|
||||
try {
|
||||
itemService.addMetadata(context, item, metadataSchema, metadataElement, metadataQualifier, null,
|
||||
((OpenaireMessageDTO) message).getAbstracts());
|
||||
itemService.update(context, item);
|
||||
} catch (SQLException | AuthorizeException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
public String extractMetadataValue(QAMessageDTO message) {
|
||||
return ((OpenaireMessageDTO) message).getAbstracts();
|
||||
}
|
||||
}
|
||||
|
@@ -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.qaevent.service.dto;
|
||||
|
||||
/**
|
||||
* Implementation of {@link QAMessageDTO} that model message coming from COAR NOTIFY.
|
||||
*
|
||||
* @author Francesco Bacchelli (francesco.bacchelli at 4science.it)
|
||||
*
|
||||
*/
|
||||
public class NotifyMessageDTO implements QAMessageDTO {
|
||||
|
||||
private String serviceName;
|
||||
|
||||
private String serviceId;
|
||||
|
||||
private String href;
|
||||
|
||||
private String relationship;
|
||||
|
||||
public String getServiceName() {
|
||||
return serviceName;
|
||||
}
|
||||
|
||||
public void setServiceName(String serviceName) {
|
||||
this.serviceName = serviceName;
|
||||
}
|
||||
|
||||
public String getServiceId() {
|
||||
return serviceId;
|
||||
}
|
||||
|
||||
public void setServiceId(String serviceId) {
|
||||
this.serviceId = serviceId;
|
||||
}
|
||||
|
||||
public String getHref() {
|
||||
return href;
|
||||
}
|
||||
|
||||
public void setHref(String href) {
|
||||
this.href = href;
|
||||
}
|
||||
|
||||
public String getRelationship() {
|
||||
return relationship;
|
||||
}
|
||||
|
||||
public void setRelationship(String relationship) {
|
||||
this.relationship = relationship;
|
||||
}
|
||||
|
||||
}
|
@@ -24,6 +24,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.json.JsonMapper;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.solr.client.solrj.SolrClient;
|
||||
import org.apache.solr.client.solrj.SolrQuery;
|
||||
import org.apache.solr.client.solrj.SolrQuery.ORDER;
|
||||
@@ -61,6 +62,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
*/
|
||||
public class QAEventServiceImpl implements QAEventService {
|
||||
|
||||
private static final Logger log = org.apache.logging.log4j.LogManager.getLogger(QAEventServiceImpl.class);
|
||||
|
||||
@Autowired(required = true)
|
||||
protected ConfigurationService configurationService;
|
||||
|
||||
@@ -516,19 +519,26 @@ public class QAEventServiceImpl implements QAEventService {
|
||||
}
|
||||
|
||||
private String getResourceUUID(Context context, String originalId) throws Exception {
|
||||
String id = getHandleFromOriginalId(originalId);
|
||||
if (id != null) {
|
||||
Item item = (Item) handleService.resolveToObject(context, id);
|
||||
if (item != null) {
|
||||
final String itemUuid = item.getID().toString();
|
||||
context.uncacheEntity(item);
|
||||
return itemUuid;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException("Malformed originalId " + originalId);
|
||||
Item item = null;
|
||||
try {
|
||||
String handleResolver = configurationService.getProperty("handle.canonical.prefix", "https://hdl.handle.net/");
|
||||
String handle = originalId.substring(handleResolver.length());
|
||||
item = (Item) handleService.resolveToObject(context, handle);
|
||||
} catch (Exception e) {
|
||||
log.warn("OriginalId given is not an handle url", originalId);
|
||||
}
|
||||
if (item == null) {
|
||||
String id = getHandleFromOriginalId(originalId);
|
||||
if (id != null) {
|
||||
item = (Item) handleService.resolveToObject(context, id);
|
||||
}
|
||||
}
|
||||
if (item != null) {
|
||||
final String itemUuid = item.getID().toString();
|
||||
context.uncacheEntity(item);
|
||||
return itemUuid;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// oai:www.openstarts.units.it:10077/21486
|
||||
@@ -562,7 +572,7 @@ public class QAEventServiceImpl implements QAEventService {
|
||||
|
||||
private String[] getSupportedSources() {
|
||||
return configurationService.getArrayProperty("qaevent.sources",
|
||||
new String[] { QAEvent.OPENAIRE_SOURCE, QAEvent.COAR_NOTIFY });
|
||||
new String[] { QAEvent.OPENAIRE_SOURCE, QAEvent.COAR_NOTIFY_SOURCE });
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -8,6 +8,7 @@
|
||||
package org.dspace.qaevent.script;
|
||||
|
||||
import static java.util.List.of;
|
||||
import static org.dspace.content.QAEvent.COAR_NOTIFY_SOURCE;
|
||||
import static org.dspace.content.QAEvent.OPENAIRE_SOURCE;
|
||||
import static org.dspace.matcher.QAEventMatcher.pendingOpenaireEventWith;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
@@ -54,6 +55,7 @@ import org.dspace.qaevent.service.impl.BrokerClientFactoryImpl;
|
||||
import org.dspace.utils.DSpace;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
@@ -458,7 +460,12 @@ public class OpenaireEventsImportIT extends AbstractIntegrationTestWithDatabase
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Improper test for ENRICH/MORE/REVIEW qa. It has the COAR_NOTIFY source
|
||||
* which must be tested via LDNMessage {@link LDNInboxControllerIT}
|
||||
*/
|
||||
@Test
|
||||
@Ignore
|
||||
public void testImportFromFileEventMoreReview() throws Exception {
|
||||
|
||||
context.turnOffAuthorisationSystem();
|
||||
@@ -475,7 +482,7 @@ public class OpenaireEventsImportIT extends AbstractIntegrationTestWithDatabase
|
||||
assertThat(qaEventService.findAllTopics(0, 20), contains(
|
||||
QATopicMatcher.with("ENRICH/MORE/REVIEW", 1L)));
|
||||
|
||||
assertThat(qaEventService.findAllSources(0, 20), hasItem(QASourceMatcher.with(OPENAIRE_SOURCE, 1L)));
|
||||
assertThat(qaEventService.findAllSources(0, 20), hasItem(QASourceMatcher.with(COAR_NOTIFY_SOURCE, 1L)));
|
||||
|
||||
verifyNoInteractions(mockBrokerClient);
|
||||
}
|
||||
|
@@ -1,11 +0,0 @@
|
||||
[
|
||||
{
|
||||
"originalId": "oai:www.openstarts.units.it:123456789/99999",
|
||||
"title": "Test Publication",
|
||||
"topic": "ENRICH/MORE/REVIEW",
|
||||
"trust": 1.0,
|
||||
"message": {
|
||||
"abstracts[0]": "More review"
|
||||
}
|
||||
}
|
||||
]
|
@@ -14,11 +14,13 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.json.JsonMapper;
|
||||
import org.dspace.app.rest.model.NotifyQAEventMessageRest;
|
||||
import org.dspace.app.rest.model.OpenaireQAEventMessageRest;
|
||||
import org.dspace.app.rest.model.QAEventMessageRest;
|
||||
import org.dspace.app.rest.model.QAEventRest;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.content.QAEvent;
|
||||
import org.dspace.qaevent.service.dto.NotifyMessageDTO;
|
||||
import org.dspace.qaevent.service.dto.OpenaireMessageDTO;
|
||||
import org.dspace.qaevent.service.dto.QAMessageDTO;
|
||||
import org.dspace.services.ConfigurationService;
|
||||
@@ -72,10 +74,22 @@ public class QAEventConverter implements DSpaceConverter<QAEvent, QAEventRest> {
|
||||
private QAEventMessageRest convertMessage(QAMessageDTO dto) {
|
||||
if (dto instanceof OpenaireMessageDTO) {
|
||||
return convertOpenaireMessage(dto);
|
||||
} else if (dto instanceof NotifyMessageDTO) {
|
||||
return convertNotifyMessage(dto);
|
||||
}
|
||||
throw new IllegalArgumentException("Unknown message type: " + dto.getClass());
|
||||
}
|
||||
|
||||
private QAEventMessageRest convertNotifyMessage(QAMessageDTO dto) {
|
||||
NotifyMessageDTO notifyDto = (NotifyMessageDTO) dto;
|
||||
NotifyQAEventMessageRest message = new NotifyQAEventMessageRest();
|
||||
message.setServiceName(notifyDto.getServiceName());
|
||||
message.setServiceId(notifyDto.getServiceId());
|
||||
message.setHref(notifyDto.getHref());
|
||||
message.setRelationship(notifyDto.getRelationship());
|
||||
return message;
|
||||
}
|
||||
|
||||
private QAEventMessageRest convertOpenaireMessage(QAMessageDTO dto) {
|
||||
OpenaireMessageDTO openaireDto = (OpenaireMessageDTO) dto;
|
||||
OpenaireQAEventMessageRest message = new OpenaireQAEventMessageRest();
|
||||
|
@@ -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.app.rest.model;
|
||||
|
||||
/**
|
||||
* Implementation of {@link QAEventMessageRest} related to COAR NOTIFY events.
|
||||
*
|
||||
* @author Francesco Bacchelli (francesco.bacchelli at 4science.it)
|
||||
*
|
||||
*/
|
||||
public class NotifyQAEventMessageRest implements QAEventMessageRest {
|
||||
|
||||
private String serviceName;
|
||||
|
||||
private String serviceId;
|
||||
|
||||
private String href;
|
||||
|
||||
private String relationship;
|
||||
|
||||
public String getServiceName() {
|
||||
return serviceName;
|
||||
}
|
||||
|
||||
public void setServiceName(String serviceName) {
|
||||
this.serviceName = serviceName;
|
||||
}
|
||||
|
||||
public String getServiceId() {
|
||||
return serviceId;
|
||||
}
|
||||
|
||||
public void setServiceId(String serviceId) {
|
||||
this.serviceId = serviceId;
|
||||
}
|
||||
|
||||
public String getHref() {
|
||||
return href;
|
||||
}
|
||||
|
||||
public void setHref(String href) {
|
||||
this.href = href;
|
||||
}
|
||||
|
||||
public String getRelationship() {
|
||||
return relationship;
|
||||
}
|
||||
|
||||
public void setRelationship(String relationship) {
|
||||
this.relationship = relationship;
|
||||
}
|
||||
|
||||
}
|
@@ -7,9 +7,9 @@
|
||||
*/
|
||||
package org.dspace.app.rest;
|
||||
|
||||
import static org.dspace.content.QAEvent.OPENAIRE_SOURCE;
|
||||
import static org.dspace.content.QAEvent.COAR_NOTIFY_SOURCE;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||
@@ -21,12 +21,14 @@ import java.nio.charset.Charset;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.dspace.app.ldn.LDNMessageEntity;
|
||||
import org.dspace.app.ldn.NotifyServiceEntity;
|
||||
import org.dspace.app.ldn.model.Notification;
|
||||
import org.dspace.app.ldn.service.LDNMessageService;
|
||||
import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
|
||||
import org.dspace.builder.CollectionBuilder;
|
||||
import org.dspace.builder.CommunityBuilder;
|
||||
import org.dspace.builder.ItemBuilder;
|
||||
import org.dspace.builder.NotifyServiceBuilder;
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.content.Community;
|
||||
import org.dspace.content.Item;
|
||||
@@ -49,49 +51,28 @@ public class LDNInboxControllerIT extends AbstractControllerIntegrationTest {
|
||||
|
||||
private QAEventService qaEventService = new DSpace().getSingletonService(QAEventService.class);
|
||||
|
||||
@Test
|
||||
public void ldnInboxEndorsementActionTest() throws Exception {
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
Community community = CommunityBuilder.createCommunity(context).withName("community").build();
|
||||
Collection collection = CollectionBuilder.createCollection(context, community).build();
|
||||
Item item = ItemBuilder.createItem(context, collection).build();
|
||||
String object = configurationService.getProperty("dspace.ui.url") + "/handle/" + item.getHandle();
|
||||
|
||||
context.restoreAuthSystemState();
|
||||
|
||||
InputStream offerEndorsementStream = getClass().getResourceAsStream("ldn_offer_endorsement_object.json");
|
||||
String offerEndorsementJson = IOUtils.toString(offerEndorsementStream, Charset.defaultCharset());
|
||||
offerEndorsementStream.close();
|
||||
String message = offerEndorsementJson.replace("<<object>>", object);
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
Notification notification = mapper.readValue(message, Notification.class);
|
||||
|
||||
getClient(getAuthToken(admin.getEmail(), password))
|
||||
.perform(post("/ldn/inbox")
|
||||
.contentType("application/ld+json")
|
||||
.content(message))
|
||||
.andExpect(status().isAccepted());
|
||||
|
||||
LDNMessageEntity ldnMessage = ldnMessageService.find(context, notification.getId());
|
||||
checkStoredLDNMessage(notification, ldnMessage, object);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ldnInboxAnnounceEndorsementTest() throws Exception {
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
Community community = CommunityBuilder.createCommunity(context).withName("community").build();
|
||||
Collection collection = CollectionBuilder.createCollection(context, community).build();
|
||||
Item item = ItemBuilder.createItem(context, collection).build();
|
||||
String object = configurationService.getProperty("dspace.ui.url") + "/handle/" + item.getHandle();
|
||||
|
||||
String object_handle = item.getHandle();
|
||||
NotifyServiceEntity notifyServiceEntity =
|
||||
NotifyServiceBuilder.createNotifyServiceBuilder(context)
|
||||
.withName("service name")
|
||||
.withDescription("service description")
|
||||
.withUrl("service url")
|
||||
.withLdnUrl("https://overlay-journal.com/inbox/")
|
||||
.build();
|
||||
context.restoreAuthSystemState();
|
||||
|
||||
InputStream announceEndorsementStream = getClass().getResourceAsStream("ldn_announce_endorsement.json");
|
||||
String announceEndorsement = IOUtils.toString(announceEndorsementStream, Charset.defaultCharset());
|
||||
announceEndorsementStream.close();
|
||||
String message = announceEndorsement.replace("<<object>>", object);
|
||||
String message = announceEndorsement.replaceAll("<<object>>", object);
|
||||
message = message.replaceAll("<<object_handle>>", object);
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
Notification notification = mapper.readValue(message, Notification.class);
|
||||
@@ -105,12 +86,27 @@ public class LDNInboxControllerIT extends AbstractControllerIntegrationTest {
|
||||
checkStoredLDNMessage(notification, ldnMessage, object);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void ldnInboxAnnounceReviewTest() throws Exception {
|
||||
context.turnOffAuthorisationSystem();
|
||||
Community community = CommunityBuilder.createCommunity(context).withName("community").build();
|
||||
Collection collection = CollectionBuilder.createCollection(context, community).build();
|
||||
Item item = ItemBuilder.createItem(context, collection).build();
|
||||
InputStream announceReviewStream = getClass().getResourceAsStream("ldn_announce_review.json");
|
||||
String message = IOUtils.toString(announceReviewStream, Charset.defaultCharset());
|
||||
String object = configurationService.getProperty("dspace.ui.url") + "/handle/" + item.getHandle();
|
||||
String object_handle = item.getHandle();
|
||||
NotifyServiceEntity notifyServiceEntity =
|
||||
NotifyServiceBuilder.createNotifyServiceBuilder(context)
|
||||
.withName("service name")
|
||||
.withDescription("service description")
|
||||
.withUrl("service url")
|
||||
.withLdnUrl("https://review-service.com/inbox/")
|
||||
.build();
|
||||
String announceReview = IOUtils.toString(announceReviewStream, Charset.defaultCharset());
|
||||
announceReviewStream.close();
|
||||
String message = announceReview.replaceAll("<<object>>", object);
|
||||
message = message.replaceAll("<<object_handle>>", object);
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
Notification notification = mapper.readValue(message, Notification.class);
|
||||
getClient(getAuthToken(admin.getEmail(), password))
|
||||
@@ -118,9 +114,9 @@ public class LDNInboxControllerIT extends AbstractControllerIntegrationTest {
|
||||
.contentType("application/ld+json")
|
||||
.content(message))
|
||||
.andExpect(status().isAccepted());
|
||||
assertThat(qaEventService.findAllSources(0, 20), contains(QASourceMatcher.with(OPENAIRE_SOURCE, 1L)));
|
||||
assertThat(qaEventService.findAllSources(0, 20), hasItem(QASourceMatcher.with(COAR_NOTIFY_SOURCE, 1L)));
|
||||
|
||||
assertThat(qaEventService.findAllTopics(0, 20), contains(
|
||||
assertThat(qaEventService.findAllTopics(0, 20), hasItem(
|
||||
QATopicMatcher.with("ENRICH/MORE/REVIEW", 1L)));
|
||||
|
||||
}
|
||||
|
@@ -9,7 +9,7 @@
|
||||
"type": ["Service"]
|
||||
},
|
||||
"context": {
|
||||
"id": "https://research-organisation.org/repository/preprint/201203/421/",
|
||||
"id": "<<object>>",
|
||||
"ietf:cite-as": "https://doi.org/10.5555/12345680",
|
||||
"type": ["sorg:AboutPage"],
|
||||
"url": {
|
||||
@@ -24,7 +24,9 @@
|
||||
"id": "urn:uuid:94ecae35-dcfd-4182-8550-22c7164fe23f",
|
||||
"inReplyTo": "urn:uuid:0370c0fb-bb78-4a9b-87f5-bed307a509dd",
|
||||
"object": {
|
||||
"id": "<<object>>",
|
||||
"id": "<<object_handle>>",
|
||||
"id_oai": "oai:www.openstarts.units.it:<<object_handle>>",
|
||||
"id_old": "https://review-service.com/review/geo/202103/0021",
|
||||
"ietf:cite-as": "https://overlay-journal.com/articles/00001/",
|
||||
"type": [
|
||||
"Page",
|
||||
|
@@ -9,8 +9,8 @@
|
||||
"type": "Service"
|
||||
},
|
||||
"context": {
|
||||
"id": "oai:http://localhost:4000/handle:123456789/12",
|
||||
"ietf:cite-as": "https://doi.org/10.5555/12345680",
|
||||
"id": "<<object>>",
|
||||
"ietf:cite-as": "https://doi.org/10.5555/12345680",
|
||||
"type": "sorg:AboutPage",
|
||||
"url": {
|
||||
"id": "https://research-organisation.org/repository/preprint/201203/421/content.pdf",
|
||||
@@ -24,7 +24,7 @@
|
||||
"id": "urn:uuid:2f4ec582-109e-4952-a94a-b7d7615a8c69",
|
||||
"inReplyTo": "urn:uuid:0370c0fb-bb78-4a9b-87f5-bed307a509dd",
|
||||
"object": {
|
||||
"id": "https://review-service.com/review/geo/202103/0021",
|
||||
"id": "<<object_handle>>",
|
||||
"ietf:cite-as": "https://doi.org/10.3214/987654",
|
||||
"type": [
|
||||
"Document",
|
||||
|
@@ -55,10 +55,10 @@
|
||||
<bean id="AbstractMetadataAction" class="org.dspace.qaevent.action.QAOpenaireSimpleMetadataAction">
|
||||
<property name="metadata" value="dc.description.abstract" />
|
||||
</bean>
|
||||
<bean id="AddReviewMetadataAction" class="org.dspace.qaevent.action.QAOpenaireSimpleMetadataAction">
|
||||
<bean id="AddReviewMetadataAction" class="org.dspace.qaevent.action.QANotifySimpleMetadataAction">
|
||||
<property name="metadata" value="datacite.relation.isReviewedBy" />
|
||||
</bean>
|
||||
<bean id="AddEndorsedMetadataAction" class="org.dspace.qaevent.action.QAOpenaireSimpleMetadataAction">
|
||||
<bean id="AddEndorsedMetadataAction" class="org.dspace.qaevent.action.QANotifySimpleMetadataAction">
|
||||
<property name="metadata" value="notify.relation.endorsedBy"/>
|
||||
</bean>
|
||||
<!-- Add a new identifier to the given item, using the defined types mapping -->
|
||||
|
Reference in New Issue
Block a user