Adding a very simple api endpoint that just returns a list of every process known to the system.
This commit is contained in:
parent
88a40c73ea
commit
22d1186236
|
@ -1,8 +1,8 @@
|
|||
"""empty message
|
||||
|
||||
Revision ID: 3e2a826ac720
|
||||
Revision ID: 7d1662ea1227
|
||||
Revises:
|
||||
Create Date: 2022-11-14 14:59:43.265173
|
||||
Create Date: 2022-11-14 21:48:34.469311
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
|
@ -10,7 +10,7 @@ import sqlalchemy as sa
|
|||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '3e2a826ac720'
|
||||
revision = '7d1662ea1227'
|
||||
down_revision = None
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
@ -42,6 +42,7 @@ def upgrade():
|
|||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('identifier', sa.String(length=255), nullable=True),
|
||||
sa.Column('display_name', sa.String(length=255), nullable=True),
|
||||
sa.Column('process_model_id', sa.String(length=255), nullable=True),
|
||||
sa.Column('type', sa.String(length=255), nullable=True),
|
||||
sa.Column('file_name', sa.String(length=255), nullable=True),
|
||||
sa.Column('relative_path', sa.String(length=255), nullable=True),
|
|
@ -371,6 +371,23 @@ paths:
|
|||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/OkTrue"
|
||||
# process_model_list
|
||||
/processes:
|
||||
get:
|
||||
operationId: spiffworkflow_backend.routes.process_api_blueprint.process_list
|
||||
summary: Return a list of all processes (not just primary process of a process model)
|
||||
useful for finding processes for call activites.
|
||||
tags:
|
||||
- Process Models
|
||||
responses:
|
||||
"200":
|
||||
description: Successfully return the requested processes
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/Process"
|
||||
|
||||
/process-instances:
|
||||
parameters:
|
||||
|
@ -1530,7 +1547,26 @@ components:
|
|||
type: string
|
||||
x-nullable: true
|
||||
example: Some Value
|
||||
|
||||
Process:
|
||||
properties:
|
||||
identifier:
|
||||
type: string
|
||||
display_name:
|
||||
type: string
|
||||
process_group_id:
|
||||
type: string
|
||||
process_model_id:
|
||||
type: string
|
||||
type:
|
||||
type: string
|
||||
file_name:
|
||||
type: string
|
||||
has_lanes:
|
||||
type: boolean
|
||||
is_executable:
|
||||
type: boolean
|
||||
is_primary:
|
||||
type: boolean
|
||||
ProcessModel:
|
||||
properties:
|
||||
id:
|
||||
|
|
|
@ -19,6 +19,7 @@ class SpecReference:
|
|||
|
||||
identifier: str # The id of the process or decision. "Process_1234"
|
||||
display_name: str # The name of the process or decision. "Invoice Submission"
|
||||
process_model_id: str
|
||||
type: str # can be 'process' or 'decision'
|
||||
file_name: str # The name of the file where this process or decision is defined.
|
||||
relative_path: str # The path to the file.
|
||||
|
@ -38,6 +39,7 @@ class SpecReferenceCache(SpiffworkflowBaseDBModel):
|
|||
id = db.Column(db.Integer, primary_key=True)
|
||||
identifier = db.Column(db.String(255), unique=True, index=True)
|
||||
display_name = db.Column(db.String(255), index=True)
|
||||
process_model_id = db.Column(db.String(255))
|
||||
type = db.Column(db.String(255), index=True) # either 'process' or 'decision'
|
||||
file_name = db.Column(db.String(255))
|
||||
relative_path = db.Column(db.String(255))
|
||||
|
@ -52,5 +54,8 @@ class SpecReferenceSchema(Schema):
|
|||
"""Meta."""
|
||||
|
||||
model = SpecReference
|
||||
fields = ["identifier", "display_name", "type"]
|
||||
fields = ["identifier", "display_name",
|
||||
"process_group_id", "process_model_id",
|
||||
"type", "file_name", "has_lanes",
|
||||
"is_executable", "is_primary"]
|
||||
unknown = INCLUDE
|
|
@ -59,6 +59,7 @@ from spiffworkflow_backend.models.process_model import ProcessModelInfo
|
|||
from spiffworkflow_backend.models.process_model import ProcessModelInfoSchema
|
||||
from spiffworkflow_backend.models.secret_model import SecretModel
|
||||
from spiffworkflow_backend.models.secret_model import SecretModelSchema
|
||||
from spiffworkflow_backend.models.spec_reference import SpecReferenceCache, SpecReferenceSchema
|
||||
from spiffworkflow_backend.models.spiff_logging import SpiffLoggingModel
|
||||
from spiffworkflow_backend.models.spiff_step_details import SpiffStepDetailsModel
|
||||
from spiffworkflow_backend.models.user import UserModel
|
||||
|
@ -336,10 +337,16 @@ def process_model_list(
|
|||
"pages": pages,
|
||||
},
|
||||
}
|
||||
|
||||
return Response(json.dumps(response_json), status=200, mimetype="application/json")
|
||||
|
||||
|
||||
def process_list() -> any:
|
||||
"""Returns a list of all known processes - this includes processes that are not the
|
||||
primary process - helpful for finding possible call activities. """
|
||||
references = SpecReferenceCache.query.filter_by(type = "process")
|
||||
return SpecReferenceSchema(many=True).dump(references)
|
||||
|
||||
|
||||
def get_file(modified_process_model_id: str, file_name: str) -> Any:
|
||||
"""Get_file."""
|
||||
process_model_identifier = modified_process_model_id.replace(":", "/")
|
||||
|
|
|
@ -124,7 +124,9 @@ class SpecFileService(FileSystemService):
|
|||
start_messages = sub_parser.start_messages()
|
||||
is_primary = sub_parser.get_id() == process_model_info.primary_process_id
|
||||
references.append(SpecReference(
|
||||
identifier=sub_parser.get_id(), display_name=sub_parser.get_name(), type=parser_type,
|
||||
identifier=sub_parser.get_id(), display_name=sub_parser.get_name(),
|
||||
process_model_id=process_model_info.id,
|
||||
type=parser_type,
|
||||
file_name=file.name, relative_path=file_path, has_lanes=has_lanes,
|
||||
is_executable=is_executable, messages=messages, is_primary=is_primary,
|
||||
correlations=correlations, start_messages=start_messages
|
||||
|
@ -235,9 +237,13 @@ class SpecFileService(FileSystemService):
|
|||
process_id_lookup = SpecReferenceCache(
|
||||
identifier=ref.identifier,
|
||||
display_name=ref.display_name,
|
||||
relative_path=ref.relative_path,
|
||||
process_model_id=ref.process_model_id,
|
||||
type=ref.type,
|
||||
is_executable=ref.is_executable
|
||||
file_name=ref.file_name,
|
||||
has_lanes=ref.has_lanes,
|
||||
is_executable=ref.is_executable,
|
||||
is_primary=ref.is_primary,
|
||||
relative_path=ref.relative_path,
|
||||
)
|
||||
db.session.add(process_id_lookup)
|
||||
else:
|
||||
|
|
|
@ -467,6 +467,18 @@ class TestProcessApi(BaseTest):
|
|||
# When adding a process model with 4 processes and a decision, 5 new records will be in the Cache
|
||||
assert(len(SpecReferenceCache.query.all()) == 6)
|
||||
|
||||
# get the results
|
||||
response = client.get("/v1.0/processes", headers=self.logged_in_headers(with_super_admin_user),
|
||||
)
|
||||
assert response.json is not None
|
||||
# We should get 5 back, as one of the items in the cache is a decision.
|
||||
assert len(response.json) == 5
|
||||
simple_form = next(p for p in response.json if p['identifier'] == 'Proccess_WithForm')
|
||||
assert(simple_form['display_name'] == 'Process With Form')
|
||||
assert(simple_form['process_model_id'] == 'test_group_one/simple_form')
|
||||
assert(simple_form['has_lanes'] == False)
|
||||
assert(simple_form['is_executable'] == True)
|
||||
assert(simple_form['is_primary'] == True)
|
||||
|
||||
|
||||
def test_process_group_add(
|
||||
|
|
Loading…
Reference in New Issue