[CST-12108] refactoring

This commit is contained in:
Mykhaylo Boychuk
2023-11-03 00:38:09 +01:00
parent f72ef270fe
commit 2261d0e6a7
17 changed files with 206 additions and 131 deletions

View File

@@ -13,7 +13,7 @@ import java.security.NoSuchAlgorithmException;
import java.util.Date;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.dspace.qaevent.service.dto.EmptyMessageDTO;
import org.dspace.qaevent.service.dto.CorrectionTypeMessageDTO;
import org.dspace.qaevent.service.dto.OpenaireMessageDTO;
import org.dspace.qaevent.service.dto.QAMessageDTO;
import org.dspace.util.RawJsonDeserializer;
@@ -198,7 +198,7 @@ public class QAEvent {
case OPENAIRE_SOURCE:
return OpenaireMessageDTO.class;
case INTERNAL_ITEM_SOURCE:
return EmptyMessageDTO.class;
return CorrectionTypeMessageDTO.class;
default:
throw new IllegalArgumentException("Unknown event's source: " + getSource());
}

View File

@@ -13,6 +13,7 @@ import org.dspace.authorize.AuthorizeException;
import org.dspace.content.Item;
import org.dspace.content.QAEvent;
import org.dspace.core.Context;
import org.dspace.qaevent.service.dto.QAMessageDTO;
/**
* Interface class that model the CorrectionType.
@@ -27,16 +28,14 @@ public interface CorrectionType {
public String getCreationForm();
public String getDiscoveryConfiguration();
public boolean isRequiredRelatedItem();
public boolean isAllowed(Context context, Item targetItem) throws AuthorizeException, SQLException;
public boolean isAllowed(Context context, Item targetItem, Item relatedItem) throws AuthorizeException,SQLException;
public QAEvent createCorrection(Context context, Item targetItem);
public QAEvent createCorrection(Context context, Item targetItem, QAMessageDTO reason);
public QAEvent createCorrection(Context context, Item targetItem, Item relatedItem);
public QAEvent createCorrection(Context context, Item targetItem, Item relatedItem, QAMessageDTO reason);
}

View File

@@ -7,7 +7,6 @@
*/
package org.dspace.correctiontype;
import static org.apache.commons.lang.StringUtils.EMPTY;
import static org.dspace.content.QAEvent.INTERNAL_ITEM_SOURCE;
import java.sql.SQLException;
@@ -21,6 +20,8 @@ import org.dspace.content.QAEvent;
import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.dspace.qaevent.service.QAEventService;
import org.dspace.qaevent.service.dto.CorrectionTypeMessageDTO;
import org.dspace.qaevent.service.dto.QAMessageDTO;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
@@ -34,6 +35,7 @@ public class ReinstateCorrectionType implements CorrectionType, InitializingBean
private String id;
private String topic;
private String creationForm;
@Autowired
private QAEventService qaEventService;
@@ -53,14 +55,15 @@ public class ReinstateCorrectionType implements CorrectionType, InitializingBean
}
@Override
public QAEvent createCorrection(Context context, Item targetItem) {
public QAEvent createCorrection(Context context, Item targetItem, QAMessageDTO reason) {
CorrectionTypeMessageDTO mesasge = (CorrectionTypeMessageDTO) reason;
QAEvent qaEvent = new QAEvent(INTERNAL_ITEM_SOURCE,
"handle:" + targetItem.getHandle(),
targetItem.getID().toString(),
targetItem.getName(),
this.getTopic(),
1.0,
new Gson().toJson(new Object()),
new Gson().toJson(mesasge),
new Date()
);
@@ -69,8 +72,8 @@ public class ReinstateCorrectionType implements CorrectionType, InitializingBean
}
@Override
public QAEvent createCorrection(Context context, Item targetItem, Item relatedItem) {
return this.createCorrection(context, targetItem);
public QAEvent createCorrection(Context context, Item targetItem, Item relatedItem, QAMessageDTO reason) {
return this.createCorrection(context, targetItem, reason);
}
@Override
@@ -101,12 +104,11 @@ public class ReinstateCorrectionType implements CorrectionType, InitializingBean
@Override
public String getCreationForm() {
return EMPTY;
return this.creationForm;
}
@Override
public String getDiscoveryConfiguration() {
return EMPTY;
public void setCreationForm(String creationForm) {
this.creationForm = creationForm;
}
}

View File

@@ -7,7 +7,6 @@
*/
package org.dspace.correctiontype;
import static org.apache.commons.lang.StringUtils.EMPTY;
import static org.dspace.content.QAEvent.INTERNAL_ITEM_SOURCE;
import static org.dspace.core.Constants.READ;
@@ -21,6 +20,8 @@ import org.dspace.content.Item;
import org.dspace.content.QAEvent;
import org.dspace.core.Context;
import org.dspace.qaevent.service.QAEventService;
import org.dspace.qaevent.service.dto.CorrectionTypeMessageDTO;
import org.dspace.qaevent.service.dto.QAMessageDTO;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
@@ -34,6 +35,7 @@ public class WithdrawnCorrectionType implements CorrectionType, InitializingBean
private String id;
private String topic;
private String creationForm;
@Autowired
private QAEventService qaEventService;
@@ -47,13 +49,14 @@ public class WithdrawnCorrectionType implements CorrectionType, InitializingBean
}
@Override
public QAEvent createCorrection(Context context, Item targetItem) {
public QAEvent createCorrection(Context context, Item targetItem, QAMessageDTO reason) {
CorrectionTypeMessageDTO mesasge = (CorrectionTypeMessageDTO) reason;
QAEvent qaEvent = new QAEvent(INTERNAL_ITEM_SOURCE,
"handle:" + targetItem.getHandle(),
targetItem.getID().toString(),
targetItem.getName(),
this.getTopic(), 1.0,
new Gson().toJson(new Object()),
new Gson().toJson(mesasge),
new Date()
);
@@ -68,8 +71,8 @@ public class WithdrawnCorrectionType implements CorrectionType, InitializingBean
}
@Override
public QAEvent createCorrection(Context context, Item targetItem, Item relatedItem) {
return createCorrection(context, targetItem);
public QAEvent createCorrection(Context context, Item targetItem, Item relatedItem, QAMessageDTO reason) {
return createCorrection(context, targetItem, reason);
}
@Override
@@ -100,12 +103,11 @@ public class WithdrawnCorrectionType implements CorrectionType, InitializingBean
@Override
public String getCreationForm() {
return EMPTY;
return this.creationForm;
}
@Override
public String getDiscoveryConfiguration() {
return EMPTY;
public void setCreationForm(String creationForm) {
this.creationForm = creationForm;
}
}

View File

@@ -0,0 +1,37 @@
/**
* 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.qaevent.service.dto;
import java.io.Serializable;
/**
* Implementation of {@link QAMessageDTO} that model empty message.
*
* @author Mykhaylo Boychuk (mykhaylo.boychuk at 4science.it)
*/
public class CorrectionTypeMessageDTO implements QAMessageDTO, Serializable {
private static final long serialVersionUID = 2718151302291303796L;
private String reason;
public CorrectionTypeMessageDTO() {}
public CorrectionTypeMessageDTO(String reason) {
this.reason = reason;
}
public String getReason() {
return reason;
}
public void setReason(String reason) {
this.reason = reason;
}
}

View File

@@ -1,10 +0,0 @@
package org.dspace.qaevent.service.dto;
/**
* Implementation of {@link QAMessageDTO} that model empty message.
*
* @author Mykhaylo Boychuk (mykhaylo.boychuk at 4science.it)
*/
public class EmptyMessageDTO implements QAMessageDTO {
}

View File

@@ -17,5 +17,4 @@ import org.dspace.content.QAEvent;
*/
public interface QAMessageDTO {
}

View File

@@ -292,7 +292,7 @@ public class QAEventServiceImpl implements QAEventService {
solrQuery.setRows(pageSize);
}
solrQuery.setSort(orderField, ascending ? ORDER.asc : ORDER.desc);
solrQuery.setQuery(TOPIC + ":" + topic.replaceAll("!", "/"));
solrQuery.setQuery(TOPIC + ":" + topic.replaceAll("!", "\\\\/"));
QueryResponse response;
try {

View File

@@ -27,7 +27,6 @@ public class CorrectionTypeConverter implements DSpaceConverter<CorrectionType,
targetRest.setProjection(projection);
targetRest.setId(target.getId());
targetRest.setTopic(target.getTopic());
targetRest.setDiscoveryConfiguration(target.getDiscoveryConfiguration());
targetRest.setCreationForm(target.getCreationForm());
return targetRest;
}

View File

@@ -14,13 +14,13 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.json.JsonMapper;
import org.dspace.app.rest.model.EmptyQAEventMessageRest;
import org.dspace.app.rest.model.CorrectionTypeQAEventMessageRest;
import org.dspace.app.rest.model.OpenaireQAEventMessageRest;
import org.dspace.app.rest.model.QAEventMessageRest;
import org.dspace.app.rest.model.QAEventRest;
import org.dspace.app.rest.projection.Projection;
import org.dspace.content.QAEvent;
import org.dspace.qaevent.service.dto.EmptyMessageDTO;
import org.dspace.qaevent.service.dto.CorrectionTypeMessageDTO;
import org.dspace.qaevent.service.dto.OpenaireMessageDTO;
import org.dspace.qaevent.service.dto.QAMessageDTO;
import org.dspace.services.ConfigurationService;
@@ -58,7 +58,7 @@ public class QAEventConverter implements DSpaceConverter<QAEvent, QAEventRest> {
rest.setMessage(convertMessage(jsonMapper.readValue(modelObject.getMessage(),
modelObject.getMessageDtoClass())));
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
throw new RuntimeException(e.getMessage(), e);
}
rest.setSource(modelObject.getSource());
rest.setOriginalId(modelObject.getOriginalId());
@@ -76,12 +76,19 @@ public class QAEventConverter implements DSpaceConverter<QAEvent, QAEventRest> {
if (dto instanceof OpenaireMessageDTO) {
return convertOpenaireMessage(dto);
}
if (dto instanceof EmptyMessageDTO) {
return new EmptyQAEventMessageRest();
if (dto instanceof CorrectionTypeMessageDTO) {
return convertCorrectionTypeMessage(dto);
}
throw new IllegalArgumentException("Unknown message type: " + dto.getClass());
}
private QAEventMessageRest convertCorrectionTypeMessage(QAMessageDTO dto) {
CorrectionTypeMessageDTO correctionTypeDto = (CorrectionTypeMessageDTO) dto;
CorrectionTypeQAEventMessageRest message = new CorrectionTypeQAEventMessageRest();
message.setReason(correctionTypeDto.getReason());
return message;
}
private QAEventMessageRest convertOpenaireMessage(QAMessageDTO dto) {
OpenaireMessageDTO openaireDto = (OpenaireMessageDTO) dto;
OpenaireQAEventMessageRest message = new OpenaireQAEventMessageRest();

View File

@@ -0,0 +1,25 @@
/**
* 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;
/**
* @author Mykhaylo Boychuk (mykhaylo.boychuk@4science.com)
*/
public class CorrectionTypeQAEventMessageRest implements QAEventMessageRest {
private String reason;
public String getReason() {
return reason;
}
public void setReason(String reason) {
this.reason = reason;
}
}

View File

@@ -7,6 +7,7 @@
*/
package org.dspace.app.rest.model;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.dspace.app.rest.RestResourceController;
/**
@@ -23,7 +24,6 @@ public class CorrectionTypeRest extends BaseObjectRest<String> {
private String topic;
private String creationForm;
private String discoveryConfiguration;
public String getTopic() {
return topic;
@@ -33,14 +33,6 @@ public class CorrectionTypeRest extends BaseObjectRest<String> {
this.topic = topic;
}
public String getDiscoveryConfiguration() {
return discoveryConfiguration;
}
public void setDiscoveryConfiguration(String discoveryConfiguration) {
this.discoveryConfiguration = discoveryConfiguration;
}
public String getCreationForm() {
return creationForm;
}
@@ -55,6 +47,7 @@ public class CorrectionTypeRest extends BaseObjectRest<String> {
}
@Override
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
public String getType() {
return NAME;
}

View File

@@ -1,12 +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;
public class EmptyQAEventMessageRest implements QAEventMessageRest {
}

View File

@@ -7,31 +7,34 @@
*/
package org.dspace.app.rest.repository;
import static org.dspace.core.Constants.ITEM;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang.StringUtils;
import org.dspace.app.rest.Parameter;
import org.dspace.app.rest.SearchRestMethod;
import org.dspace.app.rest.exception.RepositoryMethodNotImplementedException;
import org.dspace.app.rest.exception.UnprocessableEntityException;
import org.dspace.app.rest.model.QAEventRest;
import org.dspace.app.rest.model.patch.Patch;
import org.dspace.app.rest.repository.handler.service.UriListHandlerService;
import org.dspace.app.rest.repository.patch.ResourcePatch;
import org.dspace.authorize.AuthorizeException;
import org.dspace.content.DSpaceObject;
import org.dspace.content.Item;
import org.dspace.content.QAEvent;
import org.dspace.content.service.ItemService;
import org.dspace.core.Context;
import org.dspace.correctiontype.CorrectionType;
import org.dspace.correctiontype.service.CorrectionTypeService;
import org.dspace.eperson.EPerson;
import org.dspace.qaevent.dao.QAEventsDao;
import org.dspace.qaevent.service.QAEventService;
import org.dspace.qaevent.service.dto.CorrectionTypeMessageDTO;
import org.dspace.util.UUIDUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
@@ -64,7 +67,7 @@ public class QAEventRestRepository extends DSpaceRestRepository<QAEventRest, Str
private ResourcePatch<QAEvent> resourcePatch;
@Autowired
private UriListHandlerService uriListHandlerService;
private CorrectionTypeService correctionTypeService;
@Override
@PreAuthorize("hasAuthority('ADMIN')")
@@ -137,47 +140,58 @@ public class QAEventRestRepository extends DSpaceRestRepository<QAEventRest, Str
@Override
@PreAuthorize("hasAuthority('AUTHENTICATED')")
protected QAEventRest createAndReturn(Context context, List<String> stringList)
throws SQLException, AuthorizeException {
protected QAEventRest createAndReturn(Context context) throws SQLException, AuthorizeException {
ServletRequest request = getRequestService().getCurrentRequest().getServletRequest();
if (stringList.size() < 2) {
throw new IllegalArgumentException("the request must include at least uris for target item, " +
"and correction type");
String itemUUID = request.getParameter("target");
String relatedItemUUID = request.getParameter("related");
String correctionTypeStr = request.getParameter("correctionType");
if (StringUtils.isBlank(correctionTypeStr) || StringUtils.isBlank(itemUUID)) {
throw new UnprocessableEntityException("The target item and correctionType must be provided!");
}
HttpServletRequest request = getRequestService().getCurrentRequest().getHttpServletRequest();
CorrectionType correctionType = uriListHandlerService.handle(context, request, List.of(stringList.get(0)),
CorrectionType.class);
Item targetItem = null;
Item relatedItem = null;
try {
targetItem = itemService.find(context, UUID.fromString(itemUUID));
relatedItem = StringUtils.isNotBlank(relatedItemUUID) ?
itemService.find(context, UUID.fromString(relatedItemUUID)) : null;
} catch (Exception e) {
throw new UnprocessableEntityException(e.getMessage(), e);
}
if (Objects.isNull(targetItem)) {
throw new UnprocessableEntityException("The target item UUID is not valid!");
}
CorrectionType correctionType = correctionTypeService.findOne(correctionTypeStr);
if (Objects.isNull(correctionType)) {
throw new UnprocessableEntityException("The given correction type in the request is not valid!");
}
List<DSpaceObject> list = utils.constructDSpaceObjectList(context, stringList);
if (correctionType.isRequiredRelatedItem() && Objects.isNull(relatedItem)) {
throw new UnprocessableEntityException("The given correction type in the request is not valid!");
}
ObjectMapper mapper = new ObjectMapper();
CorrectionTypeMessageDTO reason = null;
try {
reason = mapper.readValue(request.getInputStream(), CorrectionTypeMessageDTO.class);
} catch (IOException exIO) {
throw new UnprocessableEntityException("error parsing the body " + exIO.getMessage(), exIO);
}
QAEvent qaEvent;
List<Item> items = getItems(list, correctionType);
if (correctionType.isRequiredRelatedItem()) {
qaEvent = correctionType.createCorrection(context, items.get(0), items.get(1));
qaEvent = correctionType.createCorrection(context, targetItem, relatedItem, reason);
} else {
qaEvent = correctionType.createCorrection(context, items.get(0));
qaEvent = correctionType.createCorrection(context, targetItem, reason);
}
return converter.toRest(qaEvent, utils.obtainProjection());
}
private List<Item> getItems(List<DSpaceObject> list, CorrectionType correctionType) {
if (correctionType.isRequiredRelatedItem()) {
if (list.size() == 2 && list.get(0).getType() == ITEM && list.get(1).getType() == ITEM) {
return List.of((Item) list.get(0), (Item) list.get(1));
} else {
throw new UnprocessableEntityException("The given items in the request were not valid!");
}
} else if (list.size() != 1) {
throw new UnprocessableEntityException("The given item in the request were not valid!");
} else {
return List.of((Item) list.get(0));
}
}
@Override
public Class<QAEventRest> getDomainClass() {
return QAEventRest.class;

View File

@@ -50,12 +50,15 @@ public class CorrectionTypeRestRepositoryIT extends AbstractControllerIntegratio
.andExpect(jsonPath("$.page.totalElements", greaterThanOrEqualTo(2)))
.andExpect(jsonPath("$._embedded.correctiontypes", containsInAnyOrder(
allOf(
hasJsonPath("$.id", equalTo("withdrawnRequest")),
hasJsonPath("$.topic", equalTo("REQUEST/WITHDRAWN"))
hasJsonPath("$.id", equalTo("request-withdrawn")),
hasJsonPath("$.topic", equalTo("REQUEST/WITHDRAWN")),
hasJsonPath("$.creationForm", equalTo("provideReason")),
hasJsonPath("$.type", equalTo("correctiontype"))
),
allOf(
hasJsonPath("$.id", equalTo("reinstateRequest")),
hasJsonPath("$.topic", equalTo("REQUEST/REINSTATE"))
hasJsonPath("$.id", equalTo("request-reinstate")),
hasJsonPath("$.topic", equalTo("REQUEST/REINSTATE")),
hasJsonPath("$.type", equalTo("correctiontype"))
)
)));
}
@@ -63,10 +66,12 @@ public class CorrectionTypeRestRepositoryIT extends AbstractControllerIntegratio
@Test
public void findOneTest() throws Exception {
String adminToken = getAuthToken(admin.getEmail(), password);
getClient(adminToken).perform(get("/api/config/correctiontypes/withdrawnRequest"))
getClient(adminToken).perform(get("/api/config/correctiontypes/request-withdrawn"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.id", equalTo("withdrawnRequest")))
.andExpect(jsonPath("$.topic", equalTo("REQUEST/WITHDRAWN")));
.andExpect(jsonPath("$.id", equalTo("request-withdrawn")))
.andExpect(jsonPath("$.topic", equalTo("REQUEST/WITHDRAWN")))
.andExpect(jsonPath("$.creationForm", equalTo("provideReason")))
.andExpect(jsonPath("$.type", equalTo("correctiontype")));
}
@Test
@@ -79,14 +84,14 @@ public class CorrectionTypeRestRepositoryIT extends AbstractControllerIntegratio
@Test
public void findByItemWithoutUUIDParameterTest() throws Exception {
String adminToken = getAuthToken(admin.getEmail(), password);
getClient(adminToken).perform(get("/api/config/correctiontypes/search/findByItem/"))
getClient(adminToken).perform(get("/api/config/correctiontypes/search/findByItem"))
.andExpect(status().isBadRequest());
}
@Test
public void findByItemNotFoundTest() throws Exception {
String adminToken = getAuthToken(admin.getEmail(), password);
getClient(adminToken).perform(get("/api/config/correctiontypes/search/findByItem/")
getClient(adminToken).perform(get("/api/config/correctiontypes/search/findByItem")
.param("uuid", UUID.randomUUID().toString()))
.andExpect(status().isUnprocessableEntity());
}
@@ -100,7 +105,7 @@ public class CorrectionTypeRestRepositoryIT extends AbstractControllerIntegratio
authorizeService.removeAllPolicies(context, privateItem);
context.restoreAuthSystemState();
getClient().perform(get("/api/config/correctiontypes/search/findByItem/")
getClient().perform(get("/api/config/correctiontypes/search/findByItem")
.param("uuid", privateItem.getID().toString()))
.andExpect(status().isUnauthorized());
}
@@ -116,7 +121,7 @@ public class CorrectionTypeRestRepositoryIT extends AbstractControllerIntegratio
context.restoreAuthSystemState();
String adminToken = getAuthToken(admin.getEmail(), password);
getClient(adminToken).perform(get("/api/config/correctiontypes/search/findByItem/")
getClient(adminToken).perform(get("/api/config/correctiontypes/search/findByItem")
.param("uuid", item.getID().toString()))
.andExpect(status().isOk())
.andExpect(jsonPath("$.page.totalElements", is(0)));
@@ -135,12 +140,12 @@ public class CorrectionTypeRestRepositoryIT extends AbstractControllerIntegratio
context.restoreAuthSystemState();
String tokenAdmin = getAuthToken(admin.getEmail(), password);
getClient(tokenAdmin).perform(get("/api/config/correctiontypes/search/findByItem/")
getClient(tokenAdmin).perform(get("/api/config/correctiontypes/search/findByItem")
.param("uuid", item.getID().toString()))
.andExpect(status().isOk())
.andExpect(jsonPath("$.page.totalElements", is(1)))
.andExpect(jsonPath("$._embedded.correctiontypes", containsInAnyOrder(allOf(
hasJsonPath("$.id", equalTo("reinstateRequest")),
hasJsonPath("$.id", equalTo("request-reinstate")),
hasJsonPath("$.topic", equalTo("REQUEST/REINSTATE"))
))));
}
@@ -156,14 +161,16 @@ public class CorrectionTypeRestRepositoryIT extends AbstractControllerIntegratio
context.restoreAuthSystemState();
String adminToken = getAuthToken(admin.getEmail(), password);
getClient(adminToken).perform(get("/api/config/correctiontypes/search/findByItem/")
getClient(adminToken).perform(get("/api/config/correctiontypes/search/findByItem")
.param("uuid", item.getID().toString()))
.andExpect(status().isOk())
.andExpect(jsonPath("$.page.totalElements", is(1)))
.andExpect(jsonPath("$._embedded.correctiontypes", containsInAnyOrder(
allOf(
hasJsonPath("$.id", equalTo("withdrawnRequest")),
hasJsonPath("$.topic", equalTo("REQUEST/WITHDRAWN"))
hasJsonPath("$.id", equalTo("request-withdrawn")),
hasJsonPath("$.topic", equalTo("REQUEST/WITHDRAWN")),
hasJsonPath("$.creationForm", equalTo("provideReason")),
hasJsonPath("$.type", equalTo("correctiontype"))
)
)));
}
@@ -179,14 +186,16 @@ public class CorrectionTypeRestRepositoryIT extends AbstractControllerIntegratio
context.restoreAuthSystemState();
String adminToken = getAuthToken(admin.getEmail(), password);
getClient(adminToken).perform(get("/api/config/correctiontypes/search/findByItem/")
getClient(adminToken).perform(get("/api/config/correctiontypes/search/findByItem")
.param("uuid", itemOne.getID().toString()))
.andExpect(status().isOk())
.andExpect(jsonPath("$.page.totalElements", is(1)))
.andExpect(jsonPath("$._embedded.correctiontypes", containsInAnyOrder(
allOf(
hasJsonPath("$.id", equalTo("withdrawnRequest")),
hasJsonPath("$.topic", equalTo("REQUEST/WITHDRAWN"))
hasJsonPath("$.id", equalTo("request-withdrawn")),
hasJsonPath("$.topic", equalTo("REQUEST/WITHDRAWN")),
hasJsonPath("$.creationForm", equalTo("provideReason")),
hasJsonPath("$.type", equalTo("correctiontype"))
)
)));
@@ -201,14 +210,16 @@ public class CorrectionTypeRestRepositoryIT extends AbstractControllerIntegratio
context.restoreAuthSystemState();
String adminToken = getAuthToken(admin.getEmail(), password);
getClient(adminToken).perform(get("/api/config/correctiontypes/search/findByItem/")
getClient(adminToken).perform(get("/api/config/correctiontypes/search/findByItem")
.param("uuid", item.getID().toString()))
.andExpect(status().isOk())
.andExpect(jsonPath("$.page.totalElements", is(1)))
.andExpect(jsonPath("$._embedded.correctiontypes", containsInAnyOrder(
allOf(
hasJsonPath("$.id", equalTo("withdrawnRequest")),
hasJsonPath("$.topic", equalTo("REQUEST/WITHDRAWN"))
hasJsonPath("$.id", equalTo("request-withdrawn")),
hasJsonPath("$.topic", equalTo("REQUEST/WITHDRAWN")),
hasJsonPath("$.creationForm", equalTo("provideReason")),
hasJsonPath("$.type", equalTo("correctiontype"))
)
)));
}
@@ -216,14 +227,14 @@ public class CorrectionTypeRestRepositoryIT extends AbstractControllerIntegratio
@Test
public void findByTopicWithoutTopicParameterTest() throws Exception {
String adminToken = getAuthToken(admin.getEmail(), password);
getClient(adminToken).perform(get("/api/config/correctiontypes/search/findByTopic/"))
getClient(adminToken).perform(get("/api/config/correctiontypes/search/findByTopic"))
.andExpect(status().isBadRequest());
}
@Test
public void findByWrongTopicTest() throws Exception {
String adminToken = getAuthToken(admin.getEmail(), password);
getClient(adminToken).perform(get("/api/config/correctiontypes/search/findByTopic/")
getClient(adminToken).perform(get("/api/config/correctiontypes/search/findByTopic")
.param("topic", "wrongValue"))
.andExpect(status().isNoContent());
}
@@ -231,11 +242,13 @@ public class CorrectionTypeRestRepositoryIT extends AbstractControllerIntegratio
@Test
public void findByTopicTest() throws Exception {
String adminToken = getAuthToken(admin.getEmail(), password);
getClient(adminToken).perform(get("/api/config/correctiontypes/search/findByTopic/")
getClient(adminToken).perform(get("/api/config/correctiontypes/search/findByTopic")
.param("topic", "REQUEST/WITHDRAWN"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.id", equalTo("withdrawnRequest")))
.andExpect(jsonPath("$.topic", equalTo("REQUEST/WITHDRAWN")));
.andExpect(jsonPath("$.id", equalTo("request-withdrawn")))
.andExpect(jsonPath("$.topic", equalTo("REQUEST/WITHDRAWN")))
.andExpect(jsonPath("$.creationForm", equalTo("provideReason")))
.andExpect(jsonPath("$.type", equalTo("correctiontype")));
}
}

View File

@@ -31,6 +31,7 @@ import java.util.UUID;
import java.util.concurrent.atomic.AtomicReference;
import javax.ws.rs.core.MediaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.dspace.app.rest.matcher.ItemMatcher;
import org.dspace.app.rest.matcher.QAEventMatcher;
import org.dspace.app.rest.model.patch.Operation;
@@ -48,6 +49,7 @@ import org.dspace.content.Item;
import org.dspace.content.QAEvent;
import org.dspace.content.QAEventProcessed;
import org.dspace.qaevent.dao.QAEventsDao;
import org.dspace.qaevent.service.dto.CorrectionTypeMessageDTO;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
@@ -890,6 +892,7 @@ public class QAEventRestRepositoryIT extends AbstractControllerIntegrationTest {
context.restoreAuthSystemState();
String adminToken = getAuthToken(admin.getEmail(), password);
String ePersonToken = getAuthToken(eperson.getEmail(), password);
getClient(adminToken).perform(get("/api/core/items/" + publication.getID()))
.andExpect(status().isOk())
.andExpect(jsonPath("$.inArchive", is(false)))
@@ -897,11 +900,14 @@ public class QAEventRestRepositoryIT extends AbstractControllerIntegrationTest {
AtomicReference<String> idRef = new AtomicReference<String>();
getClient(adminToken).perform(post("/api/integration/qualityassuranceevents")
.contentType(RestMediaTypes.TEXT_URI_LIST)
.content("https://localhost:8080/server/api/config/correctiontypes/reinstateRequest\n" +
"https://localhost:8080/server/api/core/items/" + publication.getID()
))
ObjectMapper mapper = new ObjectMapper();
CorrectionTypeMessageDTO dto = new CorrectionTypeMessageDTO("provided reason!");
getClient(ePersonToken).perform(post("/api/integration/qualityassuranceevents")
.param("correctionType", "request-withdrawn")
.param("target", publication.getID().toString())
.contentType(contentType)
.content(mapper.writeValueAsBytes(dto)))
.andExpect(status().isCreated())
.andDo(result -> idRef.set(read(result.getResponse().getContentAsString(), "$.id")));

View File

@@ -5,12 +5,13 @@
default-lazy-init="true">
<bean id="withdrawnRequest" class="org.dspace.correctiontype.WithdrawnCorrectionType" >
<property name="id" value="withdrawnRequest"/>
<property name="id" value="request-withdrawn"/>
<property name="topic" value="REQUEST/WITHDRAWN"/>
<property name="creationForm" value="provideReason"/>
</bean>
<bean id="reinstateRequest" class="org.dspace.correctiontype.ReinstateCorrectionType" >
<property name="id" value="reinstateRequest"/>
<property name="id" value="request-reinstate"/>
<property name="topic" value="REQUEST/REINSTATE"/>
</bean>