mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-16 06:23:10 +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 serviceUrl;
|
||||
private String offerType;
|
||||
private NotifyRequestStatusEnum status;
|
||||
|
||||
public String getServiceName() {
|
||||
@@ -36,5 +37,11 @@ public class RequestStatus {
|
||||
public void setStatus(NotifyRequestStatusEnum 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.processor.LDNProcessor;
|
||||
import org.dspace.app.ldn.service.LDNMessageService;
|
||||
import org.dspace.app.ldn.utility.LDNUtils;
|
||||
import org.dspace.content.DSpaceObject;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.content.service.ItemService;
|
||||
@@ -41,6 +42,7 @@ import org.dspace.handle.service.HandleService;
|
||||
import org.dspace.services.ConfigurationService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of {@link LDNMessageService}
|
||||
*
|
||||
@@ -292,6 +294,7 @@ public class LDNMessageServiceImpl implements LDNMessageService {
|
||||
RequestStatus offer = new RequestStatus();
|
||||
offer.setServiceName(msg.getTarget() == null ? "Unknown Service" : msg.getTarget().getName());
|
||||
offer.setServiceUrl(msg.getTarget() == null ? "" : msg.getTarget().getUrl());
|
||||
offer.setOfferType(LDNUtils.getNotifyType(msg.getCoarNotifyType()));
|
||||
List<LDNMessageEntity> acks = ldnMessageDao.findAllRelatedMessagesByItem(
|
||||
context, msg, item, "Accept", "TentativeReject", "TentativeAccept", "Announce");
|
||||
if (acks == null || acks.isEmpty()) {
|
||||
|
@@ -80,4 +80,17 @@ public class LDNUtils {
|
||||
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.UUID;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.dspace.app.ldn.model.NotifyRequestStatus;
|
||||
import org.dspace.app.ldn.service.LDNMessageService;
|
||||
import org.dspace.app.rest.converter.ConverterService;
|
||||
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.Utils;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
@@ -30,11 +31,8 @@ import org.dspace.core.Context;
|
||||
import org.dspace.eperson.EPerson;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.rest.webmvc.ControllerUtils;
|
||||
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.RepresentationModel;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
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.RestController;
|
||||
|
||||
|
||||
/**
|
||||
* Rest Controller for NotifyRequestStatus targeting items
|
||||
*
|
||||
@@ -80,12 +79,10 @@ public class NotifyRequestStatusRestController implements InitializingBean {
|
||||
NotifyRequestStatusRest.NAME)));
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@GetMapping(produces = "application/json")
|
||||
@PreAuthorize("hasAuthority('AUTHENTICATED')")
|
||||
public ResponseEntity<RepresentationModel<?>> findByItem(@PathVariable UUID uuid)
|
||||
throws SQLException, AuthorizeException {
|
||||
|
||||
log.info("START findItemRequests looking for requests for item " + uuid);
|
||||
public ResponseEntity<String> findByItem(@PathVariable UUID uuid)
|
||||
throws SQLException, AuthorizeException, JsonProcessingException {
|
||||
|
||||
Context context = ContextUtil.obtainCurrentRequestContext();
|
||||
Item item = itemService.find(context, uuid);
|
||||
@@ -99,11 +96,12 @@ public class NotifyRequestStatusRestController implements InitializingBean {
|
||||
NotifyRequestStatus resultRequests = ldnMessageService.findRequestsByItem(context, item);
|
||||
NotifyRequestStatusRest resultRequestStatusRests = converterService.toRest(
|
||||
resultRequests, utils.obtainProjection());
|
||||
NotifyRequestStatusResource resultRequestStatusResource = converterService.toResource(resultRequestStatusRests);
|
||||
|
||||
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"
|
||||
})
|
||||
public class NotifyRequestStatusRest extends RestAddressableModel {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
public static final String CATEGORY = RestAddressableModel.LDN;
|
||||
public static final String NAME = "notifyrequests";
|
||||
public static final String FIND_BY_ITEM = "findbyitem";
|
||||
|
||||
private List<RequestStatus> notifyStatus;
|
||||
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);
|
||||
assertEquals(ackProcessed, 0);
|
||||
|
||||
|
||||
//CHECK THE SERVICE ON ITS notifystatus ARRAY
|
||||
String authToken = getAuthToken(admin.getEmail(), password);
|
||||
getClient(authToken)
|
||||
@@ -161,6 +160,7 @@ public class NotifyRequestStatusRestControllerIT extends AbstractControllerInteg
|
||||
.andExpect(jsonPath("$.notifyStatus").isNotEmpty())
|
||||
.andExpect(jsonPath("$.notifyStatus[0].status").value("REJECTED"))
|
||||
.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