Skip to content

Commit

Permalink
added expunge request param and enabled workflowitem delete based on …
Browse files Browse the repository at this point in the history
…it (DSpace#9950)

* added expunge request param and enabled workflowitem delete based on it

* enabled expunge param only in workflowitem delete endpoint and IT

* Remove invalid param from JavaDocs

---------

Co-authored-by: Tim Donohue <tim.donohue@lyrasis.org>
  • Loading branch information
oscar-escire and tdonohue authored Jan 24, 2025
1 parent e405f1f commit c5e6d55
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
public class WorkflowItemRestRepository extends DSpaceRestRepository<WorkflowItemRest, Integer> {

public static final String OPERATION_PATH_SECTIONS = "sections";
public static final String REQUESTPARAMETER_EXPUNGE = "expunge";

private static final Logger log = LogManager.getLogger();

Expand Down Expand Up @@ -239,13 +240,25 @@ public void patch(Context context, HttpServletRequest request, String apiCategor
* move the workflowitem back to the submitter workspace regardless to how the workflow is designed
*/
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;
try {
witem = wis.find(context, id);
if (witem == null) {
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) {
throw new RESTAuthorizationException(e);
} catch (SQLException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,71 @@ public void deleteOneTest() throws Exception {
.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 the deposit of a workspaceitem POSTing to the resource workflowitems collection endpoint a workspaceitem (as
Expand Down

0 comments on commit c5e6d55

Please sign in to comment.