Merge pull request #351 from sartography/367b-CallActivity

Finish #367 - Make sure that we only use a primary_id if it is in the…
This commit is contained in:
Dan Funk 2021-08-10 12:56:25 -04:00 committed by GitHub
commit cdf454b705
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 9 deletions

View File

@ -17,7 +17,7 @@ from crc import session, app
from crc.api.common import ApiError
from crc.models.data_store import DataStoreModel
from crc.models.file import FileType, FileDataModel, FileModel, LookupFileModel, LookupDataModel
from crc.models.workflow import WorkflowSpecModel, WorkflowModel, WorkflowSpecDependencyFile
from crc.models.workflow import WorkflowSpecModel, WorkflowModel, WorkflowSpecDependencyFile, WorkflowLibraryModel
from crc.services.cache_service import cache
from crc.services.user_service import UserService
import re
@ -233,10 +233,18 @@ class FileService(object):
@staticmethod
def get_files(workflow_spec_id=None, workflow_id=None,
name=None, is_reference=False, irb_doc_code=None):
name=None, is_reference=False, irb_doc_code=None, include_libraries=False):
query = session.query(FileModel).filter_by(is_reference=is_reference)
if workflow_spec_id:
query = query.filter_by(workflow_spec_id=workflow_spec_id)
if include_libraries:
libraries = session.query(WorkflowLibraryModel).filter(
WorkflowLibraryModel.workflow_spec_id==workflow_spec_id).all()
library_workflow_specs = [x.library_spec_id for x in libraries]
library_workflow_specs.append(workflow_spec_id)
query = query.filter(FileModel.workflow_spec_id.in_(library_workflow_specs))
else:
query = query.filter(FileModel.workflow_spec_id == workflow_spec_id)
elif workflow_id:
query = query.filter_by(workflow_id=workflow_id)
if irb_doc_code:
@ -255,9 +263,9 @@ class FileService(object):
return results
@staticmethod
def get_spec_data_files(workflow_spec_id, workflow_id=None, name=None):
def get_spec_data_files(workflow_spec_id, workflow_id=None, name=None, include_libraries=False):
"""Returns all the FileDataModels related to a workflow specification.
If a workflow is specified, returns the version of the spec relatted
If a workflow is specified, returns the version of the spec related
to that workflow, otherwise, returns the lastest files."""
if workflow_id:
query = session.query(FileDataModel) \
@ -269,7 +277,7 @@ class FileService(object):
return query.all()
else:
"""Returns all the latest files related to a workflow specification"""
file_models = FileService.get_files(workflow_spec_id=workflow_spec_id)
file_models = FileService.get_files(workflow_spec_id=workflow_spec_id,include_libraries=include_libraries)
latest_data_files = []
for file_model in file_models:
if name and file_model.name == name:

View File

@ -117,7 +117,7 @@ class WorkflowProcessor(object):
if workflow_model.bpmn_workflow_json is None: # The workflow was never started.
self.spec_data_files = FileService.get_spec_data_files(
workflow_spec_id=workflow_model.workflow_spec_id)
workflow_spec_id=workflow_model.workflow_spec_id,include_libraries=True)
spec = self.get_spec(self.spec_data_files, workflow_model.workflow_spec_id)
else:
self.spec_data_files = FileService.get_spec_data_files(
@ -312,7 +312,7 @@ class WorkflowProcessor(object):
for file_data in file_data_models:
if file_data.file_model.type == FileType.bpmn:
bpmn: etree.Element = etree.fromstring(file_data.data)
if file_data.file_model.primary:
if file_data.file_model.primary and file_data.file_model.workflow_spec_id == workflow_spec_id:
process_id = FileService.get_process_id(bpmn)
parser.add_bpmn_xml(bpmn, filename=file_data.file_model.name)
elif file_data.file_model.type == FileType.dmn:

View File

@ -36,7 +36,6 @@ class TestWorkflowApi(BaseTest):
from_tests=True)
user = session.query(UserModel).first()
self.assertIsNotNone(user)
#WorkflowService.get_workflow_from_spec(spec.id, user)
rv = self.app.post(f'/v1.0/workflow-specification/%s/library/%s'%(spec1.id,spec2.id),
follow_redirects=True,