Skip to content

Commit

Permalink
workflowApi - PUT requests return http 500 if ID is unknown
Browse files Browse the repository at this point in the history
  • Loading branch information
WangLiNaruto committed Jan 4, 2024
1 parent 0f5a65e commit ecb35d6
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import lombok.extern.slf4j.Slf4j;
import org.eclipse.xpanse.modules.models.response.Response;
import org.eclipse.xpanse.modules.models.response.ResultType;
import org.eclipse.xpanse.modules.models.service.deploy.exceptions.ActivitiTaskNotFoundException;
import org.eclipse.xpanse.modules.models.service.deploy.exceptions.DeployerNotFoundException;
import org.eclipse.xpanse.modules.models.service.deploy.exceptions.FlavorInvalidException;
import org.eclipse.xpanse.modules.models.service.deploy.exceptions.InvalidDeploymentVariableException;
Expand Down Expand Up @@ -170,4 +171,16 @@ public Response handleServiceDetailsNotAccessible(
return Response.errorResponse(ResultType.SERVICE_DETAILS_NOT_ACCESSIBLE,
Collections.singletonList(ex.getMessage()));
}

/**
* Exception handler for ActivitiTaskNotFoundException.
*/
@ExceptionHandler({ActivitiTaskNotFoundException.class})
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody
public Response handleActivitiTaskNotFoundException(
ActivitiTaskNotFoundException ex) {
return Response.errorResponse(ResultType.ACTIVITI_TASK_NOT_FOUND,
Collections.singletonList(ex.getMessage()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public enum ResultType {
POLICY_VALIDATION_FAILED("Policy Validation Failed"),
POLICY_EVALUATION_FAILED("Policy Evaluation Failed"),
USER_NO_LOGIN_EXCEPTION("Current Login User No Found"),
SERVICE_DETAILS_NOT_ACCESSIBLE("Service Details No Accessible");
SERVICE_DETAILS_NOT_ACCESSIBLE("Service Details No Accessible"),
ACTIVITI_TASK_NOT_FOUND("Migrating activiti Task Not Found");

private final String value;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* SPDX-License-Identifier: Apache-2.0
* SPDX-FileCopyrightText: Huawei Inc.
*/

package org.eclipse.xpanse.modules.models.service.deploy.exceptions;


/**
* Exception thrown when the during migration, the migration task was not found.
*/
public class ActivitiTaskNotFoundException extends RuntimeException {
public ActivitiTaskNotFoundException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.activiti.engine.task.TaskInfo;
import org.eclipse.xpanse.modules.models.service.deploy.exceptions.ServiceNotDeployedException;
import org.eclipse.xpanse.modules.models.workflow.WorkFlowTask;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -93,6 +94,7 @@ public List<WorkFlowTask> doneTasks(String userId) {
* @param variables global process variables.
*/
public void completeTask(String taskId, Map<String, Object> variables) {
vaildateTaskId(taskId);
taskService.complete(taskId, variables);
}

Expand Down Expand Up @@ -120,4 +122,12 @@ private List<WorkFlowTask> transHistoricTaskInstanceToWorkFlowTask(
List<HistoricTaskInstance> list) {
return list.stream().map(this::getWorkFlow).collect(Collectors.toList());
}

private void vaildateTaskId(String taskId) {
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
if (task == null) {
throw new ServiceNotDeployedException("The migrated activiti task was not found, "
+ "taskId: " + taskId);
}
}
}

0 comments on commit ecb35d6

Please sign in to comment.