mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-16 22:43:12 +00:00
[CST-10632] fixes in LDN configuration/code
This commit is contained in:
@@ -11,14 +11,22 @@ import static java.lang.String.format;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.dspace.app.ldn.factory.NotifyServiceFactory;
|
import org.dspace.app.ldn.factory.NotifyServiceFactory;
|
||||||
|
import org.dspace.app.ldn.model.Notification;
|
||||||
import org.dspace.app.ldn.service.LDNMessageService;
|
import org.dspace.app.ldn.service.LDNMessageService;
|
||||||
import org.dspace.app.ldn.service.NotifyPatternToTriggerService;
|
import org.dspace.app.ldn.service.NotifyPatternToTriggerService;
|
||||||
import org.dspace.content.Bitstream;
|
import org.dspace.content.Bitstream;
|
||||||
@@ -79,7 +87,7 @@ public class LDNMessageConsumer implements Consumer {
|
|||||||
patternsToTrigger.forEach(patternToTrigger -> {
|
patternsToTrigger.forEach(patternToTrigger -> {
|
||||||
try {
|
try {
|
||||||
createLDNMessage(context, patternToTrigger);
|
createLDNMessage(context, patternToTrigger);
|
||||||
} catch (SQLException e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -87,17 +95,29 @@ public class LDNMessageConsumer implements Consumer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void createLDNMessage(Context context, NotifyPatternToTrigger patternToTrigger)
|
private void createLDNMessage(Context context, NotifyPatternToTrigger patternToTrigger)
|
||||||
throws SQLException {
|
throws SQLException, JsonMappingException, JsonProcessingException {
|
||||||
|
|
||||||
LDN ldn = getLDNMessage(patternToTrigger.getPattern());
|
LDN ldn = getLDNMessage(patternToTrigger.getPattern());
|
||||||
|
|
||||||
LDNMessageEntity ldnMessage =
|
LDNMessageEntity ldnMessage =
|
||||||
ldnMessageService.create(context, format("urn:uuid:%s", UUID.randomUUID()));
|
ldnMessageService.create(context, format("urn:uuid:%s", UUID.randomUUID()));
|
||||||
|
|
||||||
ldnMessage.setObject(patternToTrigger.getItem());
|
ldnMessage.setObject(patternToTrigger.getItem());
|
||||||
ldnMessage.setTarget(patternToTrigger.getNotifyService());
|
ldnMessage.setTarget(patternToTrigger.getNotifyService());
|
||||||
ldnMessage.setQueueStatus(LDNMessageEntity.QUEUE_STATUS_QUEUED);
|
ldnMessage.setQueueStatus(LDNMessageEntity.QUEUE_STATUS_QUEUED);
|
||||||
|
ldnMessage.setQueueTimeout(new Date());
|
||||||
|
|
||||||
appendGeneratedMessage(ldn, ldnMessage, patternToTrigger.getPattern());
|
appendGeneratedMessage(ldn, ldnMessage, patternToTrigger.getPattern());
|
||||||
|
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
Notification notification = mapper.readValue(ldnMessage.getMessage(), Notification.class);
|
||||||
|
ldnMessage.setType(StringUtils.joinWith(",", notification.getType()));
|
||||||
|
|
||||||
|
ArrayList<String> notificationTypeArrayList = new ArrayList<String>(notification.getType());
|
||||||
|
// sorting the list
|
||||||
|
Collections.sort(notificationTypeArrayList);
|
||||||
|
ldnMessage.setActivityStreamType(notificationTypeArrayList.get(0));
|
||||||
|
ldnMessage.setCoarNotifyType(notificationTypeArrayList.get(1));
|
||||||
|
|
||||||
ldnMessageService.update(context, ldnMessage);
|
ldnMessageService.update(context, ldnMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -9,6 +9,9 @@ package org.dspace.app.ldn.action;
|
|||||||
|
|
||||||
import static org.dspace.app.ldn.RdfMediaType.APPLICATION_JSON_LD;
|
import static org.dspace.app.ldn.RdfMediaType.APPLICATION_JSON_LD;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.dspace.app.ldn.converter.JsonLdHttpMessageConverter;
|
import org.dspace.app.ldn.converter.JsonLdHttpMessageConverter;
|
||||||
@@ -19,6 +22,7 @@ import org.springframework.http.HttpEntity;
|
|||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.http.converter.HttpMessageConverter;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -34,12 +38,16 @@ public class SendLDNMessageAction implements LDNAction {
|
|||||||
|
|
||||||
public SendLDNMessageAction() {
|
public SendLDNMessageAction() {
|
||||||
restTemplate = new RestTemplate();
|
restTemplate = new RestTemplate();
|
||||||
restTemplate.getMessageConverters().add(new JsonLdHttpMessageConverter());
|
List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
|
||||||
|
messageConverters.add(new JsonLdHttpMessageConverter());
|
||||||
|
messageConverters.addAll(restTemplate.getMessageConverters());
|
||||||
|
restTemplate.setMessageConverters(messageConverters);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ActionStatus execute(Context context, Notification notification, Item item) throws Exception {
|
public ActionStatus execute(Context context, Notification notification, Item item) throws Exception {
|
||||||
//TODO authorization with Bearer token should be supported.
|
//TODO authorization with Bearer token should be supported.
|
||||||
|
|
||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
headers.add("Content-Type", APPLICATION_JSON_LD.toString());
|
headers.add("Content-Type", APPLICATION_JSON_LD.toString());
|
||||||
|
|
||||||
|
@@ -138,7 +138,12 @@ public class LDNMetadataProcessor implements LDNProcessor {
|
|||||||
private Item lookupItem(Context context, Notification notification) throws SQLException {
|
private Item lookupItem(Context context, Notification notification) throws SQLException {
|
||||||
Item item = null;
|
Item item = null;
|
||||||
|
|
||||||
String url = notification.getContext().getId();
|
String url = null;
|
||||||
|
if (notification.getContext() != null) {
|
||||||
|
url = notification.getContext().getId();
|
||||||
|
} else {
|
||||||
|
url = notification.getObject().getId();
|
||||||
|
}
|
||||||
|
|
||||||
log.info("Looking up item {}", url);
|
log.info("Looking up item {}", url);
|
||||||
|
|
||||||
|
@@ -62,7 +62,7 @@
|
|||||||
</key>
|
</key>
|
||||||
<ref bean="rejectAckAction" />
|
<ref bean="rejectAckAction" />
|
||||||
</entry>
|
</entry>
|
||||||
<entry>
|
<entry>
|
||||||
<key>
|
<key>
|
||||||
<set>
|
<set>
|
||||||
<value>Accept</value>
|
<value>Accept</value>
|
||||||
@@ -80,7 +80,7 @@
|
|||||||
</key>
|
</key>
|
||||||
<ref bean="rejectAckAction" />
|
<ref bean="rejectAckAction" />
|
||||||
</entry>
|
</entry>
|
||||||
<entry>
|
<entry>
|
||||||
<key>
|
<key>
|
||||||
<set>
|
<set>
|
||||||
<value>Accept</value>
|
<value>Accept</value>
|
||||||
@@ -114,7 +114,7 @@
|
|||||||
<entry>
|
<entry>
|
||||||
<key>
|
<key>
|
||||||
<set>
|
<set>
|
||||||
<value>Announce</value>
|
<value>Offer</value>
|
||||||
<value>coar-notify:ReviewAction</value>
|
<value>coar-notify:ReviewAction</value>
|
||||||
</set>
|
</set>
|
||||||
</key>
|
</key>
|
||||||
@@ -123,7 +123,7 @@
|
|||||||
<entry>
|
<entry>
|
||||||
<key>
|
<key>
|
||||||
<set>
|
<set>
|
||||||
<value>Announce</value>
|
<value>Offer</value>
|
||||||
<value>coar-notify:EndorsementAction</value>
|
<value>coar-notify:EndorsementAction</value>
|
||||||
</set>
|
</set>
|
||||||
</key>
|
</key>
|
||||||
@@ -132,7 +132,7 @@
|
|||||||
<entry>
|
<entry>
|
||||||
<key>
|
<key>
|
||||||
<set>
|
<set>
|
||||||
<value>Announce</value>
|
<value>Offer</value>
|
||||||
<value>coar-notify:IngestAction</value>
|
<value>coar-notify:IngestAction</value>
|
||||||
</set>
|
</set>
|
||||||
</key>
|
</key>
|
||||||
|
Reference in New Issue
Block a user