mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 10:04:21 +00:00
code review
This commit is contained in:
@@ -29,9 +29,28 @@ import org.dspace.core.ReloadableEntity;
|
|||||||
@Table(name = "ldn_message")
|
@Table(name = "ldn_message")
|
||||||
public class LDNMessageEntity implements ReloadableEntity<String> {
|
public class LDNMessageEntity implements ReloadableEntity<String> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LDN messages interact with a fictitious queue. Scheduled tasks manage the queue.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Message queued, it has to be elaborated.
|
||||||
|
*/
|
||||||
public static final Integer QUEUE_STATUS_QUEUED = 1;
|
public static final Integer QUEUE_STATUS_QUEUED = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Message has been taken from the queue and it's elaboration is in progress.
|
||||||
|
*/
|
||||||
public static final Integer QUEUE_STATUS_PROCESSING = 2;
|
public static final Integer QUEUE_STATUS_PROCESSING = 2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Message has been correctly elaborated.
|
||||||
|
*/
|
||||||
public static final Integer QUEUE_STATUS_PROCESSED = 3;
|
public static final Integer QUEUE_STATUS_PROCESSED = 3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Message has not been correctly elaborated - despite more than "ldn.processor.max.attempts" retryies
|
||||||
|
*/
|
||||||
public static final Integer QUEUE_STATUS_FAILED = 4;
|
public static final Integer QUEUE_STATUS_FAILED = 4;
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@@ -77,6 +96,12 @@ public class LDNMessageEntity implements ReloadableEntity<String> {
|
|||||||
@JoinColumn(name = "context", referencedColumnName = "uuid")
|
@JoinColumn(name = "context", referencedColumnName = "uuid")
|
||||||
private DSpaceObject context;
|
private DSpaceObject context;
|
||||||
|
|
||||||
|
@Column(name = "activity_stream_type")
|
||||||
|
private String activityStreamType;
|
||||||
|
|
||||||
|
@Column(name = "coar_notify_type")
|
||||||
|
private String coarNotifyType;
|
||||||
|
|
||||||
protected LDNMessageEntity() {
|
protected LDNMessageEntity() {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -118,6 +143,22 @@ public class LDNMessageEntity implements ReloadableEntity<String> {
|
|||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getActivityStreamType() {
|
||||||
|
return activityStreamType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setActivityStreamType(String activityStreamType) {
|
||||||
|
this.activityStreamType = activityStreamType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCoarNotifyType() {
|
||||||
|
return coarNotifyType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCoarNotifyType(String coarNotifyType) {
|
||||||
|
this.coarNotifyType = coarNotifyType;
|
||||||
|
}
|
||||||
|
|
||||||
public NotifyServiceEntity getOrigin() {
|
public NotifyServiceEntity getOrigin() {
|
||||||
return origin;
|
return origin;
|
||||||
}
|
}
|
||||||
|
@@ -36,6 +36,7 @@ public class LDNQueueExtractor {
|
|||||||
} else {
|
} else {
|
||||||
log.error("Errors happened during the extract operations. Check the log above!");
|
log.error("Errors happened during the extract operations. Check the log above!");
|
||||||
}
|
}
|
||||||
|
context.complete();
|
||||||
log.info("END LDNQueueExtractor.extractMessageFromQueue()");
|
log.info("END LDNQueueExtractor.extractMessageFromQueue()");
|
||||||
return processed_messages;
|
return processed_messages;
|
||||||
}
|
}
|
||||||
|
@@ -38,6 +38,7 @@ public class LDNQueueTimeoutChecker {
|
|||||||
log.error("Errors happened during the check operation. Check the log above!");
|
log.error("Errors happened during the check operation. Check the log above!");
|
||||||
}
|
}
|
||||||
log.info("END LDNQueueTimeoutChecker.checkQueueMessageTimeout()");
|
log.info("END LDNQueueTimeoutChecker.checkQueueMessageTimeout()");
|
||||||
|
context.complete();
|
||||||
return fixed_messages;
|
return fixed_messages;
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -30,23 +30,17 @@ public class LDNRouter {
|
|||||||
* @return LDNProcessor processor to process notification, can be null
|
* @return LDNProcessor processor to process notification, can be null
|
||||||
*/
|
*/
|
||||||
public LDNProcessor route(LDNMessageEntity ldnMessage) {
|
public LDNProcessor route(LDNMessageEntity ldnMessage) {
|
||||||
|
if (ldnMessage == null) {
|
||||||
|
log.warn("an null LDNMessage is received for routing!");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
if (StringUtils.isEmpty(ldnMessage.getType())) {
|
if (StringUtils.isEmpty(ldnMessage.getType())) {
|
||||||
log.warn("LDNMessage " + ldnMessage + " has no type!");
|
log.warn("LDNMessage " + ldnMessage + " has no type!");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (ldnMessage == null) {
|
|
||||||
log.warn("an null LDNMessage " + ldnMessage + "is received for routing!");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
String ldnMessageType = ldnMessage.getType();
|
|
||||||
ldnMessageType = ldnMessageType.replace("[", "");
|
|
||||||
ldnMessageType = ldnMessageType.replace("]", "");
|
|
||||||
ldnMessageType = ldnMessageType.replace(" ", "");
|
|
||||||
String[] ldnMsgTypeArray = ldnMessageType.split(",");
|
|
||||||
Set<String> ldnMessageTypeSet = new HashSet<String>();
|
Set<String> ldnMessageTypeSet = new HashSet<String>();
|
||||||
for (int i = 0; i < ldnMsgTypeArray.length; i++) {
|
ldnMessageTypeSet.add(ldnMessage.getActivityStreamType());
|
||||||
ldnMessageTypeSet.add(ldnMsgTypeArray[i]);
|
ldnMessageTypeSet.add(ldnMessage.getCoarNotifyType());
|
||||||
}
|
|
||||||
LDNProcessor processor = processors.get(ldnMessageTypeSet);
|
LDNProcessor processor = processors.get(ldnMessageTypeSet);
|
||||||
return processor;
|
return processor;
|
||||||
}
|
}
|
||||||
|
@@ -73,6 +73,9 @@ public class NotifyServiceEntity implements ReloadableEntity<Integer> {
|
|||||||
this.description = description;
|
this.description = description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return URL of an informative website
|
||||||
|
*/
|
||||||
public String getUrl() {
|
public String getUrl() {
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
@@ -81,6 +84,9 @@ public class NotifyServiceEntity implements ReloadableEntity<Integer> {
|
|||||||
this.url = url;
|
this.url = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return URL of the LDN InBox
|
||||||
|
*/
|
||||||
public String getLdnUrl() {
|
public String getLdnUrl() {
|
||||||
return ldnUrl;
|
return ldnUrl;
|
||||||
}
|
}
|
||||||
@@ -89,6 +95,9 @@ public class NotifyServiceEntity implements ReloadableEntity<Integer> {
|
|||||||
this.ldnUrl = ldnUrl;
|
this.ldnUrl = ldnUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The list of the inbound patterns configuration supported by the service
|
||||||
|
*/
|
||||||
public List<NotifyServiceInboundPattern> getInboundPatterns() {
|
public List<NotifyServiceInboundPattern> getInboundPatterns() {
|
||||||
return inboundPatterns;
|
return inboundPatterns;
|
||||||
}
|
}
|
||||||
|
@@ -14,7 +14,7 @@ import org.dspace.services.factory.DSpaceServicesFactory;
|
|||||||
* Abstract factory to get services for the NotifyService package,
|
* Abstract factory to get services for the NotifyService package,
|
||||||
* use NotifyServiceFactory.getInstance() to retrieve an implementation
|
* use NotifyServiceFactory.getInstance() to retrieve an implementation
|
||||||
*
|
*
|
||||||
* @author Mohamed Eskander (mohamed.eskander at 4science.com)
|
* @author Francesco Bacchelli (francesco.bacchelli at 4science.com)
|
||||||
*/
|
*/
|
||||||
public abstract class LDNMessageServiceFactory {
|
public abstract class LDNMessageServiceFactory {
|
||||||
|
|
||||||
|
@@ -14,7 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
* Factory implementation to get services for the notifyservices package, use
|
* Factory implementation to get services for the notifyservices package, use
|
||||||
* NotifyServiceFactory.getInstance() to retrieve an implementation
|
* NotifyServiceFactory.getInstance() to retrieve an implementation
|
||||||
*
|
*
|
||||||
* @author Mohamed Eskander (mohamed.eskander at 4science.com)
|
* @author Francesco Bacchelli (francesco.bacchelli at 4science.com)
|
||||||
*/
|
*/
|
||||||
public class LDNMessageServiceFactoryImpl extends LDNMessageServiceFactory {
|
public class LDNMessageServiceFactoryImpl extends LDNMessageServiceFactory {
|
||||||
|
|
||||||
|
@@ -14,7 +14,7 @@ import org.dspace.services.factory.DSpaceServicesFactory;
|
|||||||
* Abstract factory to get services for the NotifyService package, use
|
* Abstract factory to get services for the NotifyService package, use
|
||||||
* NotifyServiceFactory.getInstance() to retrieve an implementation
|
* NotifyServiceFactory.getInstance() to retrieve an implementation
|
||||||
*
|
*
|
||||||
* @author Mohamed Eskander (mohamed.eskander at 4science.com)
|
* @author Francesco Bacchelli (francesco.bacchelli at 4science.com)
|
||||||
*/
|
*/
|
||||||
public abstract class LDNRouterFactory {
|
public abstract class LDNRouterFactory {
|
||||||
|
|
||||||
|
@@ -61,22 +61,37 @@ public interface LDNMessageService {
|
|||||||
public void update(Context context, LDNMessageEntity ldnMessage) throws SQLException;
|
public void update(Context context, LDNMessageEntity ldnMessage) throws SQLException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* find the oldest queued LDNMessage
|
* Find the oldest queued LDNMessages that still can be elaborated
|
||||||
*
|
*
|
||||||
|
* @return list of LDN messages
|
||||||
* @param context The DSpace context
|
* @param context The DSpace context
|
||||||
* @throws SQLException If something goes wrong in the database
|
* @throws SQLException If something goes wrong in the database
|
||||||
*/
|
*/
|
||||||
public List<LDNMessageEntity> findOldestMessageToProcess(Context context) throws SQLException;
|
public List<LDNMessageEntity> findOldestMessageToProcess(Context context) throws SQLException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* find all messages queue timedout and with queue status Processing
|
* Find all messages in the queue with the Processing status but timed-out
|
||||||
*
|
*
|
||||||
|
* @return all the LDN Messages to be fixed on their queue_ attributes
|
||||||
* @param context The DSpace context
|
* @param context The DSpace context
|
||||||
* @throws SQLException If something goes wrong in the database
|
* @throws SQLException If something goes wrong in the database
|
||||||
*/
|
*/
|
||||||
public List<LDNMessageEntity> findProcessingTimedoutMessages(Context context) throws SQLException;
|
public List<LDNMessageEntity> findProcessingTimedoutMessages(Context context) throws SQLException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find all messages in the queue with the Processing status but timed-out and modify their queue_status
|
||||||
|
* considering the queue_attempts
|
||||||
|
*
|
||||||
|
* @return number of messages fixed
|
||||||
|
* @param context The DSpace context
|
||||||
|
*/
|
||||||
public int checkQueueMessageTimeout(Context context);
|
public int checkQueueMessageTimeout(Context context);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Elaborates the oldest enqueued message
|
||||||
|
*
|
||||||
|
* @return number of messages fixed
|
||||||
|
* @param context The DSpace context
|
||||||
|
*/
|
||||||
public int extractAndProcessMessageFromQueue(Context context) throws SQLException;
|
public int extractAndProcessMessageFromQueue(Context context) throws SQLException;
|
||||||
}
|
}
|
||||||
|
@@ -10,8 +10,11 @@ package org.dspace.app.ldn.service.impl;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.JsonSyntaxException;
|
import com.google.gson.JsonSyntaxException;
|
||||||
import org.apache.commons.lang.time.DateUtils;
|
import org.apache.commons.lang.time.DateUtils;
|
||||||
@@ -34,7 +37,6 @@ import org.dspace.handle.service.HandleService;
|
|||||||
import org.dspace.services.ConfigurationService;
|
import org.dspace.services.ConfigurationService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of {@link LDNMessageService}
|
* Implementation of {@link LDNMessageService}
|
||||||
*
|
*
|
||||||
@@ -81,9 +83,31 @@ public class LDNMessageServiceImpl implements LDNMessageService {
|
|||||||
ldnMessage.setOrigin(findNotifyService(context, notification.getOrigin()));
|
ldnMessage.setOrigin(findNotifyService(context, notification.getOrigin()));
|
||||||
ldnMessage.setTarget(findNotifyService(context, notification.getTarget()));
|
ldnMessage.setTarget(findNotifyService(context, notification.getTarget()));
|
||||||
ldnMessage.setInReplyTo(find(context, notification.getInReplyTo()));
|
ldnMessage.setInReplyTo(find(context, notification.getInReplyTo()));
|
||||||
ldnMessage.setMessage(new Gson().toJson(notification));
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
String message = null;
|
||||||
|
try {
|
||||||
|
message = mapper.writeValueAsString(notification);
|
||||||
|
ldnMessage.setMessage(message);
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
log.error("Notification json can't be correctly processed and stored inside the LDN Message Entity");
|
||||||
|
log.error(e);
|
||||||
|
}
|
||||||
ldnMessage.setType(StringUtils.joinWith(",", notification.getType()));
|
ldnMessage.setType(StringUtils.joinWith(",", notification.getType()));
|
||||||
|
Set<String> notificationType = notification.getType();
|
||||||
|
if (notificationType != null) {
|
||||||
|
String[] notificationTypeArray = (String[]) notificationType.toArray();
|
||||||
|
if (notificationTypeArray.length >= 2) {
|
||||||
|
ldnMessage.setActivityStreamType(notificationTypeArray[0]);
|
||||||
|
ldnMessage.setCoarNotifyType(notificationTypeArray[1]);
|
||||||
|
} else {
|
||||||
|
log.warn("LDN Message from Notification won't be typed because notification has incorrect "
|
||||||
|
+ "Type attribute");
|
||||||
|
log.warn(message);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.warn("LDN Message from Notification won't be typed because notification has incorrect Type attribute");
|
||||||
|
log.warn(message);
|
||||||
|
}
|
||||||
ldnMessage.setQueueStatus(LDNMessageEntity.QUEUE_STATUS_QUEUED);
|
ldnMessage.setQueueStatus(LDNMessageEntity.QUEUE_STATUS_QUEUED);
|
||||||
ldnMessage.setQueueTimeout(new Date());
|
ldnMessage.setQueueTimeout(new Date());
|
||||||
|
|
||||||
|
@@ -20,6 +20,8 @@ CREATE TABLE ldn_message
|
|||||||
target INTEGER,
|
target INTEGER,
|
||||||
inReplyTo VARCHAR(255),
|
inReplyTo VARCHAR(255),
|
||||||
context uuid,
|
context uuid,
|
||||||
|
activity_stream_type VARCHAR(255),
|
||||||
|
coar_notify_type VARCHAR(255),
|
||||||
queue_status INTEGER DEFAULT NULL,
|
queue_status INTEGER DEFAULT NULL,
|
||||||
queue_attempts INTEGER DEFAULT 0,
|
queue_attempts INTEGER DEFAULT 0,
|
||||||
queue_last_start_time TIMESTAMP,
|
queue_last_start_time TIMESTAMP,
|
||||||
|
@@ -20,6 +20,8 @@ CREATE TABLE ldn_message
|
|||||||
target INTEGER,
|
target INTEGER,
|
||||||
inReplyTo VARCHAR(255),
|
inReplyTo VARCHAR(255),
|
||||||
context uuid,
|
context uuid,
|
||||||
|
activity_stream_type VARCHAR(255),
|
||||||
|
coar_notify_type VARCHAR(255),
|
||||||
queue_status INTEGER DEFAULT NULL,
|
queue_status INTEGER DEFAULT NULL,
|
||||||
queue_attempts INTEGER DEFAULT 0,
|
queue_attempts INTEGER DEFAULT 0,
|
||||||
queue_last_start_time TIMESTAMP,
|
queue_last_start_time TIMESTAMP,
|
||||||
|
@@ -48,9 +48,8 @@ import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
|
|||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define the Spring Boot Application settings itself. This class takes the
|
* Define the Spring Boot Application settings itself. This class takes the place
|
||||||
* place of a web.xml file, and configures all Filters/Listeners as methods (see
|
* of a web.xml file, and configures all Filters/Listeners as methods (see below).
|
||||||
* below).
|
|
||||||
* <p>
|
* <p>
|
||||||
* NOTE: Requires a Servlet 3.0 container, e.g. Tomcat 7.0 or above.
|
* NOTE: Requires a Servlet 3.0 container, e.g. Tomcat 7.0 or above.
|
||||||
* <p>
|
* <p>
|
||||||
@@ -100,30 +99,28 @@ public class Application extends SpringBootServletInitializer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Override the default SpringBootServletInitializer.configure() method, passing
|
* Override the default SpringBootServletInitializer.configure() method,
|
||||||
* it this Application class.
|
* passing it this Application class.
|
||||||
* <p>
|
* <p>
|
||||||
* This is necessary to allow us to build a deployable WAR, rather than always
|
* This is necessary to allow us to build a deployable WAR, rather than
|
||||||
* relying on embedded Tomcat.
|
* always relying on embedded Tomcat.
|
||||||
* <p>
|
* <p>
|
||||||
* See:
|
* See: http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-create-a-deployable-war-file
|
||||||
* http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-create-a-deployable-war-file
|
|
||||||
*
|
*
|
||||||
* @param application
|
* @param application
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
||||||
// Pass this Application class, and our initializers for DSpace Kernel and
|
// Pass this Application class, and our initializers for DSpace Kernel and Configuration
|
||||||
// Configuration
|
|
||||||
// NOTE: Kernel must be initialized before Configuration
|
// NOTE: Kernel must be initialized before Configuration
|
||||||
return application.sources(Application.class)
|
return application.sources(Application.class)
|
||||||
.initializers(new DSpaceKernelInitializer(), new DSpaceConfigurationInitializer());
|
.initializers(new DSpaceKernelInitializer(), new DSpaceConfigurationInitializer());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the "DSpaceContextListener" so that it is loaded for this
|
* Register the "DSpaceContextListener" so that it is loaded
|
||||||
* Application.
|
* for this Application.
|
||||||
*
|
*
|
||||||
* @return DSpaceContextListener
|
* @return DSpaceContextListener
|
||||||
*/
|
*/
|
||||||
@@ -135,8 +132,8 @@ public class Application extends SpringBootServletInitializer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the DSpaceWebappServletFilter, which initializes the DSpace
|
* Register the DSpaceWebappServletFilter, which initializes the
|
||||||
* RequestService / SessionService
|
* DSpace RequestService / SessionService
|
||||||
*
|
*
|
||||||
* @return DSpaceWebappServletFilter
|
* @return DSpaceWebappServletFilter
|
||||||
*/
|
*/
|
||||||
@@ -185,70 +182,59 @@ public class Application extends SpringBootServletInitializer {
|
|||||||
|
|
||||||
return new WebMvcConfigurer() {
|
return new WebMvcConfigurer() {
|
||||||
/**
|
/**
|
||||||
* Create a custom CORS mapping for the DSpace REST API (/api/ paths), based on
|
* Create a custom CORS mapping for the DSpace REST API (/api/ paths), based on configured allowed origins.
|
||||||
* configured allowed origins.
|
|
||||||
* @param registry CorsRegistry
|
* @param registry CorsRegistry
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void addCorsMappings(@NonNull CorsRegistry registry) {
|
public void addCorsMappings(@NonNull CorsRegistry registry) {
|
||||||
// Get allowed origins for api and iiif endpoints.
|
// Get allowed origins for api and iiif endpoints.
|
||||||
// The actuator endpoints are configured using management.endpoints.web.cors.*
|
// The actuator endpoints are configured using management.endpoints.web.cors.* properties
|
||||||
// properties
|
|
||||||
String[] corsAllowedOrigins = configuration
|
String[] corsAllowedOrigins = configuration
|
||||||
.getCorsAllowedOrigins(configuration.getCorsAllowedOriginsConfig());
|
.getCorsAllowedOrigins(configuration.getCorsAllowedOriginsConfig());
|
||||||
String[] iiifAllowedOrigins = configuration
|
String[] iiifAllowedOrigins = configuration
|
||||||
.getCorsAllowedOrigins(configuration.getIiifAllowedOriginsConfig());
|
.getCorsAllowedOrigins(configuration.getIiifAllowedOriginsConfig());
|
||||||
String[] signpostingAllowedOrigins = configuration
|
String[] signpostingAllowedOrigins = configuration
|
||||||
.getCorsAllowedOrigins(configuration.getSignpostingAllowedOriginsConfig());
|
.getCorsAllowedOrigins(configuration.getSignpostingAllowedOriginsConfig());
|
||||||
|
|
||||||
boolean corsAllowCredentials = configuration.getCorsAllowCredentials();
|
boolean corsAllowCredentials = configuration.getCorsAllowCredentials();
|
||||||
boolean iiifAllowCredentials = configuration.getIiifAllowCredentials();
|
boolean iiifAllowCredentials = configuration.getIiifAllowCredentials();
|
||||||
boolean signpostingAllowCredentials = configuration.getSignpostingAllowCredentials();
|
boolean signpostingAllowCredentials = configuration.getSignpostingAllowCredentials();
|
||||||
if (corsAllowedOrigins != null) {
|
if (corsAllowedOrigins != null) {
|
||||||
registry.addMapping("/api/**").allowedMethods(CorsConfiguration.ALL)
|
registry.addMapping("/api/**").allowedMethods(CorsConfiguration.ALL)
|
||||||
// Set Access-Control-Allow-Credentials to "true" and specify which origins are
|
// Set Access-Control-Allow-Credentials to "true" and specify which origins are valid
|
||||||
// valid
|
// for our Access-Control-Allow-Origin header
|
||||||
// for our Access-Control-Allow-Origin header
|
// for our Access-Control-Allow-Origin header
|
||||||
// for our Access-Control-Allow-Origin header
|
.allowCredentials(corsAllowCredentials).allowedOrigins(corsAllowedOrigins)
|
||||||
.allowCredentials(corsAllowCredentials).allowedOrigins(corsAllowedOrigins)
|
// Allow list of request preflight headers allowed to be sent to us from the client
|
||||||
// Allow list of request preflight headers allowed to be sent to us from the
|
.allowedHeaders("Accept", "Authorization", "Content-Type", "Origin", "X-On-Behalf-Of",
|
||||||
// client
|
"X-Requested-With", "X-XSRF-TOKEN", "X-CORRELATION-ID", "X-REFERRER",
|
||||||
.allowedHeaders("Accept", "Authorization", "Content-Type", "Origin", "X-On-Behalf-Of",
|
"x-recaptcha-token")
|
||||||
"X-Requested-With", "X-XSRF-TOKEN", "X-CORRELATION-ID", "X-REFERRER",
|
// Allow list of response headers allowed to be sent by us (the server) to the client
|
||||||
"x-recaptcha-token")
|
.exposedHeaders("Authorization", "DSPACE-XSRF-TOKEN", "Location", "WWW-Authenticate");
|
||||||
// Allow list of response headers allowed to be sent by us (the server) to the
|
|
||||||
// client
|
|
||||||
.exposedHeaders("Authorization", "DSPACE-XSRF-TOKEN", "Location", "WWW-Authenticate");
|
|
||||||
}
|
}
|
||||||
if (iiifAllowedOrigins != null) {
|
if (iiifAllowedOrigins != null) {
|
||||||
registry.addMapping("/iiif/**").allowedMethods(CorsConfiguration.ALL)
|
registry.addMapping("/iiif/**").allowedMethods(CorsConfiguration.ALL)
|
||||||
// Set Access-Control-Allow-Credentials to "true" and specify which origins are
|
// Set Access-Control-Allow-Credentials to "true" and specify which origins are valid
|
||||||
// valid
|
// for our Access-Control-Allow-Origin header
|
||||||
// for our Access-Control-Allow-Origin header
|
.allowCredentials(iiifAllowCredentials).allowedOrigins(iiifAllowedOrigins)
|
||||||
.allowCredentials(iiifAllowCredentials).allowedOrigins(iiifAllowedOrigins)
|
// Allow list of request preflight headers allowed to be sent to us from the client
|
||||||
// Allow list of request preflight headers allowed to be sent to us from the
|
.allowedHeaders("Accept", "Authorization", "Content-Type", "Origin", "X-On-Behalf-Of",
|
||||||
// client
|
"X-Requested-With", "X-XSRF-TOKEN", "X-CORRELATION-ID", "X-REFERRER",
|
||||||
.allowedHeaders("Accept", "Authorization", "Content-Type", "Origin", "X-On-Behalf-Of",
|
"x-recaptcha-token")
|
||||||
"X-Requested-With", "X-XSRF-TOKEN", "X-CORRELATION-ID", "X-REFERRER",
|
// Allow list of response headers allowed to be sent by us (the server) to the client
|
||||||
"x-recaptcha-token")
|
.exposedHeaders("Authorization", "DSPACE-XSRF-TOKEN", "Location", "WWW-Authenticate");
|
||||||
// Allow list of response headers allowed to be sent by us (the server) to the
|
|
||||||
// client
|
|
||||||
.exposedHeaders("Authorization", "DSPACE-XSRF-TOKEN", "Location", "WWW-Authenticate");
|
|
||||||
}
|
}
|
||||||
if (signpostingAllowedOrigins != null) {
|
if (signpostingAllowedOrigins != null) {
|
||||||
registry.addMapping("/signposting/**").allowedMethods(CorsConfiguration.ALL)
|
registry.addMapping("/signposting/**").allowedMethods(CorsConfiguration.ALL)
|
||||||
// Set Access-Control-Allow-Credentials to "true" and specify which origins are
|
// Set Access-Control-Allow-Credentials to "true" and specify which origins are valid
|
||||||
// valid
|
// for our Access-Control-Allow-Origin header
|
||||||
// for our Access-Control-Allow-Origin header
|
.allowCredentials(signpostingAllowCredentials).allowedOrigins(signpostingAllowedOrigins)
|
||||||
.allowCredentials(signpostingAllowCredentials).allowedOrigins(signpostingAllowedOrigins)
|
// Allow list of request preflight headers allowed to be sent to us from the client
|
||||||
// Allow list of request preflight headers allowed to be sent to us from the
|
.allowedHeaders("Accept", "Authorization", "Content-Type", "Origin", "X-On-Behalf-Of",
|
||||||
// client
|
"X-Requested-With", "X-XSRF-TOKEN", "X-CORRELATION-ID", "X-REFERRER",
|
||||||
.allowedHeaders("Accept", "Authorization", "Content-Type", "Origin", "X-On-Behalf-Of",
|
"x-recaptcha-token", "access-control-allow-headers")
|
||||||
"X-Requested-With", "X-XSRF-TOKEN", "X-CORRELATION-ID", "X-REFERRER",
|
// Allow list of response headers allowed to be sent by us (the server) to the client
|
||||||
"x-recaptcha-token", "access-control-allow-headers")
|
.exposedHeaders("Authorization", "DSPACE-XSRF-TOKEN", "Location", "WWW-Authenticate");
|
||||||
// Allow list of response headers allowed to be sent by us (the server) to the
|
|
||||||
// client
|
|
||||||
.exposedHeaders("Authorization", "DSPACE-XSRF-TOKEN", "Location", "WWW-Authenticate");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,15 +249,14 @@ public class Application extends SpringBootServletInitializer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a new ResourceHandler to allow us to use WebJars.org to pull in web
|
* Add a new ResourceHandler to allow us to use WebJars.org to pull in web dependencies
|
||||||
* dependencies dynamically for HAL Browser, etc.
|
* dynamically for HAL Browser, etc.
|
||||||
* @param registry ResourceHandlerRegistry
|
* @param registry ResourceHandlerRegistry
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||||
// First, "mount" the Hal Browser resources at the /browser path
|
// First, "mount" the Hal Browser resources at the /browser path
|
||||||
// NOTE: the hal-browser directory uses the version of the Hal browser, so this
|
// NOTE: the hal-browser directory uses the version of the Hal browser, so this needs to be synced
|
||||||
// needs to be synced
|
|
||||||
// with the org.webjars.hal-browser version in the POM
|
// with the org.webjars.hal-browser version in the POM
|
||||||
registry
|
registry
|
||||||
.addResourceHandler("/browser/**")
|
.addResourceHandler("/browser/**")
|
||||||
|
@@ -13,7 +13,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.dspace.app.ldn.model.Notification;
|
import org.dspace.app.ldn.model.Notification;
|
||||||
import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
|
import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
|
||||||
@@ -45,8 +45,10 @@ public class LDNInboxControllerIT extends AbstractControllerIntegrationTest {
|
|||||||
context.restoreAuthSystemState();
|
context.restoreAuthSystemState();
|
||||||
InputStream offerEndorsementStream = getClass().getResourceAsStream("ldn_offer_endorsement_object.json");
|
InputStream offerEndorsementStream = getClass().getResourceAsStream("ldn_offer_endorsement_object.json");
|
||||||
String offerEndorsementJson = IOUtils.toString(offerEndorsementStream, Charset.defaultCharset());
|
String offerEndorsementJson = IOUtils.toString(offerEndorsementStream, Charset.defaultCharset());
|
||||||
|
offerEndorsementStream.close();
|
||||||
String message = offerEndorsementJson.replace("<<object>>", object);
|
String message = offerEndorsementJson.replace("<<object>>", object);
|
||||||
Notification notification = new Gson().fromJson(message, Notification.class);
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
Notification notification = mapper.readValue(message, Notification.class);
|
||||||
|
|
||||||
getClient(getAuthToken(admin.getEmail(), password))
|
getClient(getAuthToken(admin.getEmail(), password))
|
||||||
.perform(post("/ldn/inbox")
|
.perform(post("/ldn/inbox")
|
||||||
@@ -60,7 +62,9 @@ public class LDNInboxControllerIT extends AbstractControllerIntegrationTest {
|
|||||||
|
|
||||||
InputStream announceEndorsementStream = getClass().getResourceAsStream("ldn_announce_endorsement.json");
|
InputStream announceEndorsementStream = getClass().getResourceAsStream("ldn_announce_endorsement.json");
|
||||||
String message = IOUtils.toString(announceEndorsementStream, Charset.defaultCharset());
|
String message = IOUtils.toString(announceEndorsementStream, Charset.defaultCharset());
|
||||||
Notification notification = new Gson().fromJson(message, Notification.class);
|
announceEndorsementStream.close();
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
Notification notification = mapper.readValue(announceEndorsementStream, Notification.class);
|
||||||
getClient(getAuthToken(admin.getEmail(), password))
|
getClient(getAuthToken(admin.getEmail(), password))
|
||||||
.perform(post("/ldn/inbox")
|
.perform(post("/ldn/inbox")
|
||||||
.contentType("application/ld+json")
|
.contentType("application/ld+json")
|
||||||
@@ -71,9 +75,11 @@ public class LDNInboxControllerIT extends AbstractControllerIntegrationTest {
|
|||||||
@Test
|
@Test
|
||||||
public void ldnInboxEndorsementActionBadRequestTest() throws Exception {
|
public void ldnInboxEndorsementActionBadRequestTest() throws Exception {
|
||||||
// id is not an uri
|
// id is not an uri
|
||||||
InputStream announceEndorsementStream = getClass().getResourceAsStream("ldn_offer_endorsement_badrequest.json");
|
InputStream offerEndorsementStream = getClass().getResourceAsStream("ldn_offer_endorsement_badrequest.json");
|
||||||
String message = IOUtils.toString(announceEndorsementStream, Charset.defaultCharset());
|
String message = IOUtils.toString(offerEndorsementStream, Charset.defaultCharset());
|
||||||
Notification notification = new Gson().fromJson(message, Notification.class);
|
offerEndorsementStream.close();
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
Notification notification = mapper.readValue(offerEndorsementStream, Notification.class);
|
||||||
getClient(getAuthToken(admin.getEmail(), password))
|
getClient(getAuthToken(admin.getEmail(), password))
|
||||||
.perform(post("/ldn/inbox")
|
.perform(post("/ldn/inbox")
|
||||||
.contentType("application/ld+json")
|
.contentType("application/ld+json")
|
||||||
|
@@ -29,10 +29,16 @@ service.dev-hdc3b.lib.harvard.edu/api/inbox.key = 8df0c72a-56b5-44ef-b1c0-b4dbcb
|
|||||||
|
|
||||||
service.dev-hdc3b.lib.harvard.edu/api/inbox.key.header = X-Dataverse-key
|
service.dev-hdc3b.lib.harvard.edu/api/inbox.key.header = X-Dataverse-key
|
||||||
|
|
||||||
|
# LDN Queue extractor elaborates LDN Message entities of the queue
|
||||||
ldn.queue.extractor.cron = 0 0/1 * 1/1 * ?
|
ldn.queue.extractor.cron = 0 0/1 * 1/1 * ?
|
||||||
|
|
||||||
|
# LDN Queue timeout checks LDN Message Entities relation with the queue
|
||||||
ldn.queue.timeout.checker.cron = 0 0/1 * 1/1 * ?
|
ldn.queue.timeout.checker.cron = 0 0/1 * 1/1 * ?
|
||||||
|
|
||||||
|
# LDN Queue extractor elaborates LDN Message entities with max_attempts < than ldn.processor.max.attempts
|
||||||
ldn.processor.max.attempts = 5
|
ldn.processor.max.attempts = 5
|
||||||
|
|
||||||
|
# LDN Queue extractor sets LDN Message Entity queue_timeout property every time it tryies a new elaboration
|
||||||
|
# of the message. LDN Message with a future queue_timeout is not elaborated. This property is used to calculateas:
|
||||||
|
# a new timeout, such as: new_timeout = now + ldn.processor.queue.msg.timeout (in minutes)
|
||||||
ldn.processor.queue.msg.timeout = 60
|
ldn.processor.queue.msg.timeout = 60
|
||||||
|
Reference in New Issue
Block a user