mirror of
https://github.com/sartography/spiffworkflow-backend.git
synced 2025-02-24 05:18:22 +00:00
added crud api calls for reports w/ burnettk
This commit is contained in:
parent
e8ca4f7ba9
commit
76adcce043
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import with_statement
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from logging.config import fileConfig
|
from logging.config import fileConfig
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
"""empty message
|
"""empty message
|
||||||
|
|
||||||
Revision ID: c96f24ebe8d2
|
Revision ID: 3f7aa48eaf3a
|
||||||
Revises:
|
Revises:
|
||||||
Create Date: 2022-07-09 13:14:09.924901
|
Create Date: 2022-07-11 16:08:00.002287
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from alembic import op
|
from alembic import op
|
||||||
@ -10,7 +10,7 @@ import sqlalchemy as sa
|
|||||||
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
# revision identifiers, used by Alembic.
|
||||||
revision = 'c96f24ebe8d2'
|
revision = '3f7aa48eaf3a'
|
||||||
down_revision = None
|
down_revision = None
|
||||||
branch_labels = None
|
branch_labels = None
|
||||||
depends_on = None
|
depends_on = None
|
||||||
@ -78,7 +78,8 @@ def upgrade():
|
|||||||
sa.Column('created_at_in_seconds', sa.Integer(), nullable=True),
|
sa.Column('created_at_in_seconds', sa.Integer(), nullable=True),
|
||||||
sa.Column('updated_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.ForeignKeyConstraint(['created_by_id'], ['user.id'], ),
|
||||||
sa.PrimaryKeyConstraint('id')
|
sa.PrimaryKeyConstraint('id'),
|
||||||
|
sa.UniqueConstraint('process_group_identifier', 'process_model_identifier', 'identifier', name='process_instance_report_unique')
|
||||||
)
|
)
|
||||||
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_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_group_identifier'), 'process_instance_report', ['process_group_identifier'], unique=False)
|
@ -495,6 +495,18 @@ paths:
|
|||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
$ref: "#/components/schemas/Workflow"
|
$ref: "#/components/schemas/Workflow"
|
||||||
|
post:
|
||||||
|
operationId: spiffworkflow_backend.routes.process_api_blueprint.process_instance_report_create
|
||||||
|
summary: Returns all process instance reports for process model
|
||||||
|
tags:
|
||||||
|
- Process Instances
|
||||||
|
responses:
|
||||||
|
"201":
|
||||||
|
description: The process instance report was created.
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#components/schemas/OkTrue"
|
||||||
|
|
||||||
/process-models/{process_group_id}/{process_model_id}/process-instances/reports/{report_identifier}:
|
/process-models/{process_group_id}/{process_model_id}/process-instances/reports/{report_identifier}:
|
||||||
parameters:
|
parameters:
|
||||||
@ -542,6 +554,30 @@ paths:
|
|||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
$ref: "#/components/schemas/Workflow"
|
$ref: "#/components/schemas/Workflow"
|
||||||
|
put:
|
||||||
|
operationId: spiffworkflow_backend.routes.process_api_blueprint.process_instance_report_update
|
||||||
|
summary: Updates a process instance report
|
||||||
|
tags:
|
||||||
|
- Process Instances
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: The process instance report was updated.
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#components/schemas/OkTrue"
|
||||||
|
delete:
|
||||||
|
operationId: spiffworkflow_backend.routes.process_api_blueprint.process_instance_report_delete
|
||||||
|
summary: Delete a process instance report
|
||||||
|
tags:
|
||||||
|
- Process Instances
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: The process instance report was delete.
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#components/schemas/OkTrue"
|
||||||
|
|
||||||
/process-models/{process_group_id}/{process_model_id}/file/{file_name}:
|
/process-models/{process_group_id}/{process_model_id}/file/{file_name}:
|
||||||
parameters:
|
parameters:
|
||||||
|
@ -56,6 +56,12 @@ class ProcessInstanceReportModel(SpiffworkflowBaseDBModel):
|
|||||||
"""ProcessInstanceReportModel."""
|
"""ProcessInstanceReportModel."""
|
||||||
|
|
||||||
__tablename__ = "process_instance_report"
|
__tablename__ = "process_instance_report"
|
||||||
|
__table_args__ = (
|
||||||
|
db.UniqueConstraint(
|
||||||
|
"process_group_identifier", "process_model_identifier", "identifier", name="process_instance_report_unique"
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
identifier: str = 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_model_identifier: str = db.Column(db.String(50), nullable=False, index=True)
|
||||||
@ -70,16 +76,6 @@ class ProcessInstanceReportModel(SpiffworkflowBaseDBModel):
|
|||||||
def add_fixtures(cls) -> None:
|
def add_fixtures(cls) -> None:
|
||||||
"""Add_fixtures."""
|
"""Add_fixtures."""
|
||||||
try:
|
try:
|
||||||
db.session.query(ProcessInstanceReportModel).filter_by(
|
|
||||||
process_group_identifier="sartography-admin",
|
|
||||||
process_model_identifier="ticket",
|
|
||||||
).delete()
|
|
||||||
db.session.commit()
|
|
||||||
db.session.query(ProcessInstanceReportModel).filter_by(
|
|
||||||
process_group_identifier="category_number_one",
|
|
||||||
process_model_identifier="process-model-with-form",
|
|
||||||
).delete()
|
|
||||||
db.session.commit()
|
|
||||||
process_model = ProcessModelService().get_process_model(
|
process_model = ProcessModelService().get_process_model(
|
||||||
group_id="sartography-admin", process_model_id="ticket"
|
group_id="sartography-admin", process_model_id="ticket"
|
||||||
)
|
)
|
||||||
@ -95,28 +91,28 @@ class ProcessInstanceReportModel(SpiffworkflowBaseDBModel):
|
|||||||
]
|
]
|
||||||
json = {"order": "month asc", "columns": columns}
|
json = {"order": "month asc", "columns": columns}
|
||||||
|
|
||||||
cls.make_fixture_report(
|
cls.create_report(
|
||||||
identifier="standard",
|
identifier="standard",
|
||||||
process_group_identifier=process_model.process_group_id,
|
process_group_identifier=process_model.process_group_id,
|
||||||
process_model_identifier=process_model.id,
|
process_model_identifier=process_model.id,
|
||||||
user=user,
|
user=user,
|
||||||
report_metadata=json,
|
report_metadata=json,
|
||||||
)
|
)
|
||||||
cls.make_fixture_report(
|
cls.create_report(
|
||||||
identifier="for-month",
|
identifier="for-month",
|
||||||
process_group_identifier="sartography-admin",
|
process_group_identifier="sartography-admin",
|
||||||
process_model_identifier="ticket",
|
process_model_identifier="ticket",
|
||||||
user=user,
|
user=user,
|
||||||
report_metadata=cls.ticket_for_month_report(),
|
report_metadata=cls.ticket_for_month_report(),
|
||||||
)
|
)
|
||||||
cls.make_fixture_report(
|
cls.create_report(
|
||||||
identifier="for-month-3",
|
identifier="for-month-3",
|
||||||
process_group_identifier="sartography-admin",
|
process_group_identifier="sartography-admin",
|
||||||
process_model_identifier="ticket",
|
process_model_identifier="ticket",
|
||||||
user=user,
|
user=user,
|
||||||
report_metadata=cls.ticket_for_month_3_report(),
|
report_metadata=cls.ticket_for_month_3_report(),
|
||||||
)
|
)
|
||||||
cls.make_fixture_report(
|
cls.create_report(
|
||||||
identifier="hot-report",
|
identifier="hot-report",
|
||||||
process_group_identifier="category_number_one",
|
process_group_identifier="category_number_one",
|
||||||
process_model_identifier="process-model-with-form",
|
process_model_identifier="process-model-with-form",
|
||||||
@ -128,7 +124,7 @@ class ProcessInstanceReportModel(SpiffworkflowBaseDBModel):
|
|||||||
print("Did not find process models so not adding report fixtures for them")
|
print("Did not find process models so not adding report fixtures for them")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def make_fixture_report(
|
def create_report(
|
||||||
cls,
|
cls,
|
||||||
identifier: str,
|
identifier: str,
|
||||||
process_group_identifier: str,
|
process_group_identifier: str,
|
||||||
@ -137,15 +133,22 @@ class ProcessInstanceReportModel(SpiffworkflowBaseDBModel):
|
|||||||
report_metadata: ReportMetadata,
|
report_metadata: ReportMetadata,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Make_fixture_report."""
|
"""Make_fixture_report."""
|
||||||
process_instance_report = cls(
|
process_instance_report = ProcessInstanceReportModel.query.filter_by(
|
||||||
identifier=identifier,
|
identifier=identifier,
|
||||||
process_group_identifier=process_group_identifier,
|
process_group_identifier=process_group_identifier,
|
||||||
process_model_identifier=process_model_identifier,
|
process_model_identifier=process_group_identifier,
|
||||||
created_by_id=user.id,
|
).first()
|
||||||
report_metadata=report_metadata,
|
|
||||||
)
|
if process_instance_report is None:
|
||||||
db.session.add(process_instance_report)
|
process_instance_report = cls(
|
||||||
db.session.commit()
|
identifier=identifier,
|
||||||
|
process_group_identifier=process_group_identifier,
|
||||||
|
process_model_identifier=process_model_identifier,
|
||||||
|
created_by_id=user.id,
|
||||||
|
report_metadata=report_metadata,
|
||||||
|
)
|
||||||
|
db.session.add(process_instance_report)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def ticket_for_month_report(cls) -> dict:
|
def ticket_for_month_report(cls) -> dict:
|
||||||
|
@ -13,6 +13,7 @@ from flask_bpmn.models.db import db
|
|||||||
from werkzeug.wrappers.response import Response
|
from werkzeug.wrappers.response import Response
|
||||||
|
|
||||||
from spiffworkflow_backend.models.principal import PrincipalModel
|
from spiffworkflow_backend.models.principal import PrincipalModel
|
||||||
|
from spiffworkflow_backend.models.process_instance_report import ProcessInstanceReportModel
|
||||||
from spiffworkflow_backend.models.user import UserModel
|
from spiffworkflow_backend.models.user import UserModel
|
||||||
from spiffworkflow_backend.services.process_instance_processor import (
|
from spiffworkflow_backend.services.process_instance_processor import (
|
||||||
ProcessInstanceProcessor,
|
ProcessInstanceProcessor,
|
||||||
@ -34,6 +35,7 @@ ALLOWED_BPMN_EXTENSIONS = {"bpmn", "dmn"}
|
|||||||
def before_first_request() -> None:
|
def before_first_request() -> None:
|
||||||
"""Before_first_request."""
|
"""Before_first_request."""
|
||||||
token()
|
token()
|
||||||
|
ProcessInstanceReportModel.add_fixtures()
|
||||||
|
|
||||||
|
|
||||||
@admin_blueprint.route("/token", methods=["GET"])
|
@admin_blueprint.route("/token", methods=["GET"])
|
||||||
|
@ -403,7 +403,6 @@ def process_instance_report_list(
|
|||||||
process_group_id: str, process_model_id: str, page: int = 1, per_page: int = 100
|
process_group_id: str, process_model_id: str, page: int = 1, per_page: int = 100
|
||||||
) -> flask.wrappers.Response:
|
) -> flask.wrappers.Response:
|
||||||
"""Process_instance_report_list."""
|
"""Process_instance_report_list."""
|
||||||
ProcessInstanceReportModel.add_fixtures()
|
|
||||||
process_model = get_process_model(process_model_id, process_group_id)
|
process_model = get_process_model(process_model_id, process_group_id)
|
||||||
|
|
||||||
process_instance_reports = ProcessInstanceReportModel.query.filter_by(
|
process_instance_reports = ProcessInstanceReportModel.query.filter_by(
|
||||||
@ -414,6 +413,70 @@ def process_instance_report_list(
|
|||||||
return make_response(jsonify(process_instance_reports), 200)
|
return make_response(jsonify(process_instance_reports), 200)
|
||||||
|
|
||||||
|
|
||||||
|
def process_instance_report_create(
|
||||||
|
process_group_id: str, process_model_id: str,
|
||||||
|
body: Dict[str, Any]
|
||||||
|
) -> flask.wrappers.Response:
|
||||||
|
"""Process_instance_report_create."""
|
||||||
|
|
||||||
|
ProcessInstanceReportModel.create_report(
|
||||||
|
identifier=body['identifier'],
|
||||||
|
process_group_identifier=process_group_id,
|
||||||
|
process_model_identifier=process_model_id,
|
||||||
|
user=g.user,
|
||||||
|
report_metadata=body['report_metadata'],
|
||||||
|
)
|
||||||
|
|
||||||
|
return Response(json.dumps({"ok": True}), status=200, mimetype="application/json")
|
||||||
|
|
||||||
|
|
||||||
|
def process_instance_report_update(
|
||||||
|
process_group_id: str, process_model_id: str,
|
||||||
|
report_identifier: str,
|
||||||
|
body: Dict[str, Any]
|
||||||
|
) -> flask.wrappers.Response:
|
||||||
|
"""Process_instance_report_create."""
|
||||||
|
process_instance_report = ProcessInstanceReportModel.query.filter_by(
|
||||||
|
identifier=report_identifier,
|
||||||
|
process_group_identifier=process_group_id,
|
||||||
|
process_model_identifier=process_model_id,
|
||||||
|
).first()
|
||||||
|
if process_instance_report is None:
|
||||||
|
raise ApiError(
|
||||||
|
code="unknown_process_instance_report",
|
||||||
|
message="Unknown process instance report",
|
||||||
|
status_code=404,
|
||||||
|
)
|
||||||
|
|
||||||
|
process_instance_report.report_metadata = body['report_metadata']
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
return Response(json.dumps({"ok": True}), status=200, mimetype="application/json")
|
||||||
|
|
||||||
|
|
||||||
|
def process_instance_report_delete(
|
||||||
|
process_group_id: str, process_model_id: str,
|
||||||
|
report_identifier: str,
|
||||||
|
) -> flask.wrappers.Response:
|
||||||
|
"""Process_instance_report_create."""
|
||||||
|
process_instance_report = ProcessInstanceReportModel.query.filter_by(
|
||||||
|
identifier=report_identifier,
|
||||||
|
process_group_identifier=process_group_id,
|
||||||
|
process_model_identifier=process_model_id,
|
||||||
|
).first()
|
||||||
|
if process_instance_report is None:
|
||||||
|
raise ApiError(
|
||||||
|
code="unknown_process_instance_report",
|
||||||
|
message="Unknown process instance report",
|
||||||
|
status_code=404,
|
||||||
|
)
|
||||||
|
|
||||||
|
db.session.delete(process_instance_report)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
return Response(json.dumps({"ok": True}), status=200, mimetype="application/json")
|
||||||
|
|
||||||
|
|
||||||
def process_instance_report_show(
|
def process_instance_report_show(
|
||||||
process_group_id: str,
|
process_group_id: str,
|
||||||
process_model_id: str,
|
process_model_id: str,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user