Skip to content

Commit d02b883

Browse files
authored
Merge pull request #163 from folio-org/MODWRKFLOW-72
MODWRKFLOW-72: Properly handle when workflow engine does not have a workflow to deactivate on workflow delete.
2 parents b995534 + ded791d commit d02b883

8 files changed

Lines changed: 784 additions & 224 deletions

File tree

service/src/main/java/org/folio/rest/workflow/controller/WorkflowController.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.regex.Pattern;
88
import org.apache.commons.logging.Log;
99
import org.apache.commons.logging.LogFactory;
10+
import org.folio.rest.workflow.exception.WorkflowDeploymentNotFound;
1011
import org.folio.rest.workflow.exception.WorkflowEngineServiceException;
1112
import org.folio.rest.workflow.exception.WorkflowImportException;
1213
import org.folio.rest.workflow.exception.WorkflowNotFoundException;
@@ -138,7 +139,7 @@ public JsonNode workflowHistory(
138139
@PathVariable String id,
139140
@TenantHeader String tenant,
140141
@TokenHeader String token
141-
) throws WorkflowEngineServiceException {
142+
) throws WorkflowDeploymentNotFound, WorkflowEngineServiceException {
142143
LOG.debug(String.format("Retrieving History: %s", sanitize(id)));
143144
return workflowEngineService.history(id, tenant, token);
144145
}
@@ -149,7 +150,7 @@ public JsonNode startWorkflow(
149150
@TenantHeader String tenant,
150151
@TokenHeader String token,
151152
@RequestBody JsonNode context
152-
) throws WorkflowEngineServiceException {
153+
) throws WorkflowDeploymentNotFound, WorkflowEngineServiceException, WorkflowNotFoundException {
153154
LOG.info(String.format("Starting: %s with context %s", sanitize(id), sanitize(context)));
154155
return workflowEngineService.start(id, tenant, token, context);
155156
}

service/src/main/java/org/folio/rest/workflow/controller/advice/WorkflowControllerAdvice.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.folio.rest.workflow.exception.WorkflowAlreadyActiveException;
66
import org.folio.rest.workflow.exception.WorkflowCreateAlreadyExistsException;
77
import org.folio.rest.workflow.exception.WorkflowDeploymentException;
8+
import org.folio.rest.workflow.exception.WorkflowDeploymentNotFound;
89
import org.folio.rest.workflow.exception.WorkflowEngineServiceException;
910
import org.folio.rest.workflow.exception.WorkflowImportException;
1011
import org.folio.rest.workflow.exception.WorkflowNotFoundException;
@@ -75,6 +76,12 @@ public ResponseEntity<String> handleWorkflowDeploymentException(WorkflowDeployme
7576
return buildError(exception, HttpStatus.INTERNAL_SERVER_ERROR);
7677
}
7778

79+
@ResponseStatus(HttpStatus.NOT_FOUND)
80+
@ExceptionHandler(WorkflowDeploymentNotFound.class)
81+
public ResponseEntity<String> handleWorkflowDeploymentNotFound(WorkflowDeploymentNotFound exception) {
82+
return buildError(exception, HttpStatus.NOT_FOUND);
83+
}
84+
7885
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
7986
@ExceptionHandler(WorkflowEngineServiceException.class)
8087
public ResponseEntity<String> handleWorkflowEngineServiceException(WorkflowEngineServiceException exception) {

service/src/main/java/org/folio/rest/workflow/exception/WorkflowAlreadyActiveException.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,8 @@ public WorkflowAlreadyActiveException(String id) {
1010
super(String.format(WORKFLOW_ALREADY_ACTIVE_MESSAGE, id));
1111
}
1212

13+
public WorkflowAlreadyActiveException(String id, Exception e) {
14+
super(String.format(WORKFLOW_ALREADY_ACTIVE_MESSAGE, id), e);
15+
}
16+
1317
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.folio.rest.workflow.exception;
2+
3+
/**
4+
* For providing a 404 when any Workflow deployment is not found in the Workflow Engine.
5+
*/
6+
public class WorkflowDeploymentNotFound extends Exception {
7+
8+
private static final long serialVersionUID = 424162623670077L;
9+
10+
public WorkflowDeploymentNotFound(String message) {
11+
super(message);
12+
}
13+
14+
public WorkflowDeploymentNotFound(String message, Exception e) {
15+
super(message, e);
16+
}
17+
18+
public WorkflowDeploymentNotFound(int code) {
19+
super(Integer.toString(code));
20+
}
21+
22+
public WorkflowDeploymentNotFound(int code, Exception e) {
23+
super(Integer.toString(code), e);
24+
}
25+
26+
}

service/src/main/java/org/folio/rest/workflow/exception/WorkflowNotFoundException.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,8 @@ public WorkflowNotFoundException(String id) {
1010
super(String.format(WORKFLOW_NOT_FOUND_MESSAGE, id));
1111
}
1212

13+
public WorkflowNotFoundException(String id, Exception e) {
14+
super(String.format(WORKFLOW_NOT_FOUND_MESSAGE, id), e);
15+
}
16+
1317
}

0 commit comments

Comments
 (0)