Skip to content

Commit

Permalink
Updating process model to store bpmn files as binary in database
Browse files Browse the repository at this point in the history
  • Loading branch information
ratheesh-aot committed Jul 22, 2024
1 parent 678cc4f commit c0cc9d8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion spiffworkflow-backend/migrations/versions/1801292017d5_.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def upgrade():
sa.Column('is_executable', sa.Boolean(), nullable=True),
sa.Column('fault_or_suspend_on_exception', sa.String(), nullable=True),
sa.Column('process_group', sa.String(), nullable=True),
sa.Column('content', sa.Text(), nullable=True),
sa.Column('content', sa.LargeBinary(), nullable=True),
sa.Column('type', sa.String(), nullable=True),
sa.Column('bpmn_version_control_identifier', sa.String(), nullable=True),
sa.PrimaryKeyConstraint('process_id')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

import enum
import os
from datetime import datetime

from dataclasses import dataclass
from dataclasses import field
from typing import Any
Expand All @@ -21,7 +23,7 @@
from marshmallow.decorators import post_load

from spiffworkflow_backend.interfaces import ProcessGroupLite
from spiffworkflow_backend.models.file import File
from spiffworkflow_backend.models.file import File, CONTENT_TYPES

# we only want to save these items to the json file
PROCESS_MODEL_SUPPORTED_KEYS_FOR_DISK_SERIALIZATION = [
Expand Down Expand Up @@ -54,12 +56,13 @@ class ProcessModelInfo(SpiffworkflowBaseDBModel):
process_group=db.Column(db.String, default="formsflow")

# files: list[File] | None = field(default_factory=list[File])
content = db.Column(db.Text)
content = db.Column(db.LargeBinary)
type = db.Column(db.String, default="bpmn") # BPMN or DMN

# just for the API
# parent_groups: list[ProcessGroupLite] | None = None
bpmn_version_control_identifier= db.Column(db.String)


@property
def primary_file_name(self):
Expand Down Expand Up @@ -87,7 +90,20 @@ def display_order(self):

@property
def files(self):
return [self.content]
file_objects = []
for content in [self.content]:
if content:
file = File(
content_type=CONTENT_TYPES.get(self.type, "application/octet-stream"),
name=(self.display_name or "bpmn_file") + '.bpmn',
type=self.type,
last_modified=datetime.now(), # Placeholder for actual last modified time
size=len(content),
file_contents=content,
process_model_id=self.id,
)
file_objects.append(file)
return file_objects

@property
def parent_groups(self):
Expand Down Expand Up @@ -122,11 +138,12 @@ def modify_process_identifier_for_path_param(cls, identifier: str) -> str:

def serialized(self) -> dict[str, Any]:
file_objects = self.files
dictionary = self.__dict__
dictionary = {k: v for k, v in self.__dict__.items() if k != "_sa_instance_state" and k != "content"}
if file_objects is not None:
serialized_files = []
for file in file_objects:
serialized_files.append(file.serialized())
if file is not None:
serialized_files.append(file.serialized())
dictionary["files"] = serialized_files
return dictionary

Expand Down

0 comments on commit c0cc9d8

Please sign in to comment.