Merge pull request #10329 from tdonohue/port_9950_to_8x

[Port dspace-8_x] added expunge request param and enabled workflowitem delete based on it
This commit is contained in:
Tim Donohue
2025-01-24 10:47:34 -06:00
committed by GitHub
2 changed files with 79 additions and 1 deletions

View File

@@ -71,6 +71,7 @@ import org.springframework.web.multipart.MultipartFile;
public class WorkflowItemRestRepository extends DSpaceRestRepository<WorkflowItemRest, Integer> { public class WorkflowItemRestRepository extends DSpaceRestRepository<WorkflowItemRest, Integer> {
public static final String OPERATION_PATH_SECTIONS = "sections"; public static final String OPERATION_PATH_SECTIONS = "sections";
public static final String REQUESTPARAMETER_EXPUNGE = "expunge";
private static final Logger log = LogManager.getLogger(); private static final Logger log = LogManager.getLogger();
@@ -239,13 +240,25 @@ public class WorkflowItemRestRepository extends DSpaceRestRepository<WorkflowIte
* move the workflowitem back to the submitter workspace regardless to how the workflow is designed * move the workflowitem back to the submitter workspace regardless to how the workflow is designed
*/ */
protected void delete(Context context, Integer id) { protected void delete(Context context, Integer id) {
String expungeParam = getRequestService()
.getCurrentRequest()
.getServletRequest()
.getParameter(REQUESTPARAMETER_EXPUNGE);
boolean expunge = false;
if (expungeParam != null) {
expunge = Boolean.parseBoolean(expungeParam);
}
XmlWorkflowItem witem = null; XmlWorkflowItem witem = null;
try { try {
witem = wis.find(context, id); witem = wis.find(context, id);
if (witem == null) { if (witem == null) {
throw new ResourceNotFoundException("WorkflowItem ID " + id + " not found"); throw new ResourceNotFoundException("WorkflowItem ID " + id + " not found");
} }
wfs.abort(context, witem, context.getCurrentUser()); if (expunge) {
wis.delete(context, witem);
} else {
wfs.abort(context, witem, context.getCurrentUser());
}
} catch (AuthorizeException e) { } catch (AuthorizeException e) {
throw new RESTAuthorizationException(e); throw new RESTAuthorizationException(e);
} catch (SQLException e) { } catch (SQLException e) {

View File

@@ -686,6 +686,71 @@ public class WorkflowItemRestRepositoryIT extends AbstractControllerIntegrationT
.andExpect(jsonPath("$.page.totalElements", is(1))); .andExpect(jsonPath("$.page.totalElements", is(1)));
} }
@Test
/**
* A delete request over a workflowitem with expunge param should result in delete item over detabase
* workspace
*
* @throws Exception
*/
public void deleteOneWithExpungeTest() throws Exception {
context.turnOffAuthorisationSystem();
//** GIVEN **
//1. A community with one collection.
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community")
.build();
Collection col1 = CollectionBuilder.createCollection(context, parentCommunity).withName("Collection 1")
.withWorkflowGroup(1, admin).build();
//2. create a normal user to use as submitter
EPerson submitter = EPersonBuilder.createEPerson(context)
.withEmail("submitter@example.com")
.withPassword("dspace")
.build();
context.setCurrentUser(submitter);
//3. a workflow item
XmlWorkflowItem witem = WorkflowItemBuilder.createWorkflowItem(context, col1)
.withTitle("Workflow Item 1")
.withIssueDate("2017-10-17")
.build();
Item item = witem.getItem();
//Add a bitstream to the item
String bitstreamContent = "ThisIsSomeDummyText";
Bitstream bitstream = null;
try (InputStream is = IOUtils.toInputStream(bitstreamContent, Charset.defaultCharset())) {
bitstream = BitstreamBuilder
.createBitstream(context, item, is)
.withName("Bitstream1")
.withMimeType("text/plain").build();
}
context.restoreAuthSystemState();
String token = getAuthToken(admin.getEmail(), password);
// Delete the workflowitem
getClient(token).perform(delete("/api/workflow/workflowitems/" + witem.getID() + "?expunge=true"))
.andExpect(status().is(204));
// Trying to get deleted workflowitem should fail with 404
getClient(token).perform(get("/api/workflow/workflowitems/" + witem.getID()))
.andExpect(status().is(404));
// the workflowitem's item should fail with 404
getClient(token).perform(get("/api/core/items/" + item.getID()))
.andExpect(status().is(404));
// the workflowitem's bitstream should fail with 404
getClient(token).perform(get("/api/core/bitstreams/" + bitstream.getID()))
.andExpect(status().is(404));
}
@Test @Test
/** /**
* Test the deposit of a workspaceitem POSTing to the resource workflowitems collection endpoint a workspaceitem (as * Test the deposit of a workspaceitem POSTing to the resource workflowitems collection endpoint a workspaceitem (as