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