Skip to content

Commit

Permalink
Merged in CST-12822-coar-display-pattern-type (pull request DSpace#1379)
Browse files Browse the repository at this point in the history
CST-12822 add offerType to NotifyRequestStatus object, adjust IT test  and fix json response
  • Loading branch information
frabacche committed Nov 29, 2023
2 parents 87c512f + 7f99236 commit f4abd63
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class RequestStatus {

private String serviceName;
private String serviceUrl;
private String offerType;
private NotifyRequestStatusEnum status;

public String getServiceName() {
Expand All @@ -36,5 +37,11 @@ public NotifyRequestStatusEnum getStatus() {
public void setStatus(NotifyRequestStatusEnum status) {
this.status = status;
}
public String getOfferType() {
return offerType;
}
public void setOfferType(String offerType) {
this.offerType = offerType;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
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;
Expand All @@ -41,6 +42,7 @@
import org.dspace.services.ConfigurationService;
import org.springframework.beans.factory.annotation.Autowired;


/**
* Implementation of {@link LDNMessageService}
*
Expand Down Expand Up @@ -292,6 +294,7 @@ public NotifyRequestStatus findRequestsByItem(Context context, Item item) throws
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()) {
Expand Down
13 changes: 13 additions & 0 deletions dspace-api/src/main/java/org/dspace/app/ldn/utility/LDNUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,17 @@ public static String processContextResolverId(String value) {
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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
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;
Expand All @@ -30,11 +31,8 @@
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;
Expand All @@ -43,6 +41,7 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
* Rest Controller for NotifyRequestStatus targeting items
*
Expand Down Expand Up @@ -80,12 +79,10 @@ public void afterPropertiesSet() {
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);
Expand All @@ -99,11 +96,12 @@ public ResponseEntity<RepresentationModel<?>> findByItem(@PathVariable UUID uuid
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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
"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;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ public void oneStatusRejectedTest() throws Exception {
assertEquals(ackProcessed, 1);
ackProcessed = ldnMessageService.extractAndProcessMessageFromQueue(context);
assertEquals(ackProcessed, 0);


//CHECK THE SERVICE ON ITS notifystatus ARRAY
String authToken = getAuthToken(admin.getEmail(), password);
Expand All @@ -161,6 +160,7 @@ public void oneStatusRejectedTest() throws Exception {
.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"))
;
}
}

0 comments on commit f4abd63

Please sign in to comment.