fixed a couple apis for the react frontend w/ burnettk

This commit is contained in:
jasquat 2022-06-06 17:16:25 -04:00
parent 4d05f35ed6
commit 60c60e7ea3
4 changed files with 49 additions and 42 deletions

View File

@ -38,20 +38,7 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/WorkflowSpecCategory"
/process-models/{process_model_id}:
get:
operationId: spiffworkflow_backend.routes.process_api_blueprint.process_model_show
summary: Returns a single process model
tags:
- Workflow Specification
responses:
'200':
description: Workflow spec.
content:
application/json:
schema:
$ref: "#/components/schemas/WorkflowSpec"
/workflow-specification:
/process-models:
# get:
# operationId: crc.api.workflow.all_specifications
# summary: Provides a list of workflows specifications that can be added to a study manually. Please note that Protocol Builder will handle this most of the time.
@ -96,9 +83,9 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/WorkflowSpec"
/workflow-specification/{spec_id}/file:
/process-models/{process_model_id}/file:
parameters:
- name: spec_id
- name: process_model_id
in: path
required: true
description: The unique id of an existing workflow specification to validate.
@ -139,26 +126,26 @@ paths:
application/json:
schema:
$ref: "#components/schemas/File"
/workflow-specification/{spec_id}:
/process-models/{process_model_id}:
parameters:
- name: spec_id
- name: process_model_id
in: path
required: true
description: The unique id of an existing workflow specification.
schema:
type: string
# get:
# operationId: crc.api.workflow.get_workflow_specification
# summary: Returns a single workflow specification
# tags:
# - Workflow Specifications
# responses:
# '200':
# description: Workflow specification.
# content:
# application/json:
# schema:
# $ref: "#/components/schemas/WorkflowSpec"
get:
operationId: spiffworkflow_backend.routes.process_api_blueprint.process_model_show
summary: Returns a single process model
tags:
- Workflow Specification
responses:
'200':
description: Workflow spec.
content:
application/json:
schema:
$ref: "#/components/schemas/WorkflowSpec"
post:
operationId: spiffworkflow_backend.routes.process_api_blueprint.create_process_instance
summary: Creates a workflow from a workflow spec and returns the workflow
@ -200,9 +187,9 @@ paths:
# responses:
# '204':
# description: The workflow specification has been removed.
/process-models/{spec_id}/file/{file_name}:
/process-models/{process_model_id}/file/{file_name}:
parameters:
- name: spec_id
- name: process_model_id
in: path
required: true
description: The unique id of an existing workflow specification to validate.
@ -460,7 +447,7 @@ components:
type: string
x-nullable: true
example: MyTask
spec_id:
process_model_id:
type: string
x-nullable: true
example: My Spec Name

View File

@ -101,6 +101,8 @@ class File:
data_store: Optional[dict] = field(default_factory=dict)
user_uid: Optional[str] = None
file_contents: Optional[str] = None
process_model_id: Optional[str] = None
process_group_id: Optional[str] = None
archived: bool = False
@classmethod
@ -134,6 +136,8 @@ class FileSchema(Schema):
"user_uid",
"url",
"file_contents",
"process_model_id",
"process_group_id",
]
unknown = INCLUDE

View File

@ -43,43 +43,45 @@ def add_process_model(body):
)
def get_file(spec_id, file_name):
def get_file(process_model_id, file_name):
"""Get_file."""
process_model = ProcessModelService().get_spec(spec_id)
process_model = ProcessModelService().get_spec(process_model_id)
files = SpecFileService.get_files(process_model, file_name)
if len(files) == 0:
raise ApiError(
code="unknown file",
message=f"No information exists for file {file_name}"
f" it does not exist in workflow {spec_id}.",
f" it does not exist in workflow {process_model_id}.",
status_code=404,
)
file = files[0]
file_contents = SpecFileService.get_data(process_model, file.name)
file.file_contents = file_contents
file.process_model_id = process_model.id
file.process_group_id = process_model.process_group_id
return FileSchema().dump(file)
def add_file(spec_id):
def add_file(process_model_id):
"""Add_file."""
workflow_spec_service = ProcessModelService()
process_model = workflow_spec_service.get_spec(spec_id)
process_model_service = ProcessModelService()
process_model = process_model_service.get_spec(process_model_id)
request_file = connexion.request.files["file"]
file = SpecFileService.add_file(
process_model, request_file.filename, request_file.stream.read()
)
if not process_model.primary_process_id and file.type == FileType.bpmn.value:
SpecFileService.set_primary_bpmn(process_model, file.name)
workflow_spec_service.update_spec(process_model)
process_model_service.update_spec(process_model)
return Response(
json.dumps(FileSchema().dump(file)), status=201, mimetype="application/json"
)
def create_process_instance(spec_id):
def create_process_instance(process_model_id):
"""Create_process_instance."""
process_instance = ProcessInstanceService.create_process_instance(spec_id, g.user)
process_instance = ProcessInstanceService.create_process_instance(process_model_id, g.user)
processor = ProcessInstanceProcessor(process_instance)
processor.do_engine_steps()

View File

@ -48,6 +48,20 @@ def test_add_new_process_model(app, client: FlaskClient, with_bpmn_file_cleanup)
#
def test_get_file(app, client: FlaskClient, with_bpmn_file_cleanup):
user = find_or_create_user()
test_process_group_id = "group_id1"
process_model_dir_name = "hello_world"
load_test_spec(app, process_model_dir_name, process_group_id=test_process_group_id)
response = client.get(
f"/v1.0/process-models/{process_model_dir_name}/file/hello_world.bpmn", headers=logged_in_headers(user)
)
assert response.status_code == 200
assert response.json["name"] == "hello_world.bpmn"
assert response.json["process_group_id"] == "group_id1"
assert response.json["process_model_id"] == "hello_world"
def test_get_workflow_from_workflow_spec(
app, client: FlaskClient, with_bpmn_file_cleanup
):