mirror of
https://github.com/sartography/spiffworkflow-backend.git
synced 2025-02-23 12:58:13 +00:00
pyl is passing
This commit is contained in:
parent
98e1776edf
commit
704ce5709e
@ -5,13 +5,12 @@ from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
import marshmallow
|
||||
from flask_bpmn.models.db import db
|
||||
from flask_bpmn.models.db import SpiffworkflowBaseDBModel
|
||||
from marshmallow import INCLUDE
|
||||
from marshmallow import Schema
|
||||
|
||||
from spiffworkflow_backend.helpers.spiff_enum import SpiffEnum
|
||||
|
||||
|
||||
class FileType(SpiffEnum):
|
||||
"""FileType."""
|
||||
|
||||
@ -62,15 +61,21 @@ CONTENT_TYPES = {
|
||||
"zip": "application/zip",
|
||||
}
|
||||
|
||||
|
||||
@dataclass()
|
||||
class FileReference:
|
||||
"""File Reference Information -- such as the process id and name for a BPMN,
|
||||
"""File Reference Information.
|
||||
|
||||
Includes items such as the process id and name for a BPMN,
|
||||
or the Decision id and Decision name for a DMN file. There may be more than
|
||||
one reference that points to a particular file."""
|
||||
one reference that points to a particular file.
|
||||
"""
|
||||
|
||||
id: str
|
||||
name: str
|
||||
type: str # can be 'process', 'decision', or just 'file'
|
||||
|
||||
|
||||
@dataclass(order=True)
|
||||
class File:
|
||||
"""File."""
|
||||
@ -82,12 +87,11 @@ class File:
|
||||
type: str
|
||||
last_modified: datetime
|
||||
size: int
|
||||
references: list[FileReference] = None
|
||||
references: Optional[list[FileReference]] = None
|
||||
file_contents: Optional[bytes] = None
|
||||
process_model_id: Optional[str] = None
|
||||
process_group_id: Optional[str] = None
|
||||
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
"""__post_init__."""
|
||||
self.sort_index = f"{self.type}:{self.name}"
|
||||
@ -132,10 +136,12 @@ class FileSchema(Schema):
|
||||
"file_contents",
|
||||
"references",
|
||||
"process_group_id",
|
||||
"process_model_id"
|
||||
"process_model_id",
|
||||
]
|
||||
unknown = INCLUDE
|
||||
references = marshmallow.fields.List(marshmallow.fields.Nested("FileReferenceSchema"))
|
||||
references = marshmallow.fields.List(
|
||||
marshmallow.fields.Nested("FileReferenceSchema")
|
||||
)
|
||||
|
||||
|
||||
class FileReferenceSchema(Schema):
|
||||
@ -145,14 +151,5 @@ class FileReferenceSchema(Schema):
|
||||
"""Meta."""
|
||||
|
||||
model = FileReference
|
||||
fields = [
|
||||
"id",
|
||||
"name",
|
||||
"type"
|
||||
]
|
||||
fields = ["id", "name", "type"]
|
||||
unknown = INCLUDE
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -64,8 +64,9 @@ from spiffworkflow_backend.services.error_handling_service import ErrorHandlingS
|
||||
from spiffworkflow_backend.services.file_system_service import FileSystemService
|
||||
from spiffworkflow_backend.services.git_service import GitService
|
||||
from spiffworkflow_backend.services.message_service import MessageService
|
||||
from spiffworkflow_backend.services.process_instance_processor import MyCustomParser
|
||||
from spiffworkflow_backend.services.process_instance_processor import (
|
||||
ProcessInstanceProcessor, MyCustomParser,
|
||||
ProcessInstanceProcessor,
|
||||
)
|
||||
from spiffworkflow_backend.services.process_instance_service import (
|
||||
ProcessInstanceService,
|
||||
@ -264,7 +265,9 @@ def process_model_show(process_group_id: str, process_model_id: str) -> Any:
|
||||
files = sorted(SpecFileService.get_files(process_model))
|
||||
process_model.files = files
|
||||
for file in process_model.files:
|
||||
file.references = SpecFileService.get_references_for_file(file, process_model, MyCustomParser)
|
||||
file.references = SpecFileService.get_references_for_file(
|
||||
file, process_model, MyCustomParser
|
||||
)
|
||||
process_model_json = ProcessModelInfoSchema().dump(process_model)
|
||||
return process_model_json
|
||||
|
||||
|
@ -2,11 +2,10 @@
|
||||
import os
|
||||
import shutil
|
||||
from datetime import datetime
|
||||
from typing import Any
|
||||
from typing import List
|
||||
from typing import Optional
|
||||
|
||||
from SpiffWorkflow.bpmn.parser.BpmnParser import BpmnParser
|
||||
from SpiffWorkflow.dmn.parser.BpmnDmnParser import BpmnDmnParser
|
||||
from flask_bpmn.api.api_error import ApiError
|
||||
from flask_bpmn.models.db import db
|
||||
from lxml import etree # type: ignore
|
||||
@ -15,7 +14,8 @@ from lxml.etree import Element as EtreeElement
|
||||
from SpiffWorkflow.bpmn.parser.ValidationException import ValidationException # type: ignore
|
||||
|
||||
from spiffworkflow_backend.models.bpmn_process_id_lookup import BpmnProcessIdLookup
|
||||
from spiffworkflow_backend.models.file import File, FileReference
|
||||
from spiffworkflow_backend.models.file import File
|
||||
from spiffworkflow_backend.models.file import FileReference
|
||||
from spiffworkflow_backend.models.file import FileType
|
||||
from spiffworkflow_backend.models.message_correlation_property import (
|
||||
MessageCorrelationPropertyModel,
|
||||
@ -56,35 +56,39 @@ class SpecFileService(FileSystemService):
|
||||
)
|
||||
return files
|
||||
|
||||
|
||||
@staticmethod
|
||||
def get_references_for_file(file: File, process_model_info: ProcessModelInfo, parser_class: any) -> \
|
||||
list[FileReference]:
|
||||
""" Uses spiffworkflow to parse BPMN and DMN files to determine how they can be externally referenced
|
||||
def get_references_for_file(
|
||||
file: File, process_model_info: ProcessModelInfo, parser_class: Any
|
||||
) -> list[FileReference]:
|
||||
"""Uses spiffworkflow to parse BPMN and DMN files to determine how they can be externally referenced.
|
||||
|
||||
Returns a list of Reference objects that contain the type of reference, the id, the name.
|
||||
Ex.
|
||||
id = {str} 'Level3'
|
||||
name = {str} 'Level 3'
|
||||
type = {str} 'process'
|
||||
"""
|
||||
references = []
|
||||
references: list[FileReference] = []
|
||||
file_path = SpecFileService.file_path(process_model_info, file.name)
|
||||
parser = parser_class()
|
||||
parser_type = None
|
||||
sub_parser = None
|
||||
if file.type == FileType.bpmn.value:
|
||||
parser.add_bpmn_file(file_path)
|
||||
parser_type = 'process'
|
||||
parser_type = "process"
|
||||
sub_parsers = list(parser.process_parsers.values())
|
||||
elif file.type == FileType.dmn.value:
|
||||
parser.add_dmn_file(file_path)
|
||||
sub_parsers = list(parser.dmn_parsers.values())
|
||||
parser_type = 'decision'
|
||||
parser_type = "decision"
|
||||
else:
|
||||
return references;
|
||||
return references
|
||||
for sub_parser in sub_parsers:
|
||||
references.append(FileReference(
|
||||
id=sub_parser.get_id(), name=sub_parser.get_name(), type=parser_type))
|
||||
references.append(
|
||||
FileReference(
|
||||
id=sub_parser.get_id(), name=sub_parser.get_name(), type=parser_type
|
||||
)
|
||||
)
|
||||
return references
|
||||
|
||||
@staticmethod
|
||||
|
@ -1 +1 @@
|
||||
{}
|
||||
{}
|
||||
|
@ -2,17 +2,16 @@
|
||||
import os
|
||||
|
||||
import pytest
|
||||
from SpiffWorkflow.dmn.parser.BpmnDmnParser import BpmnDmnParser
|
||||
from flask import Flask
|
||||
from flask_bpmn.api.api_error import ApiError
|
||||
from flask_bpmn.models.db import db
|
||||
|
||||
from spiffworkflow_backend.services.process_model_service import ProcessModelService
|
||||
from spiffworkflow_backend.services.spec_file_service import SpecFileService
|
||||
from SpiffWorkflow.dmn.parser.BpmnDmnParser import BpmnDmnParser # type: ignore
|
||||
from tests.spiffworkflow_backend.helpers.base_test import BaseTest
|
||||
from tests.spiffworkflow_backend.helpers.test_data import load_test_spec
|
||||
|
||||
from spiffworkflow_backend.models.bpmn_process_id_lookup import BpmnProcessIdLookup
|
||||
from spiffworkflow_backend.services.process_model_service import ProcessModelService
|
||||
from spiffworkflow_backend.services.spec_file_service import SpecFileService
|
||||
|
||||
|
||||
class TestSpecFileService(BaseTest):
|
||||
@ -100,10 +99,11 @@ class TestSpecFileService(BaseTest):
|
||||
== self.call_activity_nested_relative_file_path
|
||||
)
|
||||
|
||||
def test_load_reference_information (
|
||||
def test_load_reference_information(
|
||||
self, app: Flask, with_db_and_bpmn_file_cleanup: None
|
||||
) -> None:
|
||||
"""
|
||||
"""Test_load_reference_information.
|
||||
|
||||
When getting files from the spec_file service, each file includes
|
||||
details about how the file can be referenced -- for instance
|
||||
it is possible to reference a DMN file with a Decision.id or
|
||||
@ -112,24 +112,30 @@ class TestSpecFileService(BaseTest):
|
||||
Note that a single bpmn file can contain many processes, and
|
||||
a DMN file can (theoretically) contain many decisions. So this
|
||||
is an array.
|
||||
"""
|
||||
"""
|
||||
load_test_spec(
|
||||
"call_activity_nested",
|
||||
process_model_source_directory="call_activity_nested")
|
||||
process_model_info = ProcessModelService().get_process_model("call_activity_nested")
|
||||
process_model_source_directory="call_activity_nested",
|
||||
)
|
||||
process_model_info = ProcessModelService().get_process_model(
|
||||
"call_activity_nested"
|
||||
)
|
||||
files = SpecFileService.get_files(process_model_info)
|
||||
|
||||
file = next(filter(lambda f : f.name == 'call_activity_level_3.bpmn', files))
|
||||
ca_3 = SpecFileService.get_references_for_file(file, process_model_info, BpmnDmnParser)
|
||||
assert(len(ca_3) == 1)
|
||||
assert(ca_3[0].name == 'Level 3')
|
||||
assert(ca_3[0].id == 'Level3')
|
||||
assert(ca_3[0].type == 'process')
|
||||
|
||||
file = next(filter(lambda f : f.name == 'level2c.dmn', files))
|
||||
dmn1 = SpecFileService.get_references_for_file(file, process_model_info, BpmnDmnParser)
|
||||
assert(len(dmn1) == 1)
|
||||
assert(dmn1[0].name == 'Decision 1')
|
||||
assert(dmn1[0].id == 'Decision_0vrtcmk')
|
||||
assert(dmn1[0].type == 'decision')
|
||||
file = next(filter(lambda f: f.name == "call_activity_level_3.bpmn", files))
|
||||
ca_3 = SpecFileService.get_references_for_file(
|
||||
file, process_model_info, BpmnDmnParser
|
||||
)
|
||||
assert len(ca_3) == 1
|
||||
assert ca_3[0].name == "Level 3"
|
||||
assert ca_3[0].id == "Level3"
|
||||
assert ca_3[0].type == "process"
|
||||
|
||||
file = next(filter(lambda f: f.name == "level2c.dmn", files))
|
||||
dmn1 = SpecFileService.get_references_for_file(
|
||||
file, process_model_info, BpmnDmnParser
|
||||
)
|
||||
assert len(dmn1) == 1
|
||||
assert dmn1[0].name == "Decision 1"
|
||||
assert dmn1[0].id == "Decision_0vrtcmk"
|
||||
assert dmn1[0].type == "decision"
|
||||
|
Loading…
x
Reference in New Issue
Block a user