Skip to content

Commit

Permalink
Workflow listing with count and search endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
ratheesh-aot committed Jul 23, 2024
1 parent c0cc9d8 commit 4d43f6a
Show file tree
Hide file tree
Showing 3 changed files with 182 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def create_app() -> flask.app.Flask:
]
CORS(app, origins=origins_re, max_age=3600, supports_credentials=True)

connexion_app.add_api("api.yml", base_path=V1_API_PATH_PREFIX, pythonic_params=True)
connexion_app.add_api("api.yml", base_path=V1_API_PATH_PREFIX, pythonic_params=False)

app.json = MyJSONEncoder(app)

Expand Down
113 changes: 113 additions & 0 deletions spiffworkflow-backend/src/spiffworkflow_backend/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3276,6 +3276,113 @@ paths:
schema:
$ref: "#/components/schemas/ProcessModel"

/process-definition:
parameters:
- name: latestVersion
in: query
required: false
description: Return only the latest version of each process definition
schema:
type: boolean
- name: includeProcessDefinitionsWithoutTenantId
in: query
required: false
description: Include process definitions that do not have a tenant ID
schema:
type: boolean
- name: sortBy
in: query
required: false
description: Sort the results by the given field
schema:
type: string
- name: sortOrder
in: query
required: false
description: Sort the results in the specified order (asc or desc)
schema:
type: string
- name: maxResults
in: query
required: false
description: Maximum number of results to return
schema:
type: integer
- name: nameLike
in: query
required: false
description: Filter with name
schema:
type: string
get:
operationId: spiffworkflow_backend.routes.process_models_controller.process_definition_list
summary: Return a list of process definitions
tags:
- Process Definitions
responses:
"200":
description: Successfully return the requested process definitions
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/ProcessModel"

/process-definition/count:
parameters:
- name: latestVersion
in: query
required: false
description: Return only the latest version of each process definition
schema:
type: boolean
- name: includeProcessDefinitionsWithoutTenantId
in: query
required: false
description: Include process definitions that do not have a tenant ID
schema:
type: boolean
- name: sortBy
in: query
required: false
description: Sort the results by the given field
schema:
type: string
- name: sortOrder
in: query
required: false
description: Sort the results in the specified order (asc or desc)
schema:
type: string
- name: maxResults
in: query
required: false
description: Maximum number of results to return
schema:
type: integer
- name: nameLike
in: query
required: false
description: Filter with name
schema:
type: string
get:
operationId: spiffworkflow_backend.routes.process_models_controller.process_definition_list_count
summary: Return the count of process models
tags:
- Process Definitions
responses:
"200":
description: Successfully return the requested process definitions count
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/ProcessModelCount"


/key/{process_model_identifier}/start:
parameters:
- name: process_model_identifier
Expand Down Expand Up @@ -3980,3 +4087,9 @@ components:
api_key:
type: string
nullable: false
ProcessModelCount:
properties:
count:
type: number
example: 1
nullable: false
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import connexion # type: ignore
import flask.wrappers
import fnmatch
from flask import current_app
from flask import g
from flask import jsonify
Expand Down Expand Up @@ -68,7 +69,7 @@ def process_model_create_formsflow(upload: FileStorage) -> flask.wrappers.Respon
raise ProcessModelFileInvalidError(f"Received error trying to parse bpmn xml: {str(exception)}") from exception
if not (process_model_info:= ProcessModelService.find_by_process_id(_key)):
process_model_info = ProcessModelInfo() # type: ignore
#TODO Check on version management
# TODO Check on version management

process_model_info.display_name = _name
process_model_info.content = _content
Expand All @@ -91,6 +92,72 @@ def process_model_create_formsflow(upload: FileStorage) -> flask.wrappers.Respon
)


def process_definition_list(
latestVersion: bool | None = False,
includeProcessDefinitionsWithoutTenantId: bool | None = False,
sortBy: str | None = None,
sortOrder: str | None = None,
firstResult: int | None = 0,
maxResults: int = 100,
nameLike: str | None = None,
return_count_only: bool | None = False,
) -> flask.wrappers.Response:

page = (firstResult // maxResults) + 1
per_page = maxResults

process_models = ProcessModelService.get_process_models_for_api(user=g.user)
process_models_to_return = ProcessModelService.get_batch(process_models, page=page, per_page=per_page)

# Convert to desired format
converted_process_models = [
{
"id": model.id,
"key": model.id, # Assuming 'key' is same as 'id'
"tenantId": None, # TODO: Need to update
"name": model.display_name,
"description": model.description,
"version": 1, # Assuming version 1
"resource": model.files[0].name if model.files else None,
"deploymentId": "some_deployment_id", # TODO: Placeholder, update with actual
"suspended": False, # TODO: Do something based on model.fault_or_suspend_on_exception
}
for model in process_models_to_return
]

# Filter by nameLike if provided TODO : Change to filter using db query itself.
if nameLike:
pattern = nameLike.replace('%', '*').lower()
converted_process_models = [
model for model in converted_process_models if fnmatch.fnmatch(model["name"].lower(), pattern)
]
if return_count_only:
return make_response(jsonify({"count": len(converted_process_models)}), 200)

return make_response(jsonify(converted_process_models), 200)


def process_definition_list_count(
latestVersion: bool | None = False,
includeProcessDefinitionsWithoutTenantId: bool | None = False,
sortBy: str | None = None,
sortOrder: str | None = None,
firstResult: int | None = 0,
maxResults: int = 100,
nameLike: str | None = None,
) -> flask.wrappers.Response:
return process_definition_list(
latestVersion,
includeProcessDefinitionsWithoutTenantId,
sortBy,
sortOrder,
firstResult,
maxResults,
nameLike,
True,
)


def process_model_create(
modified_process_group_id: str, body: dict[str, str | bool | int | None | list]
) -> flask.wrappers.Response:
Expand Down

0 comments on commit 4d43f6a

Please sign in to comment.