From c6075b51a06e8dcaca49232dada53e2365e40e27 Mon Sep 17 00:00:00 2001 From: frabacche Date: Fri, 1 Dec 2023 16:44:10 +0100 Subject: [PATCH] CST-12850 Announce Relationship first implementation w/o tests --- .../action/LDNRelationCorrectionAction.java | 105 ++++++++++++++++++ .../org/dspace/qaevent/QANotifyPatterns.java | 1 + .../QANotifyFormattedMetadataAction.java | 40 +++++++ dspace/config/spring/api/ldn-coar-notify.xml | 2 +- dspace/config/spring/api/qaevents.xml | 7 ++ 5 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 dspace-api/src/main/java/org/dspace/app/ldn/action/LDNRelationCorrectionAction.java create mode 100644 dspace-api/src/main/java/org/dspace/qaevent/action/QANotifyFormattedMetadataAction.java diff --git a/dspace-api/src/main/java/org/dspace/app/ldn/action/LDNRelationCorrectionAction.java b/dspace-api/src/main/java/org/dspace/app/ldn/action/LDNRelationCorrectionAction.java new file mode 100644 index 0000000000..7bd36412c7 --- /dev/null +++ b/dspace-api/src/main/java/org/dspace/app/ldn/action/LDNRelationCorrectionAction.java @@ -0,0 +1,105 @@ +/** + * 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.ldn.action; + +import java.math.BigDecimal; +import java.sql.SQLException; +import java.util.Date; + +import com.github.jsonldjava.utils.JsonUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.dspace.app.ldn.NotifyServiceEntity; +import org.dspace.app.ldn.model.Notification; +import org.dspace.app.ldn.service.LDNMessageService; +import org.dspace.content.Item; +import org.dspace.content.QAEvent; +import org.dspace.content.service.ItemService; +import org.dspace.core.Context; +import org.dspace.handle.service.HandleService; +import org.dspace.qaevent.service.QAEventService; +import org.dspace.qaevent.service.dto.NotifyMessageDTO; +import org.dspace.services.ConfigurationService; +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 LDNRelationCorrectionAction implements LDNAction { + + private static final Logger log = LogManager.getLogger(LDNEmailAction.class); + + private String qaEventTopic; + + @Autowired + private ConfigurationService configurationService; + @Autowired + protected ItemService itemService; + @Autowired + private QAEventService qaEventService; + @Autowired + private LDNMessageService ldnMessageService; + @Autowired + private HandleService handleService; + + @Override + public ActionStatus execute(Context context, Notification notification, Item item) throws Exception { + ActionStatus result = ActionStatus.ABORT; + String itemName = itemService.getName(item); + QAEvent qaEvent = null; + if (notification.getObject() != null) { + NotifyMessageDTO message = new NotifyMessageDTO(); + /*relationFormat.replace("[0]", notification.getObject().getAsRelationship()); + hrefValue = hrefValue.replace("[1]", notification.getObject().getAsSubject());*/ + message.setHref(notification.getObject().getAsSubject()); + message.setRelationship(notification.getObject().getAsRelationship()); + if (notification.getOrigin() != null) { + message.setServiceId(notification.getOrigin().getId()); + message.setServiceName(notification.getOrigin().getInbox()); + } + BigDecimal score = getScore(context, notification); + double doubleScoreValue = score != null ? score.doubleValue() : 0d; + qaEvent = new QAEvent(QAEvent.COAR_NOTIFY_SOURCE, + handleService.findHandle(context, item), item.getID().toString(), itemName, + this.getQaEventTopic(), doubleScoreValue, + JsonUtils.toString(message) + , new Date()); + qaEventService.store(context, qaEvent); + result = ActionStatus.CONTINUE; + } + + return result; + } + + private BigDecimal getScore(Context context, Notification notification) throws SQLException { + + if (notification.getOrigin() == null) { + return BigDecimal.ZERO; + } + + NotifyServiceEntity service = ldnMessageService.findNotifyService(context, notification.getOrigin()); + + if (service == null) { + return BigDecimal.ZERO; + } + + return service.getScore(); + } + + public String getQaEventTopic() { + return qaEventTopic; + } + + public void setQaEventTopic(String qaEventTopic) { + this.qaEventTopic = qaEventTopic; + } + +} diff --git a/dspace-api/src/main/java/org/dspace/qaevent/QANotifyPatterns.java b/dspace-api/src/main/java/org/dspace/qaevent/QANotifyPatterns.java index bc0d8dc1b8..b66bd9efb3 100644 --- a/dspace-api/src/main/java/org/dspace/qaevent/QANotifyPatterns.java +++ b/dspace-api/src/main/java/org/dspace/qaevent/QANotifyPatterns.java @@ -21,6 +21,7 @@ public class QANotifyPatterns { 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"; + public static final String TOPIC_ENRICH_MORE_LINK = "ENRICH/MORE/LINK"; /** * Default constructor diff --git a/dspace-api/src/main/java/org/dspace/qaevent/action/QANotifyFormattedMetadataAction.java b/dspace-api/src/main/java/org/dspace/qaevent/action/QANotifyFormattedMetadataAction.java new file mode 100644 index 0000000000..4c8919b958 --- /dev/null +++ b/dspace-api/src/main/java/org/dspace/qaevent/action/QANotifyFormattedMetadataAction.java @@ -0,0 +1,40 @@ +/** + * 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 QANotifyFormattedMetadataAction extends ASimpleMetadataAction { + + private String format; + + public String extractMetadataValue(QAMessageDTO message) { + NotifyMessageDTO mDTO = (NotifyMessageDTO) message; + String result = format.replace("[0]", mDTO.getRelationship()); + result = result.replace("[1]", mDTO.getHref()); + return result; + } + + public String getFormat() { + return format; + } + + public void setFormat(String format) { + this.format = format; + } + +} diff --git a/dspace/config/spring/api/ldn-coar-notify.xml b/dspace/config/spring/api/ldn-coar-notify.xml index 4bd06ebd6e..fe676a4b80 100644 --- a/dspace/config/spring/api/ldn-coar-notify.xml +++ b/dspace/config/spring/api/ldn-coar-notify.xml @@ -259,7 +259,7 @@ - + diff --git a/dspace/config/spring/api/qaevents.xml b/dspace/config/spring/api/qaevents.xml index fb6eef868b..20b7b1a4ea 100644 --- a/dspace/config/spring/api/qaevents.xml +++ b/dspace/config/spring/api/qaevents.xml @@ -44,6 +44,9 @@ + + + @@ -74,6 +77,10 @@ + + + +