get_files needs to have workflow_spec_id
This commit is contained in:
parent
68820c67cb
commit
9ea1399578
|
@ -802,6 +802,12 @@ paths:
|
|||
|
||||
/file:
|
||||
parameters:
|
||||
- name: workflow_spec_id
|
||||
in: query
|
||||
required: false
|
||||
description: The unique id of a workflow specification
|
||||
schema:
|
||||
type: string
|
||||
- name: workflow_id
|
||||
in: query
|
||||
required: false
|
||||
|
|
|
@ -28,21 +28,22 @@ def to_file_api(file_model):
|
|||
DocumentService.get_dictionary())
|
||||
|
||||
|
||||
def get_files(workflow_id=None, form_field_key=None,study_id=None):
|
||||
if workflow_id is None:
|
||||
def get_files(workflow_spec_id=None, workflow_id=None, form_field_key=None,study_id=None):
|
||||
if all(v is None for v in [workflow_spec_id, workflow_id, form_field_key,study_id]):
|
||||
raise ApiError('missing_parameter',
|
||||
'Please specify a workflow_id with an optional form_field_key')
|
||||
'Please specify either a workflow_spec_id or a '
|
||||
'workflow_id with an optional form_field_key')
|
||||
|
||||
if study_id is not None:
|
||||
file_models = FileService.get_files_for_study(study_id=study_id, irb_doc_code=form_field_key)
|
||||
else:
|
||||
file_models = FileService.get_files(workflow_id=workflow_id,
|
||||
irb_doc_code=form_field_key)
|
||||
file_models = FileService.get_files(workflow_spec_id=workflow_spec_id,
|
||||
workflow_id=workflow_id,
|
||||
irb_doc_code=form_field_key)
|
||||
|
||||
files = (to_file_api(model) for model in file_models)
|
||||
return FileSchema(many=True).dump(files)
|
||||
|
||||
|
||||
def get_spec_files(workflow_spec_id, include_libraries=False):
|
||||
if workflow_spec_id is None:
|
||||
raise ApiError(code='missing_spec_id',
|
||||
|
|
|
@ -16,7 +16,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 WorkflowModel
|
||||
from crc.models.workflow import WorkflowModel, WorkflowLibraryModel
|
||||
from crc.services.cache_service import cache
|
||||
from crc.services.user_service import UserService
|
||||
import re
|
||||
|
@ -163,21 +163,35 @@ class FileService(object):
|
|||
return query.all()
|
||||
|
||||
@staticmethod
|
||||
def get_files(workflow_id=None, name=None, irb_doc_code=None):
|
||||
if workflow_id is not None:
|
||||
query = session.query(FileModel).filter_by(workflow_id=workflow_id)
|
||||
def get_files(workflow_spec_id=None, workflow_id=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:
|
||||
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:
|
||||
query = query.filter_by(irb_doc_code=irb_doc_code)
|
||||
elif is_reference:
|
||||
query = query.filter_by(is_reference=True)
|
||||
|
||||
if name:
|
||||
query = query.filter_by(name=name)
|
||||
if name:
|
||||
query = query.filter_by(name=name)
|
||||
|
||||
query = query.filter(FileModel.archived == False)
|
||||
query = query.order_by(FileModel.id)
|
||||
query = query.filter(FileModel.archived == False)
|
||||
|
||||
results = query.all()
|
||||
return results
|
||||
query = query.order_by(FileModel.id)
|
||||
|
||||
results = query.all()
|
||||
return results
|
||||
|
||||
@staticmethod
|
||||
def get_workflow_data_files(workflow_id=None):
|
||||
|
|
Loading…
Reference in New Issue