90948: Add custom exception for deleting Group with pending tasks

This commit is contained in:
Yura Bondarenko
2022-04-28 16:46:31 +02:00
parent 122924af82
commit c00cdd4d0d
5 changed files with 42 additions and 2 deletions

View File

@@ -119,3 +119,4 @@ org.dspace.app.rest.exception.RESTEmptyWorkflowGroupException.message = Refused
workflow group {1}. Delete the tasks and group first if you want to remove this user.
org.dspace.app.rest.exception.EPersonNameNotProvidedException.message = The eperson.firstname and eperson.lastname values need to be filled in
org.dspace.app.rest.exception.GroupNameNotProvidedException.message = Cannot create group, no group name is provided
org.dspace.app.rest.exception.GroupHasPendingWorkflowTasksException.message = Cannot delete group, the associated workflow role still has pending tasks

View File

@@ -133,6 +133,7 @@ public class DSpaceApiExceptionControllerAdvice extends ResponseEntityExceptionH
RESTEmptyWorkflowGroupException.class,
EPersonNameNotProvidedException.class,
GroupNameNotProvidedException.class,
GroupHasPendingWorkflowTasksException.class,
})
protected void handleCustomUnprocessableEntityException(HttpServletRequest request, HttpServletResponse response,
TranslatableException ex) throws IOException {

View File

@@ -0,0 +1,36 @@
/**
* 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.exception;
import org.dspace.core.I18nUtil;
/**
* <p>Extend {@link UnprocessableEntityException} to provide a specific error message
* in the REST response. The error message is added to the response in
* {@link DSpaceApiExceptionControllerAdvice#handleCustomUnprocessableEntityException},
* hence it should not contain sensitive or security-compromising info.</p>
*
*/
public class GroupHasPendingWorkflowTasksException
extends UnprocessableEntityException implements TranslatableException {
public static final String MESSAGE_KEY =
"org.dspace.app.rest.exception.GroupHasPendingTasksException.message";
public GroupHasPendingWorkflowTasksException() {
super(I18nUtil.getMessage(MESSAGE_KEY));
}
public GroupHasPendingWorkflowTasksException(Throwable cause) {
super(I18nUtil.getMessage(MESSAGE_KEY), cause);
}
public String getMessageKey() {
return MESSAGE_KEY;
}
}

View File

@@ -24,6 +24,7 @@ import org.apache.logging.log4j.Logger;
import org.dspace.app.rest.Parameter;
import org.dspace.app.rest.SearchRestMethod;
import org.dspace.app.rest.exception.DSpaceBadRequestException;
import org.dspace.app.rest.exception.GroupHasPendingWorkflowTasksException;
import org.dspace.app.rest.exception.RepositoryMethodNotImplementedException;
import org.dspace.app.rest.exception.UnprocessableEntityException;
import org.dspace.app.rest.model.BitstreamRest;
@@ -695,8 +696,8 @@ public class CollectionRestRepository extends DSpaceObjectRestRepository<Collect
throws SQLException, WorkflowConfigurationException, AuthorizeException, WorkflowException, IOException {
Group group = workflowService.getWorkflowRoleGroup(context, collection, workflowRole, null);
if (!poolTaskService.findByGroup(context, group).isEmpty()) {
throw new UnprocessableEntityException("The Group that was attempted to be deleted " +
"still has Pooltasks open");
// todo: also handle claimed tasks that would become associated with this group once returned to the pool
throw new GroupHasPendingWorkflowTasksException();
}
if (group == null) {
throw new ResourceNotFoundException("The requested Group was not found");

View File

@@ -11,3 +11,4 @@ org.dspace.app.rest.exception.RESTEmptyWorkflowGroupException.message = [PL] Ref
workflow group {1}. Delete the tasks and group first if you want to remove this user.
org.dspace.app.rest.exception.EPersonNameNotProvidedException.message = [PL] The eperson.firstname and eperson.lastname values need to be filled in
org.dspace.app.rest.exception.GroupNameNotProvidedException.message = [PL] Cannot create group, no group name is provided
org.dspace.app.rest.exception.GroupHasPendingWorkflowTasksException.message = [PL] Cannot delete group, the associated workflow role still has pending tasks