diff --git a/dspace-api/src/main/java/org/dspace/app/ldn/model/RequestStatus.java b/dspace-api/src/main/java/org/dspace/app/ldn/model/RequestStatus.java index a2c0e98ce1..d193698307 100644 --- a/dspace-api/src/main/java/org/dspace/app/ldn/model/RequestStatus.java +++ b/dspace-api/src/main/java/org/dspace/app/ldn/model/RequestStatus.java @@ -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; + } } diff --git a/dspace-api/src/main/java/org/dspace/app/ldn/service/impl/LDNMessageServiceImpl.java b/dspace-api/src/main/java/org/dspace/app/ldn/service/impl/LDNMessageServiceImpl.java index d857d4d4eb..35490f6697 100644 --- a/dspace-api/src/main/java/org/dspace/app/ldn/service/impl/LDNMessageServiceImpl.java +++ b/dspace-api/src/main/java/org/dspace/app/ldn/service/impl/LDNMessageServiceImpl.java @@ -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 acks = ldnMessageDao.findAllRelatedMessagesByItem( context, msg, item, "Accept", "TentativeReject", "TentativeAccept", "Announce"); if (acks == null || acks.isEmpty()) { diff --git a/dspace-api/src/main/java/org/dspace/app/ldn/utility/LDNUtils.java b/dspace-api/src/main/java/org/dspace/app/ldn/utility/LDNUtils.java index bce56ccd65..949da655bc 100644 --- a/dspace-api/src/main/java/org/dspace/app/ldn/utility/LDNUtils.java +++ b/dspace-api/src/main/java/org/dspace/app/ldn/utility/LDNUtils.java @@ -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; + } + } \ No newline at end of file diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/NotifyRequestStatusRestController.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/NotifyRequestStatusRestController.java index c3fb634ab4..63d6e3cf23 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/NotifyRequestStatusRestController.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/NotifyRequestStatusRestController.java @@ -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> findByItem(@PathVariable UUID uuid) - throws SQLException, AuthorizeException { - - log.info("START findItemRequests looking for requests for item " + uuid); + public ResponseEntity 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); } } diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/model/NotifyRequestStatusRest.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/model/NotifyRequestStatusRest.java index 55918ac180..271edbbb91 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/model/NotifyRequestStatusRest.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/model/NotifyRequestStatusRest.java @@ -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 notifyStatus; private UUID itemuuid; diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/model/hateoas/NotifyRequestStatusResource.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/model/hateoas/NotifyRequestStatusResource.java deleted file mode 100644 index 581a5b1d6f..0000000000 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/model/hateoas/NotifyRequestStatusResource.java +++ /dev/null @@ -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 { - public NotifyRequestStatusResource(NotifyRequestStatusRest status, Utils utils) { - super(status, utils); - } -} diff --git a/dspace-server-webapp/src/test/java/org/dspace/app/rest/NotifyRequestStatusRestControllerIT.java b/dspace-server-webapp/src/test/java/org/dspace/app/rest/NotifyRequestStatusRestControllerIT.java index 5c375e4d38..a7077f20da 100644 --- a/dspace-server-webapp/src/test/java/org/dspace/app/rest/NotifyRequestStatusRestControllerIT.java +++ b/dspace-server-webapp/src/test/java/org/dspace/app/rest/NotifyRequestStatusRestControllerIT.java @@ -148,7 +148,6 @@ public class NotifyRequestStatusRestControllerIT extends AbstractControllerInteg assertEquals(ackProcessed, 1); ackProcessed = ldnMessageService.extractAndProcessMessageFromQueue(context); assertEquals(ackProcessed, 0); - //CHECK THE SERVICE ON ITS notifystatus ARRAY String authToken = getAuthToken(admin.getEmail(), password); @@ -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")) ; } }