added basis of api to create process models from text w/ burnettk

This commit is contained in:
jasquat 2022-12-30 16:30:52 -05:00
parent 7c88f2f756
commit cfaf2d9c6d
3 changed files with 115 additions and 4 deletions

View File

@ -327,6 +327,32 @@ paths:
schema:
$ref: "#/components/schemas/ProcessModel"
/process-models-natural-language/{modified_process_group_id}:
parameters:
- name: modified_process_group_id
in: path
required: true
description: modified id of an existing process group
schema:
type: string
post:
operationId: spiffworkflow_backend.routes.process_models_controller.process_model_create_with_natural_language
summary: Creates a new process model with the given parameters.
tags:
- Process Models
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/ProcessModel"
responses:
"201":
description: Process model created successfully.
content:
application/json:
schema:
$ref: "#/components/schemas/ProcessModel"
/process-models/{modified_process_model_identifier}/files:
parameters:
- name: modified_process_model_identifier

View File

@ -1,5 +1,6 @@
"""APIs for dealing with process groups, process models, and process instances."""
import json
import re
from typing import Any
from typing import Dict
from typing import Optional
@ -299,10 +300,66 @@ def process_model_file_show(
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)
# {
# "natural_language_text": "Create a bug tracker process model with a bug-details form that collects summary, description, and priority"
# }
def process_model_create_with_natural_language(
modified_process_group_id: str, body: Dict[str, Union[str, bool, int]]
) -> flask.wrappers.Response:
# body_include_list = [
# "id",
# "display_name",
# "primary_file_name",
# "primary_process_id",
# "description",
# "metadata_extraction_paths",
# ]
# body_filtered = {
# include_item: body[include_item]
# for include_item in body_include_list
# if include_item in body
# }
pattern = re.compile(r"Create a (?P<pm_name>.*?) process model with a (?P<form_name>.*?) form that collects (?P<columns_hey>.*)")
match = pattern.match(body["natural_language_text"])
process_model_display_name = match.group('pm_name')
process_model_identifier = re.sub(r"[ _]", '-', process_model_display_name)
process_model_identifier = re.sub(r"-{2,}", '-', process_model_identifier).lower()
print(f"process_model_identifier: {process_model_identifier}")
form_name = match.group('form_name')
form_identifier = re.sub(r"[ _]", '-', form_name)
form_identifier = re.sub(r"-{2,}", '-', form_identifier).lower()
print(f"form_identifier: {form_identifier}")
column_names = match.group('columns_hey')
print(f"column_names: {column_names}")
columns = re.sub(r"(, (and )?)", ',', column_names).split(',')
print(f"columns: {columns}")
#
# if modified_process_group_id is None:
# raise ApiError(
# error_code="process_group_id_not_specified",
# message="Process Model could not be created when process_group_id path param is unspecified",
# status_code=400,
# )
#
# unmodified_process_group_id = _un_modify_modified_process_model_id(
# modified_process_group_id
# )
# process_group = ProcessModelService.get_process_group(unmodified_process_group_id)
# if process_group is None:
# raise ApiError(
# error_code="process_model_could_not_be_created",
# message=f"Process Model could not be created from given body because Process Group could not be found: {body}",
# status_code=400,
# )
def _get_file_from_request() -> Any:
"""Get_file_from_request."""
request_file = connexion.request.files.get("file")

View File

@ -163,6 +163,37 @@ class TestProcessApi(BaseTest):
assert process_model.primary_file_name == bpmn_file_name
assert process_model.primary_process_id == "sample"
def test_process_model_create_with_natural_language(
self,
app: Flask,
client: FlaskClient,
with_db_and_bpmn_file_cleanup: None,
with_super_admin_user: UserModel,
) -> None:
process_group_id = "test_process_group"
process_group_description = "Test Process Group"
process_model_id = "sample"
process_model_identifier = f"{process_group_id}/{process_model_id}"
self.create_process_group(
client, with_super_admin_user, process_group_id, process_group_description
)
body = {
"natural_language_text": "Create a Bug Tracker process model with a Bug Details form that collects summary, description, and priority"
}
self.create_process_model_with_api(
client,
process_model_id=process_model_identifier,
user=with_super_admin_user,
)
response = client.post(
f"/v1.0/process-models-natural-language/{process_group_id}",
content_type="application/json",
data=json.dumps(body),
headers=self.logged_in_headers(with_super_admin_user),
)
assert response.status_code == 201
def test_primary_process_id_updates_via_xml(
self,
app: Flask,
@ -250,9 +281,6 @@ class TestProcessApi(BaseTest):
assert response.json is not None
assert response.json["ok"] is True
# assert we no longer have a model
with pytest.raises(ProcessEntityNotFoundError):
ProcessModelService.get_process_model(process_model_identifier)
def test_process_model_delete_with_instances(
self,