add process_instance_report_list
This commit is contained in:
parent
15866e2297
commit
5047b9aa8b
3
.flake8
3
.flake8
|
@ -22,3 +22,6 @@ per-file-ignores =
|
|||
|
||||
# this file overwrites methods from the logging library so we can't change them
|
||||
src/spiffworkflow_backend/services/logging_service.py:N802
|
||||
|
||||
# ignore long comment line
|
||||
src/spiffworkflow_backend/services/logging_service.py:B950
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,3 +1,5 @@
|
|||
from __future__ import with_statement
|
||||
|
||||
import logging
|
||||
from logging.config import fileConfig
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
"""empty message
|
||||
|
||||
Revision ID: e7557de20067
|
||||
Revision ID: c96f24ebe8d2
|
||||
Revises:
|
||||
Create Date: 2022-06-30 16:28:51.558359
|
||||
Create Date: 2022-07-09 13:14:09.924901
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
|
@ -10,7 +10,7 @@ import sqlalchemy as sa
|
|||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'e7557de20067'
|
||||
revision = 'c96f24ebe8d2'
|
||||
down_revision = None
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
@ -70,15 +70,17 @@ def upgrade():
|
|||
op.create_index(op.f('ix_process_instance_process_model_identifier'), 'process_instance', ['process_model_identifier'], unique=False)
|
||||
op.create_table('process_instance_report',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('identifier', sa.String(length=50), nullable=False),
|
||||
sa.Column('process_model_identifier', sa.String(length=50), nullable=False),
|
||||
sa.Column('process_group_identifier', sa.String(length=50), nullable=False),
|
||||
sa.Column('report_json', sa.JSON(), nullable=True),
|
||||
sa.Column('report_metadata', sa.JSON(), nullable=True),
|
||||
sa.Column('created_by_id', sa.Integer(), nullable=False),
|
||||
sa.Column('created_at_in_seconds', sa.Integer(), nullable=True),
|
||||
sa.Column('updated_at_in_seconds', sa.Integer(), nullable=True),
|
||||
sa.ForeignKeyConstraint(['created_by_id'], ['user.id'], ),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_index(op.f('ix_process_instance_report_identifier'), 'process_instance_report', ['identifier'], unique=False)
|
||||
op.create_index(op.f('ix_process_instance_report_process_group_identifier'), 'process_instance_report', ['process_group_identifier'], unique=False)
|
||||
op.create_index(op.f('ix_process_instance_report_process_model_identifier'), 'process_instance_report', ['process_model_identifier'], unique=False)
|
||||
op.create_table('user_group_assignment',
|
||||
|
@ -171,6 +173,7 @@ def downgrade():
|
|||
op.drop_table('user_group_assignment')
|
||||
op.drop_index(op.f('ix_process_instance_report_process_model_identifier'), table_name='process_instance_report')
|
||||
op.drop_index(op.f('ix_process_instance_report_process_group_identifier'), table_name='process_instance_report')
|
||||
op.drop_index(op.f('ix_process_instance_report_identifier'), table_name='process_instance_report')
|
||||
op.drop_table('process_instance_report')
|
||||
op.drop_index(op.f('ix_process_instance_process_model_identifier'), table_name='process_instance')
|
||||
op.drop_index(op.f('ix_process_instance_process_group_identifier'), table_name='process_instance')
|
|
@ -455,6 +455,47 @@ paths:
|
|||
schema:
|
||||
$ref: "#/components/schemas/Workflow"
|
||||
|
||||
/process-models/{process_group_id}/{process_model_id}/process-instances/reports:
|
||||
parameters:
|
||||
- name: process_group_id
|
||||
in: path
|
||||
required: true
|
||||
description: The unique id of an existing process group
|
||||
schema:
|
||||
type: string
|
||||
- name: process_model_id
|
||||
in: path
|
||||
required: true
|
||||
description: The unique id of an existing workflow specification.
|
||||
schema:
|
||||
type: string
|
||||
- name: page
|
||||
in: query
|
||||
required: false
|
||||
description: The page number to return. Defaults to page 1.
|
||||
schema:
|
||||
type: integer
|
||||
- name: per_page
|
||||
in: query
|
||||
required: false
|
||||
description: The page number to return. Defaults to page 1.
|
||||
schema:
|
||||
type: integer
|
||||
get:
|
||||
operationId: spiffworkflow_backend.routes.process_api_blueprint.process_instance_report_list
|
||||
summary: Returns all process instance reports for process model
|
||||
tags:
|
||||
- Process Instances
|
||||
responses:
|
||||
"200":
|
||||
description: Workflow.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/Workflow"
|
||||
|
||||
/process-models/{process_group_id}/{process_model_id}/process-instances/report:
|
||||
parameters:
|
||||
- name: process_group_id
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
"""Process_instance."""
|
||||
from typing import Union
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
|
||||
from flask_bpmn.models.db import db
|
||||
from flask_bpmn.models.db import SpiffworkflowBaseDBModel
|
||||
|
@ -7,31 +9,86 @@ from sqlalchemy import ForeignKey
|
|||
from sqlalchemy.orm import deferred
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from spiffworkflow_backend.exceptions.process_entity_not_found_error import (
|
||||
ProcessEntityNotFoundError,
|
||||
)
|
||||
from spiffworkflow_backend.models.user import UserModel
|
||||
from spiffworkflow_backend.services.process_model_service import ProcessModelService
|
||||
|
||||
|
||||
@dataclass
|
||||
class ProcessInstanceReportModel(SpiffworkflowBaseDBModel):
|
||||
"""ProcessInstanceReportModel."""
|
||||
|
||||
__tablename__ = "process_instance_report"
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
process_model_identifier = db.Column(db.String(50), nullable=False, index=True)
|
||||
identifier: str = db.Column(db.String(50), nullable=False, index=True)
|
||||
process_model_identifier: str = db.Column(db.String(50), nullable=False, index=True)
|
||||
process_group_identifier = db.Column(db.String(50), nullable=False, index=True)
|
||||
report_json = deferred(db.Column(db.JSON)) # type: ignore
|
||||
report_metadata: dict = deferred(db.Column(db.JSON)) # type: ignore
|
||||
created_by_id = db.Column(ForeignKey(UserModel.id), nullable=False)
|
||||
created_by = relationship("UserModel")
|
||||
created_at_in_seconds = db.Column(db.Integer)
|
||||
updated_at_in_seconds = db.Column(db.Integer)
|
||||
|
||||
@property
|
||||
def serialized(self) -> dict[str, Union[str, int]]:
|
||||
"""Return object data in serializeable format."""
|
||||
return {
|
||||
"id": self.id,
|
||||
"process_model_identifier": self.process_model_identifier,
|
||||
"process_group_identifier": self.process_group_identifier,
|
||||
"report_json": self.report_json,
|
||||
"created_by": self.process_initiator_id,
|
||||
"created_at_in_seconds": self.created_at_in_seconds,
|
||||
"updated_at_in_seconds": self.updated_at_in_seconds,
|
||||
}
|
||||
# @property
|
||||
# def serialized(self) -> dict[str, Union[str, int]]:
|
||||
# """Return object data in serializeable format."""
|
||||
# return {
|
||||
# "id": self.id,
|
||||
# "process_model_identifier": self.process_model_identifier,
|
||||
# "process_group_identifier": self.process_group_identifier,
|
||||
# "report_metadata": self.report_metadata,
|
||||
# "created_by": self.process_initiator_id,
|
||||
# "created_at_in_seconds": self.created_at_in_seconds,
|
||||
# "updated_at_in_seconds": self.updated_at_in_seconds,
|
||||
# }
|
||||
|
||||
@classmethod
|
||||
def add_fixtures(cls) -> None:
|
||||
"""Add_fixtures."""
|
||||
try:
|
||||
process_model = ProcessModelService().get_process_model(
|
||||
group_id="sartography-admin", process_model_id="ticket"
|
||||
)
|
||||
json = {"order": "month asc"}
|
||||
user = UserModel.query.first()
|
||||
process_instance_report = cls(
|
||||
identifier="for-month",
|
||||
process_group_identifier=process_model.process_group_id,
|
||||
process_model_identifier=process_model.id,
|
||||
created_by_id=user.id,
|
||||
report_metadata=json,
|
||||
)
|
||||
db.session.add(process_instance_report)
|
||||
db.session.commit()
|
||||
|
||||
except ProcessEntityNotFoundError:
|
||||
print("NOPE")
|
||||
print("NOPE")
|
||||
print("NOPE")
|
||||
print("NOPE")
|
||||
|
||||
@classmethod
|
||||
def create_with_attributes(
|
||||
cls,
|
||||
identifier: str,
|
||||
process_group_identifier: str,
|
||||
process_model_identifier: str,
|
||||
report_metadata: dict,
|
||||
user: UserModel,
|
||||
) -> ProcessInstanceReportModel:
|
||||
"""Create_with_attributes."""
|
||||
process_model = ProcessModelService().get_process_model(
|
||||
group_id=process_group_identifier, process_model_id=process_model_identifier
|
||||
)
|
||||
process_instance_report = cls(
|
||||
identifier=identifier,
|
||||
process_group_identifier=process_model.process_group_id,
|
||||
process_model_identifier=process_model.id,
|
||||
created_by_id=user.id,
|
||||
report_metadata=report_metadata,
|
||||
)
|
||||
db.session.add(process_instance_report)
|
||||
db.session.commit()
|
||||
return process_instance_report
|
||||
|
|
|
@ -29,6 +29,9 @@ from spiffworkflow_backend.models.process_group import ProcessGroupSchema
|
|||
from spiffworkflow_backend.models.process_instance import ProcessInstanceApiSchema
|
||||
from spiffworkflow_backend.models.process_instance import ProcessInstanceModel
|
||||
from spiffworkflow_backend.models.process_instance import ProcessInstanceModelSchema
|
||||
from spiffworkflow_backend.models.process_instance_report import (
|
||||
ProcessInstanceReportModel,
|
||||
)
|
||||
from spiffworkflow_backend.models.process_model import ProcessModelInfo
|
||||
from spiffworkflow_backend.models.process_model import ProcessModelInfoSchema
|
||||
from spiffworkflow_backend.services.error_handling_service import ErrorHandlingService
|
||||
|
@ -395,6 +398,21 @@ def process_instance_delete(
|
|||
return Response(json.dumps({"ok": True}), status=200, mimetype="application/json")
|
||||
|
||||
|
||||
def process_instance_report_list(
|
||||
process_group_id: str, process_model_id: str, page: int = 1, per_page: int = 100
|
||||
) -> flask.wrappers.Response:
|
||||
"""Process_instance_report_list."""
|
||||
ProcessInstanceReportModel.add_fixtures()
|
||||
process_model = get_process_model(process_model_id, process_group_id)
|
||||
|
||||
process_instance_reports = ProcessInstanceReportModel.query.filter_by(
|
||||
process_group_identifier=process_group_id,
|
||||
process_model_identifier=process_model.id,
|
||||
).all()
|
||||
|
||||
return make_response(jsonify(process_instance_reports), 200)
|
||||
|
||||
|
||||
def process_instance_report_show(
|
||||
process_group_id: str, process_model_id: str, page: int = 1, per_page: int = 100
|
||||
) -> flask.wrappers.Response:
|
||||
|
|
|
@ -22,6 +22,9 @@ from spiffworkflow_backend.models.process_group import ProcessGroup
|
|||
from spiffworkflow_backend.models.process_group import ProcessGroupSchema
|
||||
from spiffworkflow_backend.models.process_instance import ProcessInstanceModel
|
||||
from spiffworkflow_backend.models.process_instance import ProcessInstanceStatus
|
||||
from spiffworkflow_backend.models.process_instance_report import (
|
||||
ProcessInstanceReportModel,
|
||||
)
|
||||
from spiffworkflow_backend.models.process_model import NotificationType
|
||||
from spiffworkflow_backend.models.process_model import ProcessModelInfo
|
||||
from spiffworkflow_backend.models.process_model import ProcessModelInfoSchema
|
||||
|
@ -843,6 +846,35 @@ def test_process_instance_list_filter(
|
|||
assert json.loads(results[i]["bpmn_json"])["i"] in (1, 2, 3)
|
||||
|
||||
|
||||
def test_process_instance_report_list(
|
||||
app: Flask, client: FlaskClient, with_db_and_bpmn_file_cleanup: None
|
||||
) -> None:
|
||||
"""Test_process_instance_report_list."""
|
||||
process_group_identifier = "runs_without_input"
|
||||
process_model_identifier = "sample"
|
||||
user = find_or_create_user()
|
||||
logged_in_headers(user)
|
||||
load_test_spec(process_model_identifier, process_group_id=process_group_identifier)
|
||||
report_identifier = "testreport"
|
||||
report_metadata = {"order": ["month asc"]}
|
||||
ProcessInstanceReportModel.create_with_attributes(
|
||||
identifier=report_identifier,
|
||||
process_group_identifier=process_group_identifier,
|
||||
process_model_identifier=process_model_identifier,
|
||||
report_metadata=report_metadata,
|
||||
user=user,
|
||||
)
|
||||
response = client.get(
|
||||
f"/v1.0/process-models/{process_group_identifier}/{process_model_identifier}/process-instances/reports",
|
||||
headers=logged_in_headers(user),
|
||||
)
|
||||
assert response.status_code == 200
|
||||
assert response.json is not None
|
||||
assert len(response.json) == 1
|
||||
assert response.json[0]["identifier"] == report_identifier
|
||||
assert response.json[0]["report_metadata"]["order"] == ["month asc"]
|
||||
|
||||
|
||||
def test_process_instance_report_show_with_default_list(
|
||||
app: Flask, client: FlaskClient, with_db_and_bpmn_file_cleanup: None
|
||||
) -> None:
|
||||
|
|
Loading…
Reference in New Issue