mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-16 14:33:09 +00:00
CST-12822 add offerType to NotifyRequestStatus object, adjust IT test and fix json response
This commit is contained in:
@@ -16,6 +16,7 @@ public class RequestStatus {
|
|||||||
|
|
||||||
private String serviceName;
|
private String serviceName;
|
||||||
private String serviceUrl;
|
private String serviceUrl;
|
||||||
|
private String offerType;
|
||||||
private NotifyRequestStatusEnum status;
|
private NotifyRequestStatusEnum status;
|
||||||
|
|
||||||
public String getServiceName() {
|
public String getServiceName() {
|
||||||
@@ -36,5 +37,11 @@ public class RequestStatus {
|
|||||||
public void setStatus(NotifyRequestStatusEnum status) {
|
public void setStatus(NotifyRequestStatusEnum status) {
|
||||||
this.status = status;
|
this.status = status;
|
||||||
}
|
}
|
||||||
|
public String getOfferType() {
|
||||||
|
return offerType;
|
||||||
|
}
|
||||||
|
public void setOfferType(String offerType) {
|
||||||
|
this.offerType = offerType;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -33,6 +33,7 @@ import org.dspace.app.ldn.model.RequestStatus;
|
|||||||
import org.dspace.app.ldn.model.Service;
|
import org.dspace.app.ldn.model.Service;
|
||||||
import org.dspace.app.ldn.processor.LDNProcessor;
|
import org.dspace.app.ldn.processor.LDNProcessor;
|
||||||
import org.dspace.app.ldn.service.LDNMessageService;
|
import org.dspace.app.ldn.service.LDNMessageService;
|
||||||
|
import org.dspace.app.ldn.utility.LDNUtils;
|
||||||
import org.dspace.content.DSpaceObject;
|
import org.dspace.content.DSpaceObject;
|
||||||
import org.dspace.content.Item;
|
import org.dspace.content.Item;
|
||||||
import org.dspace.content.service.ItemService;
|
import org.dspace.content.service.ItemService;
|
||||||
@@ -41,6 +42,7 @@ 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}
|
||||||
*
|
*
|
||||||
@@ -292,6 +294,7 @@ public class LDNMessageServiceImpl implements LDNMessageService {
|
|||||||
RequestStatus offer = new RequestStatus();
|
RequestStatus offer = new RequestStatus();
|
||||||
offer.setServiceName(msg.getTarget() == null ? "Unknown Service" : msg.getTarget().getName());
|
offer.setServiceName(msg.getTarget() == null ? "Unknown Service" : msg.getTarget().getName());
|
||||||
offer.setServiceUrl(msg.getTarget() == null ? "" : msg.getTarget().getUrl());
|
offer.setServiceUrl(msg.getTarget() == null ? "" : msg.getTarget().getUrl());
|
||||||
|
offer.setOfferType(LDNUtils.getNotifyType(msg.getCoarNotifyType()));
|
||||||
List<LDNMessageEntity> acks = ldnMessageDao.findAllRelatedMessagesByItem(
|
List<LDNMessageEntity> acks = ldnMessageDao.findAllRelatedMessagesByItem(
|
||||||
context, msg, item, "Accept", "TentativeReject", "TentativeAccept", "Announce");
|
context, msg, item, "Accept", "TentativeReject", "TentativeAccept", "Announce");
|
||||||
if (acks == null || acks.isEmpty()) {
|
if (acks == null || acks.isEmpty()) {
|
||||||
|
@@ -80,4 +80,17 @@ public class LDNUtils {
|
|||||||
return resolverId;
|
return resolverId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear the coarNotifyType from the source code.
|
||||||
|
*
|
||||||
|
* @param coarNotifyType coar Notify Type to sanitize
|
||||||
|
* @return String just the notify type
|
||||||
|
*/
|
||||||
|
public static String getNotifyType(String coarNotifyType) {
|
||||||
|
String justNotifyType = coarNotifyType;
|
||||||
|
justNotifyType = justNotifyType.substring(justNotifyType.lastIndexOf(":") + 1);
|
||||||
|
justNotifyType = justNotifyType.replace("Action", "");
|
||||||
|
return justNotifyType;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -13,13 +13,14 @@ import java.sql.SQLException;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
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.model.NotifyRequestStatus;
|
import org.dspace.app.ldn.model.NotifyRequestStatus;
|
||||||
import org.dspace.app.ldn.service.LDNMessageService;
|
import org.dspace.app.ldn.service.LDNMessageService;
|
||||||
import org.dspace.app.rest.converter.ConverterService;
|
import org.dspace.app.rest.converter.ConverterService;
|
||||||
import org.dspace.app.rest.model.NotifyRequestStatusRest;
|
import org.dspace.app.rest.model.NotifyRequestStatusRest;
|
||||||
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;
|
||||||
@@ -30,11 +31,8 @@ import org.dspace.core.Context;
|
|||||||
import org.dspace.eperson.EPerson;
|
import org.dspace.eperson.EPerson;
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
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.ResourceNotFoundException;
|
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
|
||||||
import org.springframework.hateoas.Link;
|
import org.springframework.hateoas.Link;
|
||||||
import org.springframework.hateoas.RepresentationModel;
|
|
||||||
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.security.access.prepost.PreAuthorize;
|
||||||
@@ -43,6 +41,7 @@ import org.springframework.web.bind.annotation.PathVariable;
|
|||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rest Controller for NotifyRequestStatus targeting items
|
* Rest Controller for NotifyRequestStatus targeting items
|
||||||
*
|
*
|
||||||
@@ -80,12 +79,10 @@ public class NotifyRequestStatusRestController implements InitializingBean {
|
|||||||
NotifyRequestStatusRest.NAME)));
|
NotifyRequestStatusRest.NAME)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping(produces = "application/json")
|
||||||
@PreAuthorize("hasAuthority('AUTHENTICATED')")
|
@PreAuthorize("hasAuthority('AUTHENTICATED')")
|
||||||
public ResponseEntity<RepresentationModel<?>> findByItem(@PathVariable UUID uuid)
|
public ResponseEntity<String> findByItem(@PathVariable UUID uuid)
|
||||||
throws SQLException, AuthorizeException {
|
throws SQLException, AuthorizeException, JsonProcessingException {
|
||||||
|
|
||||||
log.info("START findItemRequests looking for requests for item " + uuid);
|
|
||||||
|
|
||||||
Context context = ContextUtil.obtainCurrentRequestContext();
|
Context context = ContextUtil.obtainCurrentRequestContext();
|
||||||
Item item = itemService.find(context, uuid);
|
Item item = itemService.find(context, uuid);
|
||||||
@@ -99,11 +96,12 @@ public class NotifyRequestStatusRestController implements InitializingBean {
|
|||||||
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());
|
||||||
NotifyRequestStatusResource resultRequestStatusResource = converterService.toResource(resultRequestStatusRests);
|
|
||||||
|
|
||||||
context.complete();
|
context.complete();
|
||||||
|
String result = new ObjectMapper()
|
||||||
|
.writerWithDefaultPrettyPrinter().writeValueAsString(resultRequestStatusRests);
|
||||||
|
|
||||||
return ControllerUtils.toResponseEntity(HttpStatus.OK, new HttpHeaders(), resultRequestStatusResource);
|
return new ResponseEntity<>(result, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -27,9 +27,10 @@ import org.dspace.app.rest.NotifyRequestStatusRestController;
|
|||||||
"itemuuid"
|
"itemuuid"
|
||||||
})
|
})
|
||||||
public class NotifyRequestStatusRest extends RestAddressableModel {
|
public class NotifyRequestStatusRest extends RestAddressableModel {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
public static final String CATEGORY = RestAddressableModel.LDN;
|
public static final String CATEGORY = RestAddressableModel.LDN;
|
||||||
public static final String NAME = "notifyrequests";
|
public static final String NAME = "notifyrequests";
|
||||||
public static final String FIND_BY_ITEM = "findbyitem";
|
|
||||||
|
|
||||||
private List<RequestStatus> notifyStatus;
|
private List<RequestStatus> notifyStatus;
|
||||||
private UUID itemuuid;
|
private UUID itemuuid;
|
||||||
|
@@ -1,25 +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.rest.model.hateoas;
|
|
||||||
|
|
||||||
import org.dspace.app.rest.model.NotifyRequestStatusRest;
|
|
||||||
import org.dspace.app.rest.model.hateoas.annotations.RelNameDSpaceResource;
|
|
||||||
import org.dspace.app.rest.utils.Utils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* NotifyRequestStatus Rest HAL Resource. The HAL Resource wraps the REST Resource
|
|
||||||
* adding support for the links and embedded resources
|
|
||||||
*
|
|
||||||
* @author Francesco Bacchelli (francesco.bacchelli at 4science.it)
|
|
||||||
*/
|
|
||||||
@RelNameDSpaceResource(NotifyRequestStatusRest.NAME)
|
|
||||||
public class NotifyRequestStatusResource extends DSpaceResource<NotifyRequestStatusRest> {
|
|
||||||
public NotifyRequestStatusResource(NotifyRequestStatusRest status, Utils utils) {
|
|
||||||
super(status, utils);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -149,7 +149,6 @@ public class NotifyRequestStatusRestControllerIT extends AbstractControllerInteg
|
|||||||
ackProcessed = ldnMessageService.extractAndProcessMessageFromQueue(context);
|
ackProcessed = ldnMessageService.extractAndProcessMessageFromQueue(context);
|
||||||
assertEquals(ackProcessed, 0);
|
assertEquals(ackProcessed, 0);
|
||||||
|
|
||||||
|
|
||||||
//CHECK THE SERVICE ON ITS notifystatus ARRAY
|
//CHECK THE SERVICE ON ITS notifystatus ARRAY
|
||||||
String authToken = getAuthToken(admin.getEmail(), password);
|
String authToken = getAuthToken(admin.getEmail(), password);
|
||||||
getClient(authToken)
|
getClient(authToken)
|
||||||
@@ -161,6 +160,7 @@ public class NotifyRequestStatusRestControllerIT extends AbstractControllerInteg
|
|||||||
.andExpect(jsonPath("$.notifyStatus").isNotEmpty())
|
.andExpect(jsonPath("$.notifyStatus").isNotEmpty())
|
||||||
.andExpect(jsonPath("$.notifyStatus[0].status").value("REJECTED"))
|
.andExpect(jsonPath("$.notifyStatus[0].status").value("REJECTED"))
|
||||||
.andExpect(jsonPath("$.notifyStatus[0].serviceUrl").value("https://review-service.com/inbox/about/"))
|
.andExpect(jsonPath("$.notifyStatus[0].serviceUrl").value("https://review-service.com/inbox/about/"))
|
||||||
|
.andExpect(jsonPath("$.notifyStatus[0].offerType").value("Review"))
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user