add endpoint to reset process to earlier step

This commit is contained in:
Elizabeth Esswein 2022-12-29 15:26:29 -05:00
parent d4faa160be
commit 0edb890470
4 changed files with 103 additions and 2 deletions

View File

@ -1060,6 +1060,39 @@ paths:
schema:
$ref: "#/components/schemas/OkTrue"
/process-instance-reset/{modified_process_model_identifier}/{process_instance_id}/{spiff_step}:
parameters:
- name: modified_process_model_identifier
in: path
required: true
description: The modified process model id
schema:
type: string
- name: process_instance_id
in: path
required: true
description: The unique id of an existing process instance.
schema:
type: integer
- name: spiff_step
in: query
required: false
description: Reset the process to this state
schema:
type: integer
post:
operationId: spiffworkflow_backend.routes.process_api_blueprint.process_instance_reset
summary: Reset a process instance to an earlier step
tags:
- Process Instances
responses:
"200":
description: Empty ok true response on successful resume.
content:
application/json:
schema:
$ref: "#/components/schemas/OkTrue"
/process-instances/reports:
parameters:
- name: page

View File

@ -651,6 +651,45 @@ def process_instance_resume(
return Response(json.dumps({"ok": True}), status=200, mimetype="application/json")
def process_instance_reset(
process_instance_id: int,
modified_process_model_identifier: str,
spiff_step: int = 0,
) -> flask.wrappers.Response:
process_instance = ProcessInstanceService().get_process_instance(
process_instance_id
)
step_detail = (
db.session.query(SpiffStepDetailsModel)
.filter(
SpiffStepDetailsModel.process_instance_id == process_instance.id,
SpiffStepDetailsModel.spiff_step == spiff_step,
)
.first()
)
if step_detail is not None and process_instance.bpmn_json is not None:
bpmn_json = json.loads(process_instance.bpmn_json)
bpmn_json["tasks"] = step_detail.task_json["tasks"]
bpmn_json["subprocesses"] = step_detail.task_json["subprocesses"]
process_instance.bpmn_json = json.dumps(bpmn_json)
db.session.add(process_instance)
try:
db.session.commit()
except Exception as e:
db.session.rollback()
raise ApiError(
error_code="reset_process_instance_error",
message=f"Could not update the Instance. Original error is {e}",
) from e
return Response(
json.dumps(ProcessInstanceModelSchema().dump(process_instance)),
status=200,
mimetype="application/json",
)
def process_instance_log_list(
modified_process_model_identifier: str,
process_instance_id: int,

View File

@ -16,6 +16,7 @@ export const useUriListForPermissions = () => {
processInstanceReportListPath: '/v1.0/process-instances/reports',
processInstanceResumePath: `/v1.0/process-instance-resume/${params.process_model_id}/${params.process_instance_id}`,
processInstanceSuspendPath: `/v1.0/process-instance-suspend/${params.process_model_id}/${params.process_instance_id}`,
processInstanceResetPath: `/v1.0/process-instance-reset/${params.process_model_id}/${params.process_instance_id}`,
processInstanceTaskListDataPath: `/v1.0/task-data/${params.process_model_id}/${params.process_instance_id}`,
processInstanceSendEventPath: `/v1.0/send-event/${params.process_model_id}/${params.process_instance_id}`,
processInstanceCompleteTaskPath: `/v1.0/complete-task/${params.process_model_id}/${params.process_instance_id}`,

View File

@ -90,6 +90,7 @@ export default function ProcessInstanceShow({ variant }: OwnProps) {
[`${targetUris.processInstanceResumePath}`]: ['POST'],
[`${targetUris.processInstanceSuspendPath}`]: ['POST'],
[`${targetUris.processInstanceTerminatePath}`]: ['POST'],
[targetUris.processInstanceResetPath]: ['POST'],
[targetUris.messageInstanceListPath]: ['GET'],
[targetUris.processInstanceActionPath]: ['DELETE'],
[targetUris.processInstanceLogListPath]: ['GET'],
@ -261,6 +262,14 @@ export default function ProcessInstanceShow({ variant }: OwnProps) {
return spiffStepLink(<CaretRight />, 1);
};
const resetProcessInstance = () => {
HttpService.makeCallToBackend({
path: `${targetUris.processInstanceResetPath}/${currentSpiffStep()}`,
successCallback: refreshPage,
httpMethod: 'POST',
});
};
const getInfoTag = () => {
if (!processInstance) {
return null;
@ -535,6 +544,15 @@ export default function ProcessInstanceShow({ variant }: OwnProps) {
);
};
const canResetProcess = (task: any) => {
return (
processInstance &&
processInstance.status === 'suspended' &&
task.state === 'READY' &&
!showingLastSpiffStep()
);
};
const getEvents = (task: any) => {
const handleMessage = (eventDefinition: any) => {
if (eventDefinition.typename === 'MessageEventDefinition') {
@ -619,7 +637,7 @@ export default function ProcessInstanceShow({ variant }: OwnProps) {
});
};
const taskDataButtons = (task: any) => {
const taskDisplayButtons = (task: any) => {
const buttons = [];
if (
@ -707,6 +725,16 @@ export default function ProcessInstanceShow({ variant }: OwnProps) {
</Button>
);
}
if (canResetProcess(task)) {
buttons.push(
<Button
data-qa="reset-process-button"
onClick={() => resetProcessInstance()}
>
Resume Process Here
</Button>
);
}
}
return buttons;
@ -771,7 +799,7 @@ export default function ProcessInstanceShow({ variant }: OwnProps) {
>
<Stack orientation="horizontal" gap={2}>
{taskToUse.name} ({taskToUse.type}): {taskToUse.state}
{taskDataButtons(taskToUse)}
{taskDisplayButtons(taskToUse)}
</Stack>
{selectingEvent
? eventSelector(candidateEvents)