mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-16 14:33:09 +00:00
CST-10638 implementation completed
This commit is contained in:
@@ -33,5 +33,5 @@ public interface LDNMessageDao extends GenericDAO<LDNMessageEntity> {
|
|||||||
Context context, Item item, String... activities) throws SQLException;
|
Context context, Item item, String... activities) throws SQLException;
|
||||||
|
|
||||||
public List<LDNMessageEntity> findAllRelatedMessagesByItem(
|
public List<LDNMessageEntity> findAllRelatedMessagesByItem(
|
||||||
Context context, String msgId, Item item, String... relatedTypes) throws SQLException;
|
Context context, LDNMessageEntity msg, Item item, String... relatedTypes) throws SQLException;
|
||||||
}
|
}
|
||||||
|
@@ -89,7 +89,7 @@ public class LDNMessageDaoImpl extends AbstractHibernateDAO<LDNMessageEntity> im
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<LDNMessageEntity> findAllRelatedMessagesByItem(
|
public List<LDNMessageEntity> findAllRelatedMessagesByItem(
|
||||||
Context context, String msgId, Item item, String... relatedTypes) throws SQLException {
|
Context context, LDNMessageEntity msg, Item item, String... relatedTypes) throws SQLException {
|
||||||
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
|
||||||
CriteriaQuery<LDNMessageEntity> criteriaQuery = getCriteriaQuery(criteriaBuilder, LDNMessageEntity.class);
|
CriteriaQuery<LDNMessageEntity> criteriaQuery = getCriteriaQuery(criteriaBuilder, LDNMessageEntity.class);
|
||||||
Root<LDNMessageEntity> root = criteriaQuery.from(LDNMessageEntity.class);
|
Root<LDNMessageEntity> root = criteriaQuery.from(LDNMessageEntity.class);
|
||||||
@@ -103,10 +103,10 @@ public class LDNMessageDaoImpl extends AbstractHibernateDAO<LDNMessageEntity> im
|
|||||||
andPredicates.add(
|
andPredicates.add(
|
||||||
criteriaBuilder.isNull(root.get(LDNMessageEntity_.target)));
|
criteriaBuilder.isNull(root.get(LDNMessageEntity_.target)));
|
||||||
andPredicates.add(
|
andPredicates.add(
|
||||||
criteriaBuilder.equal(root.get(LDNMessageEntity_.inReplyTo), msgId));
|
criteriaBuilder.equal(root.get(LDNMessageEntity_.inReplyTo), msg));
|
||||||
if (relatedTypes != null && relatedTypes.length > 0) {
|
if (relatedTypes != null && relatedTypes.length > 0) {
|
||||||
/*relatedtypePredicate = root.get(LDNMessageEntity_.activityStreamType).in(relatedTypes);
|
relatedtypePredicate = root.get(LDNMessageEntity_.activityStreamType).in(relatedTypes);
|
||||||
andPredicates.add(relatedtypePredicate);*/
|
andPredicates.add(relatedtypePredicate);
|
||||||
}
|
}
|
||||||
criteriaQuery.where(criteriaBuilder.and(andPredicates.toArray(new Predicate[] {})));
|
criteriaQuery.where(criteriaBuilder.and(andPredicates.toArray(new Predicate[] {})));
|
||||||
List<Order> orderList = new LinkedList<>();
|
List<Order> orderList = new LinkedList<>();
|
||||||
@@ -137,8 +137,8 @@ public class LDNMessageDaoImpl extends AbstractHibernateDAO<LDNMessageEntity> im
|
|||||||
andPredicates.add(
|
andPredicates.add(
|
||||||
criteriaBuilder.isNull(root.get(LDNMessageEntity_.origin)));
|
criteriaBuilder.isNull(root.get(LDNMessageEntity_.origin)));
|
||||||
if (activities != null && activities.length > 0) {
|
if (activities != null && activities.length > 0) {
|
||||||
/*activityPredicate = root.get(LDNMessageEntity_.activityStreamType).in(activities);
|
activityPredicate = root.get(LDNMessageEntity_.activityStreamType).in(activities);
|
||||||
andPredicates.add(activityPredicate);*/
|
andPredicates.add(activityPredicate);
|
||||||
}
|
}
|
||||||
criteriaQuery.where(criteriaBuilder.and(andPredicates.toArray(new Predicate[] {})));
|
criteriaQuery.where(criteriaBuilder.and(andPredicates.toArray(new Predicate[] {})));
|
||||||
List<Order> orderList = new LinkedList<>();
|
List<Order> orderList = new LinkedList<>();
|
||||||
|
@@ -269,10 +269,10 @@ 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 = null;
|
String url = null;
|
||||||
if (notification.getContext() != null) {
|
if (notification.getObject() != null) {
|
||||||
url = notification.getContext().getId();
|
|
||||||
} else if (notification.getObject() != null) {
|
|
||||||
url = notification.getObject().getId();
|
url = notification.getObject().getId();
|
||||||
|
} else if (notification.getContext() != null) {
|
||||||
|
url = notification.getContext().getId();
|
||||||
}
|
}
|
||||||
log.info("Looking up item {}", url);
|
log.info("Looking up item {}", url);
|
||||||
|
|
||||||
|
@@ -283,11 +283,10 @@ public class LDNMessageServiceImpl implements LDNMessageService {
|
|||||||
if (msgs != null && !msgs.isEmpty()) {
|
if (msgs != null && !msgs.isEmpty()) {
|
||||||
for (LDNMessageEntity msg : msgs) {
|
for (LDNMessageEntity msg : msgs) {
|
||||||
RequestStatus offer = new RequestStatus();
|
RequestStatus offer = new RequestStatus();
|
||||||
offer.setServiceName(msg.getCoarNotifyType());
|
offer.setServiceName(msg.getTarget().getName());
|
||||||
offer.setServiceUrl(msg.getTarget().getLdnUrl());
|
offer.setServiceUrl(msg.getTarget().getLdnUrl());
|
||||||
String msgId = msg.getID();
|
|
||||||
List<LDNMessageEntity> acks = ldnMessageDao.findAllRelatedMessagesByItem(
|
List<LDNMessageEntity> acks = ldnMessageDao.findAllRelatedMessagesByItem(
|
||||||
context, msgId, item, "Accept", "TentativeReject", "TentativeAccept");
|
context, msg, item, "Accept", "TentativeReject", "TentativeAccept");
|
||||||
if (acks == null || acks.isEmpty()) {
|
if (acks == null || acks.isEmpty()) {
|
||||||
offer.setStatus(NotifyRequestStatusEnum.REQUESTED);
|
offer.setStatus(NotifyRequestStatusEnum.REQUESTED);
|
||||||
} else if (acks.stream()
|
} else if (acks.stream()
|
||||||
|
@@ -22,9 +22,11 @@ import org.dspace.app.rest.model.hateoas.NotifyRequestStatusResource;
|
|||||||
import org.dspace.app.rest.utils.ContextUtil;
|
import org.dspace.app.rest.utils.ContextUtil;
|
||||||
import org.dspace.app.rest.utils.Utils;
|
import org.dspace.app.rest.utils.Utils;
|
||||||
import org.dspace.authorize.AuthorizeException;
|
import org.dspace.authorize.AuthorizeException;
|
||||||
|
import org.dspace.authorize.service.AuthorizeService;
|
||||||
import org.dspace.content.Item;
|
import org.dspace.content.Item;
|
||||||
import org.dspace.content.service.ItemService;
|
import org.dspace.content.service.ItemService;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
|
import org.dspace.eperson.EPerson;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.rest.webmvc.ControllerUtils;
|
import org.springframework.data.rest.webmvc.ControllerUtils;
|
||||||
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
|
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
|
||||||
@@ -32,6 +34,7 @@ import org.springframework.hateoas.RepresentationModel;
|
|||||||
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.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
@@ -61,8 +64,11 @@ public class NotifyRequestStatusRestController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ItemService itemService;
|
private ItemService itemService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AuthorizeService authorizeService;
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
//@PreAuthorize("hasAuthority('AUTHENTICATED')")
|
@PreAuthorize("hasAuthority('AUTHENTICATED')")
|
||||||
public ResponseEntity<RepresentationModel<?>> findByItem(@PathVariable UUID uuid)
|
public ResponseEntity<RepresentationModel<?>> findByItem(@PathVariable UUID uuid)
|
||||||
throws SQLException, AuthorizeException {
|
throws SQLException, AuthorizeException {
|
||||||
|
|
||||||
@@ -73,6 +79,10 @@ public class NotifyRequestStatusRestController {
|
|||||||
if (item == null) {
|
if (item == null) {
|
||||||
throw new ResourceNotFoundException("No such item: " + uuid);
|
throw new ResourceNotFoundException("No such item: " + uuid);
|
||||||
}
|
}
|
||||||
|
EPerson currentUser = context.getCurrentUser();
|
||||||
|
if (!currentUser.equals(item.getSubmitter()) && !authorizeService.isAdmin(context)) {
|
||||||
|
throw new AuthorizeException("User unauthorized");
|
||||||
|
}
|
||||||
NotifyRequestStatus resultRequests = ldnMessageService.findRequestsByItem(context, item);
|
NotifyRequestStatus resultRequests = ldnMessageService.findRequestsByItem(context, item);
|
||||||
NotifyRequestStatusRest resultRequestStatusRests = converterService.toRest(
|
NotifyRequestStatusRest resultRequestStatusRests = converterService.toRest(
|
||||||
resultRequests, utils.obtainProjection());
|
resultRequests, utils.obtainProjection());
|
||||||
|
Reference in New Issue
Block a user