mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-15 22:13:08 +00:00
Merge remote-tracking branch 'origin/coar-notify-7' into coar-notify-7
This commit is contained in:
@@ -29,12 +29,14 @@ 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.NotifyPatternToTriggerService;
|
||||
import org.dspace.app.ldn.service.NotifyServiceInboundPatternService;
|
||||
import org.dspace.content.Bitstream;
|
||||
import org.dspace.content.BitstreamFormat;
|
||||
import org.dspace.content.Bundle;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.content.MetadataValue;
|
||||
import org.dspace.content.factory.ContentServiceFactory;
|
||||
import org.dspace.content.logic.LogicalStatement;
|
||||
import org.dspace.content.service.BitstreamService;
|
||||
import org.dspace.content.service.ItemService;
|
||||
import org.dspace.core.Constants;
|
||||
@@ -45,6 +47,7 @@ import org.dspace.event.Consumer;
|
||||
import org.dspace.event.Event;
|
||||
import org.dspace.services.ConfigurationService;
|
||||
import org.dspace.services.factory.DSpaceServicesFactory;
|
||||
import org.dspace.utils.DSpace;
|
||||
import org.dspace.web.ContextUtil;
|
||||
|
||||
/**
|
||||
@@ -55,6 +58,7 @@ import org.dspace.web.ContextUtil;
|
||||
public class LDNMessageConsumer implements Consumer {
|
||||
|
||||
private NotifyPatternToTriggerService notifyPatternToTriggerService;
|
||||
private NotifyServiceInboundPatternService inboundPatternService;
|
||||
private LDNMessageService ldnMessageService;
|
||||
private ConfigurationService configurationService;
|
||||
private ItemService itemService;
|
||||
@@ -67,6 +71,7 @@ public class LDNMessageConsumer implements Consumer {
|
||||
configurationService = DSpaceServicesFactory.getInstance().getConfigurationService();
|
||||
itemService = ContentServiceFactory.getInstance().getItemService();
|
||||
bitstreamService = ContentServiceFactory.getInstance().getBitstreamService();
|
||||
inboundPatternService = NotifyServiceFactory.getInstance().getNotifyServiceInboundPatternService();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -77,36 +82,53 @@ public class LDNMessageConsumer implements Consumer {
|
||||
return;
|
||||
}
|
||||
|
||||
createLDNMessages(context, (Item) event.getSubject(context));
|
||||
Item item = (Item) event.getSubject(context);
|
||||
createManualLDNMessages(context, item);
|
||||
createAutomaticLDNMessages(context, item);
|
||||
}
|
||||
|
||||
private void createLDNMessages(Context context, Item item) throws SQLException {
|
||||
private void createManualLDNMessages(Context context, Item item) throws SQLException, JsonProcessingException {
|
||||
List<NotifyPatternToTrigger> patternsToTrigger =
|
||||
notifyPatternToTriggerService.findByItem(context, item);
|
||||
|
||||
patternsToTrigger.forEach(patternToTrigger -> {
|
||||
try {
|
||||
createLDNMessage(context, patternToTrigger);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
|
||||
for (NotifyPatternToTrigger patternToTrigger : patternsToTrigger) {
|
||||
createLDNMessage(context,patternToTrigger.getItem(),
|
||||
patternToTrigger.getNotifyService(), patternToTrigger.getPattern());
|
||||
}
|
||||
}
|
||||
|
||||
private void createLDNMessage(Context context, NotifyPatternToTrigger patternToTrigger)
|
||||
private void createAutomaticLDNMessages(Context context, Item item) throws SQLException, JsonProcessingException {
|
||||
|
||||
List<NotifyServiceInboundPattern> inboundPatterns = inboundPatternService.findAutomaticPatterns(context);
|
||||
|
||||
for (NotifyServiceInboundPattern inboundPattern : inboundPatterns) {
|
||||
if (inboundPattern.getConstraint() == null ||
|
||||
evaluateFilter(context, item, inboundPattern.getConstraint())) {
|
||||
createLDNMessage(context, item, inboundPattern.getNotifyService(), inboundPattern.getPattern());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean evaluateFilter(Context context, Item item, String constraint) {
|
||||
LogicalStatement filter =
|
||||
new DSpace().getServiceManager().getServiceByName(constraint, LogicalStatement.class);
|
||||
|
||||
return filter != null && filter.getResult(context, item);
|
||||
}
|
||||
|
||||
private void createLDNMessage(Context context, Item item, NotifyServiceEntity service, String pattern)
|
||||
throws SQLException, JsonMappingException, JsonProcessingException {
|
||||
|
||||
LDN ldn = getLDNMessage(patternToTrigger.getPattern());
|
||||
LDN ldn = getLDNMessage(pattern);
|
||||
LDNMessageEntity ldnMessage =
|
||||
ldnMessageService.create(context, format("urn:uuid:%s", UUID.randomUUID()));
|
||||
|
||||
ldnMessage.setObject(patternToTrigger.getItem());
|
||||
ldnMessage.setTarget(patternToTrigger.getNotifyService());
|
||||
ldnMessage.setObject(item);
|
||||
ldnMessage.setTarget(service);
|
||||
ldnMessage.setQueueStatus(LDNMessageEntity.QUEUE_STATUS_QUEUED);
|
||||
ldnMessage.setQueueTimeout(new Date());
|
||||
|
||||
appendGeneratedMessage(ldn, ldnMessage, patternToTrigger.getPattern());
|
||||
appendGeneratedMessage(ldn, ldnMessage, pattern);
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
Notification notification = mapper.readValue(ldnMessage.getMessage(), Notification.class);
|
||||
|
@@ -8,6 +8,7 @@
|
||||
package org.dspace.app.ldn.dao;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import org.dspace.app.ldn.NotifyServiceEntity;
|
||||
import org.dspace.app.ldn.NotifyServiceInboundPattern;
|
||||
@@ -35,4 +36,12 @@ public interface NotifyServiceInboundPatternDao extends GenericDAO<NotifyService
|
||||
public NotifyServiceInboundPattern findByServiceAndPattern(Context context,
|
||||
NotifyServiceEntity notifyServiceEntity,
|
||||
String pattern) throws SQLException;
|
||||
/**
|
||||
* find all automatic notifyServiceInboundPatterns
|
||||
*
|
||||
* @param context the context
|
||||
* @return all automatic notifyServiceInboundPatterns
|
||||
* @throws SQLException if database error
|
||||
*/
|
||||
List<NotifyServiceInboundPattern> findAutomaticPatterns(Context context) throws SQLException;
|
||||
}
|
||||
|
@@ -8,6 +8,7 @@
|
||||
package org.dspace.app.ldn.dao.impl;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Root;
|
||||
@@ -42,4 +43,17 @@ public class NotifyServiceInboundPatternDaoImpl
|
||||
));
|
||||
return uniqueResult(context, criteriaQuery, false, NotifyServiceInboundPattern.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NotifyServiceInboundPattern> findAutomaticPatterns(Context context) throws SQLException {
|
||||
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, NotifyServiceInboundPattern.class);
|
||||
Root<NotifyServiceInboundPattern> inboundPatternRoot = criteriaQuery.from(NotifyServiceInboundPattern.class);
|
||||
criteriaQuery.select(inboundPatternRoot);
|
||||
criteriaQuery.where(
|
||||
criteriaBuilder.equal(
|
||||
inboundPatternRoot.get(NotifyServiceInboundPattern_.automatic), true)
|
||||
);
|
||||
return list(context, criteriaQuery, false, NotifyServiceInboundPattern.class, -1, -1);
|
||||
}
|
||||
}
|
||||
|
@@ -8,6 +8,7 @@
|
||||
package org.dspace.app.ldn.service;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import org.dspace.app.ldn.NotifyServiceEntity;
|
||||
import org.dspace.app.ldn.NotifyServiceInboundPattern;
|
||||
@@ -35,6 +36,15 @@ public interface NotifyServiceInboundPatternService {
|
||||
NotifyServiceEntity notifyServiceEntity,
|
||||
String pattern) throws SQLException;
|
||||
|
||||
/**
|
||||
* find all automatic notifyServiceInboundPatterns
|
||||
*
|
||||
* @param context the context
|
||||
* @return all automatic notifyServiceInboundPatterns
|
||||
* @throws SQLException if database error
|
||||
*/
|
||||
public List<NotifyServiceInboundPattern> findAutomaticPatterns(Context context) throws SQLException;
|
||||
|
||||
/**
|
||||
* create new notifyServiceInboundPattern
|
||||
*
|
||||
|
@@ -8,6 +8,7 @@
|
||||
package org.dspace.app.ldn.service.impl;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import org.dspace.app.ldn.NotifyServiceEntity;
|
||||
import org.dspace.app.ldn.NotifyServiceInboundPattern;
|
||||
@@ -33,6 +34,11 @@ public class NotifyServiceInboundPatternServiceImpl implements NotifyServiceInbo
|
||||
return inboundPatternDao.findByServiceAndPattern(context, notifyServiceEntity, pattern);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NotifyServiceInboundPattern> findAutomaticPatterns(Context context) throws SQLException {
|
||||
return inboundPatternDao.findAutomaticPatterns(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NotifyServiceInboundPattern create(Context context, NotifyServiceEntity notifyServiceEntity)
|
||||
throws SQLException {
|
||||
|
@@ -8,7 +8,6 @@
|
||||
package org.dspace.content;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.dspace.app.ldn.ItemFilter;
|
||||
@@ -38,16 +37,12 @@ public class ItemFilterServiceImpl implements ItemFilterService {
|
||||
|
||||
@Override
|
||||
public List<ItemFilter> findAll() {
|
||||
return serviceManager.getServicesNames()
|
||||
return serviceManager.getServicesWithNamesByType(LogicalStatement.class)
|
||||
.keySet()
|
||||
.stream()
|
||||
.filter(id -> isLogicalStatement(id))
|
||||
.map(id -> new ItemFilter(id))
|
||||
.sorted()
|
||||
.map(ItemFilter::new)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private boolean isLogicalStatement(String id) {
|
||||
return Objects.nonNull(
|
||||
serviceManager.getServiceByName(id, LogicalStatement.class)
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user