use the same file path method in spec file service w/ burnettk

This commit is contained in:
jasquat 2022-11-14 14:25:27 -05:00
parent df9cc2f094
commit aa48268f18
2 changed files with 20 additions and 23 deletions

View File

@ -279,6 +279,8 @@ jobs:
# if: ${{ github.event_name != 'pull_request' }} # if: ${{ github.event_name != 'pull_request' }}
# so just skip everything but main # so just skip everything but main
if: github.ref_name == 'main' if: github.ref_name == 'main'
with:
projectBaseDir: spiffworkflow-backend
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

View File

@ -87,8 +87,10 @@ class SpecFileService(FileSystemService):
type = {str} 'process' / 'decision' type = {str} 'process' / 'decision'
""" """
references: list[FileReference] = [] references: list[FileReference] = []
full_file_path = SpecFileService.file_path(process_model_info, file.name) full_file_path = SpecFileService.full_file_path(process_model_info, file.name)
file_path = os.path.join(process_model_info.id, file.name) relative_file_path = os.path.join(
process_model_info.id_for_file_path(), file.name
)
parser = MyCustomParser() parser = MyCustomParser()
parser_type = None parser_type = None
sub_parser = None sub_parser = None
@ -120,7 +122,7 @@ class SpecFileService(FileSystemService):
name=sub_parser.get_name(), name=sub_parser.get_name(),
type=parser_type, type=parser_type,
file_name=file.name, file_name=file.name,
file_path=file_path, file_path=relative_file_path,
has_lanes=has_lanes, has_lanes=has_lanes,
executable=executable, executable=executable,
messages=messages, messages=messages,
@ -144,12 +146,9 @@ class SpecFileService(FileSystemService):
) -> File: ) -> File:
"""Update_file.""" """Update_file."""
SpecFileService.assert_valid_file_name(file_name) SpecFileService.assert_valid_file_name(file_name)
# file_path = SpecFileService.file_path(process_model_info, file_name) full_file_path = SpecFileService.full_file_path(process_model_info, file_name)
file_path = os.path.join( SpecFileService.write_file_data_to_system(full_file_path, binary_data)
FileSystemService.root_path(), process_model_info.id, file_name file = SpecFileService.to_file_object(file_name, full_file_path)
)
SpecFileService.write_file_data_to_system(file_path, binary_data)
file = SpecFileService.to_file_object(file_name, file_path)
if file.type == FileType.bpmn.value: if file.type == FileType.bpmn.value:
if ( if (
@ -183,34 +182,31 @@ class SpecFileService(FileSystemService):
@staticmethod @staticmethod
def get_data(process_model_info: ProcessModelInfo, file_name: str) -> bytes: def get_data(process_model_info: ProcessModelInfo, file_name: str) -> bytes:
"""Get_data.""" """Get_data."""
# file_path = SpecFileService.file_path(process_model_info, file_name) full_file_path = SpecFileService.full_file_path(process_model_info, file_name)
file_path = os.path.join( if not os.path.exists(full_file_path):
FileSystemService.root_path(), process_model_info.id, file_name
)
if not os.path.exists(file_path):
raise ProcessModelFileNotFoundError( raise ProcessModelFileNotFoundError(
f"No file found with name {file_name} in {process_model_info.display_name}" f"No file found with name {file_name} in {process_model_info.display_name}"
) )
with open(file_path, "rb") as f_handle: with open(full_file_path, "rb") as f_handle:
spec_file_data = f_handle.read() spec_file_data = f_handle.read()
return spec_file_data return spec_file_data
@staticmethod @staticmethod
def file_path(spec: ProcessModelInfo, file_name: str) -> str: def full_file_path(spec: ProcessModelInfo, file_name: str) -> str:
"""File_path.""" """File_path."""
return os.path.join(SpecFileService.workflow_path(spec), file_name) return os.path.join(SpecFileService.workflow_path(spec), file_name)
@staticmethod @staticmethod
def last_modified(spec: ProcessModelInfo, file_name: str) -> datetime: def last_modified(spec: ProcessModelInfo, file_name: str) -> datetime:
"""Last_modified.""" """Last_modified."""
path = SpecFileService.file_path(spec, file_name) full_file_path = SpecFileService.full_file_path(spec, file_name)
return FileSystemService._last_modified(path) return FileSystemService._last_modified(full_file_path)
@staticmethod @staticmethod
def timestamp(spec: ProcessModelInfo, file_name: str) -> float: def timestamp(spec: ProcessModelInfo, file_name: str) -> float:
"""Timestamp.""" """Timestamp."""
path = SpecFileService.file_path(spec, file_name) full_file_path = SpecFileService.full_file_path(spec, file_name)
return FileSystemService._timestamp(path) return FileSystemService._timestamp(full_file_path)
@staticmethod @staticmethod
def delete_file(spec: ProcessModelInfo, file_name: str) -> None: def delete_file(spec: ProcessModelInfo, file_name: str) -> None:
@ -220,9 +216,8 @@ class SpecFileService(FileSystemService):
# for lf in lookup_files: # for lf in lookup_files:
# session.query(LookupDataModel).filter_by(lookup_file_model_id=lf.id).delete() # session.query(LookupDataModel).filter_by(lookup_file_model_id=lf.id).delete()
# session.query(LookupFileModel).filter_by(id=lf.id).delete() # session.query(LookupFileModel).filter_by(id=lf.id).delete()
# file_path = SpecFileService.file_path(spec, file_name) full_file_path = SpecFileService.full_file_path(spec, file_name)
file_path = os.path.join(FileSystemService.root_path(), spec.id, file_name) os.remove(full_file_path)
os.remove(file_path)
@staticmethod @staticmethod
def delete_all_files(spec: ProcessModelInfo) -> None: def delete_all_files(spec: ProcessModelInfo) -> None: