mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-16 22:43:12 +00:00
Merged coar-notify-7 into coar-notify-7_CST-10632
This commit is contained in:
@@ -1,190 +0,0 @@
|
||||
/**
|
||||
* 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;
|
||||
|
||||
import static java.lang.String.format;
|
||||
import static java.lang.String.join;
|
||||
import static org.dspace.app.ldn.RdfMediaType.APPLICATION_JSON_LD;
|
||||
import static org.dspace.app.ldn.utility.LDNUtils.processContextResolverId;
|
||||
|
||||
import java.net.URI;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.dspace.app.ldn.converter.JsonLdHttpMessageConverter;
|
||||
import org.dspace.app.ldn.model.Actor;
|
||||
import org.dspace.app.ldn.model.Context;
|
||||
import org.dspace.app.ldn.model.Notification;
|
||||
import org.dspace.app.ldn.model.Object;
|
||||
import org.dspace.app.ldn.model.Service;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.content.MetadataField;
|
||||
import org.dspace.content.MetadataValue;
|
||||
import org.dspace.handle.service.HandleService;
|
||||
import org.dspace.services.ConfigurationService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
/**
|
||||
* Linked Data Notification business delegate to facilitate sending
|
||||
* notification.
|
||||
*/
|
||||
public class LDNBusinessDelegate {
|
||||
|
||||
private final static Logger log = LogManager.getLogger(LDNBusinessDelegate.class);
|
||||
|
||||
@Autowired
|
||||
private ConfigurationService configurationService;
|
||||
|
||||
@Autowired
|
||||
private HandleService handleService;
|
||||
|
||||
private final RestTemplate restTemplate;
|
||||
|
||||
/**
|
||||
* Initialize rest template with appropriate message converters.
|
||||
*/
|
||||
public LDNBusinessDelegate() {
|
||||
restTemplate = new RestTemplate();
|
||||
restTemplate.getMessageConverters().add(new JsonLdHttpMessageConverter());
|
||||
}
|
||||
|
||||
/**
|
||||
* Announce item release notification.
|
||||
*
|
||||
* @param item item released (deposited or updated)
|
||||
* @throws SQLException
|
||||
*/
|
||||
public void announceRelease(Item item) {
|
||||
String serviceIds = configurationService.getProperty("service.service-id.ldn");
|
||||
|
||||
for (String serviceId : serviceIds.split(",")) {
|
||||
doAnnounceRelease(item, serviceId.trim());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build and POST announce release notification to configured service LDN
|
||||
* inboxes.
|
||||
*
|
||||
* @param item associated item
|
||||
* @param serviceId service id for targer inbox
|
||||
*/
|
||||
public void doAnnounceRelease(Item item, String serviceId) {
|
||||
log.info("Announcing release of item {}", item.getID());
|
||||
|
||||
String dspaceServerUrl = configurationService.getProperty("dspace.server.url");
|
||||
String dspaceUIUrl = configurationService.getProperty("dspace.ui.url");
|
||||
String dspaceName = configurationService.getProperty("dspace.name");
|
||||
String dspaceLdnInboxUrl = configurationService.getProperty("ldn.notify.inbox");
|
||||
|
||||
log.info("DSpace Server URL {}", dspaceServerUrl);
|
||||
log.info("DSpace UI URL {}", dspaceUIUrl);
|
||||
log.info("DSpace Name {}", dspaceName);
|
||||
log.info("DSpace LDN Inbox URL {}", dspaceLdnInboxUrl);
|
||||
|
||||
String serviceUrl = configurationService.getProperty(join(".", "service", serviceId, "url"));
|
||||
String serviceInboxUrl = configurationService.getProperty(join(".", "service", serviceId, "inbox.url"));
|
||||
String serviceResolverUrl = configurationService.getProperty(join(".", "service", serviceId, "resolver.url"));
|
||||
|
||||
log.info("Target URL {}", serviceUrl);
|
||||
log.info("Target LDN Inbox URL {}", serviceInboxUrl);
|
||||
|
||||
Notification notification = new Notification();
|
||||
|
||||
notification.setId(format("urn:uuid:%s", UUID.randomUUID()));
|
||||
notification.addType("Announce");
|
||||
notification.addType("coar-notify:ReleaseAction");
|
||||
|
||||
Actor actor = new Actor();
|
||||
|
||||
actor.setId(dspaceUIUrl);
|
||||
actor.setName(dspaceName);
|
||||
actor.addType("Service");
|
||||
|
||||
Context context = new Context();
|
||||
|
||||
List<Context> isSupplementedBy = new ArrayList<>();
|
||||
|
||||
List<MetadataValue> metadata = item.getMetadata();
|
||||
for (MetadataValue metadatum : metadata) {
|
||||
MetadataField field = metadatum.getMetadataField();
|
||||
log.info("Metadata field {} with value {}", field, metadatum.getValue());
|
||||
if (field.getMetadataSchema().getName().equals("dc") &&
|
||||
field.getElement().equals("data") &&
|
||||
field.getQualifier().equals("uri")) {
|
||||
|
||||
String ietfCiteAs = metadatum.getValue();
|
||||
String resolverId = processContextResolverId(ietfCiteAs);
|
||||
String id = serviceResolverUrl != null
|
||||
? format("%s%s", serviceResolverUrl, resolverId)
|
||||
: ietfCiteAs;
|
||||
|
||||
Context supplement = new Context();
|
||||
supplement.setId(id);
|
||||
supplement.setIetfCiteAs(ietfCiteAs);
|
||||
supplement.addType("sorg:Dataset");
|
||||
|
||||
isSupplementedBy.add(supplement);
|
||||
}
|
||||
}
|
||||
|
||||
context.setIsSupplementedBy(isSupplementedBy);
|
||||
|
||||
Object object = new Object();
|
||||
|
||||
String itemUrl = handleService.getCanonicalForm(item.getHandle());
|
||||
|
||||
log.info("Item Handle URL {}", itemUrl);
|
||||
|
||||
log.info("Item URL {}", itemUrl);
|
||||
|
||||
object.setId(itemUrl);
|
||||
object.setIetfCiteAs(itemUrl);
|
||||
object.setTitle(item.getName());
|
||||
object.addType("sorg:ScholarlyArticle");
|
||||
|
||||
Service origin = new Service();
|
||||
origin.setId(dspaceUIUrl);
|
||||
origin.setInbox(dspaceLdnInboxUrl);
|
||||
origin.addType("Service");
|
||||
|
||||
Service target = new Service();
|
||||
target.setId(serviceUrl);
|
||||
target.setInbox(serviceInboxUrl);
|
||||
target.addType("Service");
|
||||
|
||||
notification.setActor(actor);
|
||||
notification.setContext(context);
|
||||
notification.setObject(object);
|
||||
notification.setOrigin(origin);
|
||||
notification.setTarget(target);
|
||||
|
||||
String serviceKey = configurationService.getProperty(join(".", "service", serviceId, "key"));
|
||||
String serviceKeyHeader = configurationService.getProperty(join(".", "service", serviceId, "key.header"));
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add("Content-Type", APPLICATION_JSON_LD.toString());
|
||||
if (serviceKey != null && serviceKeyHeader != null) {
|
||||
headers.add(serviceKeyHeader, serviceKey);
|
||||
}
|
||||
|
||||
HttpEntity<Notification> request = new HttpEntity<Notification>(notification, headers);
|
||||
|
||||
log.info("Announcing notification {}", request);
|
||||
|
||||
restTemplate.postForLocation(URI.create(target.getInbox()), request);
|
||||
}
|
||||
|
||||
}
|
@@ -9,6 +9,7 @@ package org.dspace.app.ldn.action;
|
||||
|
||||
import org.dspace.app.ldn.model.Notification;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.core.Context;
|
||||
|
||||
/**
|
||||
* An action that is run after a notification has been processed.
|
||||
@@ -19,11 +20,12 @@ public interface LDNAction {
|
||||
* Execute action for provided notification and item corresponding to the
|
||||
* notification context.
|
||||
*
|
||||
*@param context the context
|
||||
* @param notification the processed notification to perform action against
|
||||
* @param item the item corresponding to the notification context
|
||||
* @return ActionStatus the resulting status of the action
|
||||
* @throws Exception general exception that can be thrown while executing action
|
||||
*/
|
||||
public ActionStatus execute(Notification notification, Item item) throws Exception;
|
||||
public ActionStatus execute(Context context, Notification notification, Item item) throws Exception;
|
||||
|
||||
}
|
@@ -11,6 +11,7 @@ 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;
|
||||
@@ -20,11 +21,18 @@ 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.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,20 +47,38 @@ public class LDNCorrectionAction implements LDNAction {
|
||||
private QAEventService qaEventService;
|
||||
@Autowired
|
||||
private LDNMessageService ldnMessageService;
|
||||
@Autowired
|
||||
private HandleService handleService;
|
||||
|
||||
@Override
|
||||
public ActionStatus execute(Notification notification, Item item) throws Exception {
|
||||
ActionStatus result;
|
||||
Context context = ContextUtil.obtainCurrentRequestContext();
|
||||
//FIXME the original id should be just an (optional) identifier/reference of the event in
|
||||
// the external system. The target Item should be passed as a constructor argument
|
||||
QAEvent qaEvent = new QAEvent(QAEvent.COAR_NOTIFY,
|
||||
"oai:localhost:" + item.getHandle(), item.getID().toString(), item.getName(),
|
||||
this.getQaEventTopic(), getScore(context, notification).doubleValue(),
|
||||
"{\"abstracts[0]\": \"" + notification.getObject().getIetfCiteAs() + "\"}"
|
||||
, new Date());
|
||||
qaEventService.store(context, qaEvent);
|
||||
result = ActionStatus.CONTINUE;
|
||||
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) {
|
||||
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());
|
||||
}
|
||||
BigDecimal score = getScore(context, notification);
|
||||
double doubleScoreValue = score != null ? score.doubleValue() : 0d;
|
||||
/* String fullHandleUrl = configurationService.getProperty("dspace.ui.url") + "/handle/"
|
||||
+ handleService.findHandle(context, item); */
|
||||
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;
|
||||
}
|
||||
|
@@ -24,7 +24,6 @@ import org.dspace.core.Context;
|
||||
import org.dspace.core.Email;
|
||||
import org.dspace.core.I18nUtil;
|
||||
import org.dspace.services.ConfigurationService;
|
||||
import org.dspace.web.ContextUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
@@ -71,9 +70,7 @@ public class LDNEmailAction implements LDNAction {
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
public ActionStatus execute(Notification notification, Item item) throws Exception {
|
||||
Context context = ContextUtil.obtainCurrentRequestContext();
|
||||
|
||||
public ActionStatus execute(Context context, Notification notification, Item item) throws Exception {
|
||||
try {
|
||||
Locale supportedLocale = I18nUtil.getEPersonLocale(context.getCurrentUser());
|
||||
Email email = Email.getEmail(I18nUtil.getEmailFilename(supportedLocale, actionSendEmailTextFile));
|
||||
|
@@ -1,37 +0,0 @@
|
||||
/**
|
||||
* 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.factory;
|
||||
|
||||
import org.dspace.app.ldn.LDNBusinessDelegate;
|
||||
import org.dspace.services.factory.DSpaceServicesFactory;
|
||||
|
||||
/**
|
||||
* Abstract business delegate factory to provide ability to get instance from
|
||||
* dspace services factory.
|
||||
*/
|
||||
public abstract class LDNBusinessDelegateFactory {
|
||||
|
||||
/**
|
||||
* Abstract method to return the business delegate bean.
|
||||
*
|
||||
* @return LDNBusinessDelegate business delegate bean
|
||||
*/
|
||||
public abstract LDNBusinessDelegate getLDNBusinessDelegate();
|
||||
|
||||
/**
|
||||
* Static method to get the business delegate factory instance.
|
||||
*
|
||||
* @return LDNBusinessDelegateFactory business delegate factory from dspace
|
||||
* services factory
|
||||
*/
|
||||
public static LDNBusinessDelegateFactory getInstance() {
|
||||
return DSpaceServicesFactory.getInstance().getServiceManager()
|
||||
.getServiceByName("ldnBusinessDelegateFactory", LDNBusinessDelegateFactory.class);
|
||||
}
|
||||
|
||||
}
|
@@ -1,30 +0,0 @@
|
||||
/**
|
||||
* 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.factory;
|
||||
|
||||
import org.dspace.app.ldn.LDNBusinessDelegate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* Business delegate factory implementation that autowires business delegate for
|
||||
* static retrieval.
|
||||
*/
|
||||
public class LDNBusinessDelegateFactoryImpl extends LDNBusinessDelegateFactory {
|
||||
|
||||
@Autowired(required = true)
|
||||
private LDNBusinessDelegate ldnBusinessDelegate;
|
||||
|
||||
/**
|
||||
* @return LDNBusinessDelegate
|
||||
*/
|
||||
@Override
|
||||
public LDNBusinessDelegate getLDNBusinessDelegate() {
|
||||
return ldnBusinessDelegate;
|
||||
}
|
||||
|
||||
}
|
@@ -14,6 +14,15 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
*/
|
||||
public class Object extends Citation {
|
||||
|
||||
@JsonProperty("as:object")
|
||||
private String asObject;
|
||||
|
||||
@JsonProperty("as:relationship")
|
||||
private String asRelationship;
|
||||
|
||||
@JsonProperty("as:subject")
|
||||
private String asSubject;
|
||||
|
||||
@JsonProperty("sorg:name")
|
||||
private String title;
|
||||
|
||||
@@ -38,4 +47,28 @@ public class Object extends Citation {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getAsObject() {
|
||||
return asObject;
|
||||
}
|
||||
|
||||
public void setAsObject(String asObject) {
|
||||
this.asObject = asObject;
|
||||
}
|
||||
|
||||
public String getAsRelationship() {
|
||||
return asRelationship;
|
||||
}
|
||||
|
||||
public void setAsRelationship(String asRelationship) {
|
||||
this.asRelationship = asRelationship;
|
||||
}
|
||||
|
||||
public String getAsSubject() {
|
||||
return asSubject;
|
||||
}
|
||||
|
||||
public void setAsSubject(String asSubject) {
|
||||
this.asSubject = asSubject;
|
||||
}
|
||||
|
||||
}
|
@@ -88,7 +88,7 @@ public class LDNContextRepeater {
|
||||
}
|
||||
|
||||
JsonNode contextArrayNode = topContextNode.get(repeatOver);
|
||||
if (contextArrayNode.isNull()) {
|
||||
if (contextArrayNode == null || contextArrayNode.isNull()) {
|
||||
log.error("Notification context {} is not defined", repeatOver);
|
||||
return;
|
||||
}
|
||||
|
@@ -1,48 +0,0 @@
|
||||
/**
|
||||
* 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.processor;
|
||||
|
||||
/**
|
||||
* Instuctions for adding metadata during notification processing.
|
||||
*/
|
||||
public class LDNMetadataAdd extends LDNMetadataChange {
|
||||
|
||||
private String qualifier;
|
||||
|
||||
// velocity template with notification as it contexts
|
||||
private String valueTemplate;
|
||||
|
||||
/**
|
||||
* @return String
|
||||
*/
|
||||
public String getQualifier() {
|
||||
return qualifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param qualifier
|
||||
*/
|
||||
public void setQualifier(String qualifier) {
|
||||
this.qualifier = qualifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return String
|
||||
*/
|
||||
public String getValueTemplate() {
|
||||
return valueTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param valueTemplate
|
||||
*/
|
||||
public void setValueTemplate(String valueTemplate) {
|
||||
this.valueTemplate = valueTemplate;
|
||||
}
|
||||
|
||||
}
|
@@ -1,95 +0,0 @@
|
||||
/**
|
||||
* 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.processor;
|
||||
|
||||
import static org.dspace.app.ldn.LDNMetadataFields.ELEMENT;
|
||||
import static org.dspace.app.ldn.LDNMetadataFields.SCHEMA;
|
||||
import static org.dspace.content.Item.ANY;
|
||||
|
||||
/**
|
||||
* Base instructions for metadata change during notification processing.
|
||||
*/
|
||||
public abstract class LDNMetadataChange {
|
||||
|
||||
private String schema;
|
||||
|
||||
private String element;
|
||||
|
||||
private String language;
|
||||
|
||||
// velocity template with notification as its context
|
||||
private String conditionTemplate;
|
||||
|
||||
/**
|
||||
* Default coar schema, notify element, any language, and true condition to
|
||||
* apply metadata change.
|
||||
*/
|
||||
public LDNMetadataChange() {
|
||||
schema = SCHEMA;
|
||||
element = ELEMENT;
|
||||
language = ANY;
|
||||
conditionTemplate = "true";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return String
|
||||
*/
|
||||
public String getSchema() {
|
||||
return schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param schema
|
||||
*/
|
||||
public void setSchema(String schema) {
|
||||
this.schema = schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return String
|
||||
*/
|
||||
public String getElement() {
|
||||
return element;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param element
|
||||
*/
|
||||
public void setElement(String element) {
|
||||
this.element = element;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return String
|
||||
*/
|
||||
public String getLanguage() {
|
||||
return language;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param language
|
||||
*/
|
||||
public void setLanguage(String language) {
|
||||
this.language = language;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return String
|
||||
*/
|
||||
public String getConditionTemplate() {
|
||||
return conditionTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param conditionTemplate
|
||||
*/
|
||||
public void setConditionTemplate(String conditionTemplate) {
|
||||
this.conditionTemplate = conditionTemplate;
|
||||
}
|
||||
|
||||
}
|
@@ -9,36 +9,24 @@ package org.dspace.app.ldn.processor;
|
||||
|
||||
import static java.lang.String.format;
|
||||
|
||||
import java.io.StringWriter;
|
||||
import java.sql.SQLException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.velocity.VelocityContext;
|
||||
import org.apache.velocity.app.Velocity;
|
||||
import org.apache.velocity.app.VelocityEngine;
|
||||
import org.apache.velocity.runtime.resource.loader.StringResourceLoader;
|
||||
import org.apache.velocity.runtime.resource.util.StringResourceRepository;
|
||||
import org.dspace.app.ldn.action.ActionStatus;
|
||||
import org.dspace.app.ldn.action.LDNAction;
|
||||
import org.dspace.app.ldn.model.Notification;
|
||||
import org.dspace.app.ldn.utility.LDNUtils;
|
||||
import org.dspace.content.DSpaceObject;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.content.MetadataValue;
|
||||
import org.dspace.content.service.ItemService;
|
||||
import org.dspace.core.Constants;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.handle.service.HandleService;
|
||||
import org.dspace.web.ContextUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
@@ -51,10 +39,6 @@ public class LDNMetadataProcessor implements LDNProcessor {
|
||||
|
||||
private final static Logger log = LogManager.getLogger(LDNMetadataProcessor.class);
|
||||
|
||||
private final static String DATE_PATTERN = "yyyy-MM-dd'T'HH:mm:ss'Z'";
|
||||
|
||||
private final VelocityEngine velocityEngine;
|
||||
|
||||
@Autowired
|
||||
private ItemService itemService;
|
||||
|
||||
@@ -65,16 +49,11 @@ public class LDNMetadataProcessor implements LDNProcessor {
|
||||
|
||||
private List<LDNAction> actions = new ArrayList<>();
|
||||
|
||||
private List<LDNMetadataChange> changes = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Initialize velocity engine for templating.
|
||||
*/
|
||||
private LDNMetadataProcessor() {
|
||||
velocityEngine = new VelocityEngine();
|
||||
velocityEngine.setProperty(Velocity.RESOURCE_LOADERS, "string");
|
||||
velocityEngine.setProperty("resource.loader.string.class", StringResourceLoader.class.getName());
|
||||
velocityEngine.init();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,110 +64,9 @@ public class LDNMetadataProcessor implements LDNProcessor {
|
||||
* @throws Exception something went wrong processing the notification
|
||||
*/
|
||||
@Override
|
||||
public void process(Notification notification) throws Exception {
|
||||
Iterator<Notification> iterator = repeater.iterator(notification);
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
Notification contextNotification = iterator.next();
|
||||
Item item = doProcess(contextNotification);
|
||||
runActions(contextNotification, item);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform the actual notification processing. Applies all defined metadata
|
||||
* changes.
|
||||
*
|
||||
* @param notification current context notification
|
||||
* @return Item associated item which persist notification details
|
||||
* @throws Exception failed to process notification
|
||||
*/
|
||||
private Item doProcess(Notification notification) throws Exception {
|
||||
log.info("Processing notification {} {}", notification.getId(), notification.getType());
|
||||
Context context = ContextUtil.obtainCurrentRequestContext();
|
||||
|
||||
VelocityContext velocityContext = prepareTemplateContext(notification);
|
||||
|
||||
public void process(Context context, Notification notification) throws Exception {
|
||||
Item item = lookupItem(context, notification);
|
||||
|
||||
List<MetadataValue> metadataValuesToRemove = new ArrayList<>();
|
||||
|
||||
for (LDNMetadataChange change : changes) {
|
||||
String condition = renderTemplate(velocityContext, change.getConditionTemplate());
|
||||
|
||||
boolean proceed = Boolean.parseBoolean(condition);
|
||||
|
||||
if (!proceed) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (change instanceof LDNMetadataAdd) {
|
||||
LDNMetadataAdd add = ((LDNMetadataAdd) change);
|
||||
String value = renderTemplate(velocityContext, add.getValueTemplate());
|
||||
log.info(
|
||||
"Adding {}.{}.{} {} {}",
|
||||
add.getSchema(),
|
||||
add.getElement(),
|
||||
add.getQualifier(),
|
||||
add.getLanguage(),
|
||||
value);
|
||||
|
||||
itemService.addMetadata(
|
||||
context,
|
||||
item,
|
||||
add.getSchema(),
|
||||
add.getElement(),
|
||||
add.getQualifier(),
|
||||
add.getLanguage(),
|
||||
value);
|
||||
|
||||
} else if (change instanceof LDNMetadataRemove) {
|
||||
LDNMetadataRemove remove = (LDNMetadataRemove) change;
|
||||
|
||||
for (String qualifier : remove.getQualifiers()) {
|
||||
List<MetadataValue> itemMetadata = itemService.getMetadata(
|
||||
item,
|
||||
change.getSchema(),
|
||||
change.getElement(),
|
||||
qualifier,
|
||||
Item.ANY);
|
||||
|
||||
for (MetadataValue metadatum : itemMetadata) {
|
||||
boolean delete = true;
|
||||
for (String valueTemplate : remove.getValueTemplates()) {
|
||||
String value = renderTemplate(velocityContext, valueTemplate);
|
||||
if (!metadatum.getValue().contains(value)) {
|
||||
delete = false;
|
||||
}
|
||||
}
|
||||
if (delete) {
|
||||
log.info("Removing {}.{}.{} {} {}",
|
||||
remove.getSchema(),
|
||||
remove.getElement(),
|
||||
qualifier,
|
||||
remove.getLanguage(),
|
||||
metadatum.getValue());
|
||||
|
||||
metadataValuesToRemove.add(metadatum);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!metadataValuesToRemove.isEmpty()) {
|
||||
itemService.removeMetadataValues(context, item, metadataValuesToRemove);
|
||||
}
|
||||
|
||||
context.turnOffAuthorisationSystem();
|
||||
try {
|
||||
itemService.update(context, item);
|
||||
context.commit();
|
||||
} finally {
|
||||
context.restoreAuthSystemState();
|
||||
}
|
||||
|
||||
return item;
|
||||
runActions(context, notification, item);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -201,7 +79,7 @@ public class LDNMetadataProcessor implements LDNProcessor {
|
||||
*
|
||||
* @throws Exception failed execute the action
|
||||
*/
|
||||
private ActionStatus runActions(Notification notification, Item item) throws Exception {
|
||||
private ActionStatus runActions(Context context, Notification notification, Item item) throws Exception {
|
||||
ActionStatus operation = ActionStatus.CONTINUE;
|
||||
for (LDNAction action : actions) {
|
||||
log.info("Running action {} for notification {} {}",
|
||||
@@ -209,7 +87,7 @@ public class LDNMetadataProcessor implements LDNProcessor {
|
||||
notification.getId(),
|
||||
notification.getType());
|
||||
|
||||
operation = action.execute(notification, item);
|
||||
operation = action.execute(context, notification, item);
|
||||
if (operation == ActionStatus.ABORT) {
|
||||
break;
|
||||
}
|
||||
@@ -246,20 +124,6 @@ public class LDNMetadataProcessor implements LDNProcessor {
|
||||
this.actions = actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return List<LDNMetadataChange>
|
||||
*/
|
||||
public List<LDNMetadataChange> getChanges() {
|
||||
return changes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param changes
|
||||
*/
|
||||
public void setChanges(List<LDNMetadataChange> changes) {
|
||||
this.changes = changes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup associated item to the notification context. If UUID in URL, lookup bu
|
||||
* UUID, else lookup by handle.
|
||||
@@ -314,41 +178,4 @@ public class LDNMetadataProcessor implements LDNProcessor {
|
||||
return item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare velocity template context with notification, timestamp and some
|
||||
* static utilities.
|
||||
*
|
||||
* @param notification current context notification
|
||||
* @return VelocityContext prepared velocity context
|
||||
*/
|
||||
private VelocityContext prepareTemplateContext(Notification notification) {
|
||||
VelocityContext velocityContext = new VelocityContext();
|
||||
|
||||
String timestamp = new SimpleDateFormat(DATE_PATTERN).format(Calendar.getInstance().getTime());
|
||||
|
||||
velocityContext.put("notification", notification);
|
||||
velocityContext.put("timestamp", timestamp);
|
||||
velocityContext.put("LDNUtils", LDNUtils.class);
|
||||
velocityContext.put("Objects", Objects.class);
|
||||
velocityContext.put("StringUtils", StringUtils.class);
|
||||
|
||||
return velocityContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render velocity template with provided context.
|
||||
*
|
||||
* @param context velocity context
|
||||
* @param template template to render
|
||||
* @return String results of rendering
|
||||
*/
|
||||
private String renderTemplate(VelocityContext context, String template) {
|
||||
StringWriter writer = new StringWriter();
|
||||
StringResourceRepository repository = StringResourceLoader.getRepository();
|
||||
repository.putStringResource("template", template);
|
||||
velocityEngine.getTemplate("template").merge(context, writer);
|
||||
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
}
|
@@ -1,51 +0,0 @@
|
||||
/**
|
||||
* 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.processor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Instuctions for removing metadata during notification processing.
|
||||
*/
|
||||
public class LDNMetadataRemove extends LDNMetadataChange {
|
||||
|
||||
private List<String> qualifiers = new ArrayList<>();
|
||||
|
||||
// velocity templates with notification as it contexts
|
||||
private List<String> valueTemplates = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* @return List<String>
|
||||
*/
|
||||
public List<String> getQualifiers() {
|
||||
return qualifiers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param qualifiers
|
||||
*/
|
||||
public void setQualifiers(List<String> qualifiers) {
|
||||
this.qualifiers = qualifiers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return List<String>
|
||||
*/
|
||||
public List<String> getValueTemplates() {
|
||||
return valueTemplates;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param valueTemplates
|
||||
*/
|
||||
public void setValueTemplates(List<String> valueTemplates) {
|
||||
this.valueTemplates = valueTemplates;
|
||||
}
|
||||
|
||||
}
|
@@ -8,6 +8,7 @@
|
||||
package org.dspace.app.ldn.processor;
|
||||
|
||||
import org.dspace.app.ldn.model.Notification;
|
||||
import org.dspace.core.Context;
|
||||
|
||||
/**
|
||||
* Processor interface to allow for custom implementations of process.
|
||||
@@ -20,5 +21,5 @@ public interface LDNProcessor {
|
||||
* @param notification received notification
|
||||
* @throws Exception something went wrong processing the notification
|
||||
*/
|
||||
public void process(Notification notification) throws Exception;
|
||||
public void process(Context context, Notification notification) throws Exception;
|
||||
}
|
@@ -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() {
|
||||
|
||||
@@ -203,7 +203,7 @@ public class LDNMessageServiceImpl implements LDNMessageService {
|
||||
update(context, msg);
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
Notification notification = mapper.readValue(msg.getMessage(), Notification.class);
|
||||
processor.process(notification);
|
||||
processor.process(context, notification);
|
||||
msg.setQueueStatus(LDNMessageEntity.QUEUE_STATUS_PROCESSED);
|
||||
result = 1;
|
||||
} catch (JsonSyntaxException jse) {
|
||||
|
@@ -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,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() { }
|
||||
}
|
@@ -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;
|
||||
}
|
||||
|
||||
}
|
@@ -27,6 +27,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;
|
||||
@@ -70,6 +71,8 @@ import org.springframework.beans.factory.annotation.Qualifier;
|
||||
*/
|
||||
public class QAEventServiceImpl implements QAEventService {
|
||||
|
||||
private static final Logger log = org.apache.logging.log4j.LogManager.getLogger(QAEventServiceImpl.class);
|
||||
|
||||
@Autowired(required = true)
|
||||
protected ConfigurationService configurationService;
|
||||
|
||||
@@ -649,7 +652,7 @@ public class QAEventServiceImpl implements QAEventService {
|
||||
if (startPosition != -1) {
|
||||
return originalId.substring(startPosition + 1, originalId.length());
|
||||
} else {
|
||||
return null;
|
||||
return originalId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -673,8 +676,8 @@ public class QAEventServiceImpl implements QAEventService {
|
||||
}
|
||||
|
||||
private String[] getSupportedSources() {
|
||||
return configurationService.getArrayProperty("qaevent.sources", new String[]
|
||||
{ QAEvent.OPENAIRE_SOURCE, QAEvent.COAR_NOTIFY });
|
||||
return configurationService.getArrayProperty("qaevent.sources",
|
||||
new String[] { QAEvent.OPENAIRE_SOURCE, QAEvent.COAR_NOTIFY_SOURCE });
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user