def get(self, request): query_list_types = ["job_groups", "jira_ids", "request_ids", "runs"] fixed_query_params = fix_query_list(request.query_params, query_list_types) serializer = CWLJsonSerializer(data=fixed_query_params) show_inputs = False if serializer.is_valid(): job_groups = fixed_query_params.get("job_groups") jira_ids = fixed_query_params.get("jira_ids") request_ids = fixed_query_params.get("request_ids") runs = fixed_query_params.get("runs") cwl_inputs = fixed_query_params.get("cwl_inputs") if not job_groups and not jira_ids and not request_ids and not runs: return Response("Error: No runs specified", status=status.HTTP_400_BAD_REQUEST) queryset = Run.objects.all() if job_groups: queryset = queryset.filter(job_group__in=job_groups) if jira_ids: queryset = queryset.filter( job_group_notifier__jira_id__in=jira_ids) if request_ids: queryset = queryset.filter(tags__requestId__in=request_ids) if runs: queryset = queryset.filter(id__in=runs) if cwl_inputs: show_inputs = bool(strtobool(cwl_inputs)) try: page = self.paginate_queryset( queryset.order_by("-created_date").all()) except ValidationError as e: return Response(e, status=status.HTTP_400_BAD_REQUEST) if page is not None: if show_inputs: serializer = RunSerializerCWLInput(page, many=True) else: serializer = RunSerializerCWLOutput(page, many=True) return self.get_paginated_response(serializer.data) else: return Response([], status=status.HTTP_200_OK) else: return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def list(self, request, *args, **kwargs): query_list_types = [ "file_group", "path", "metadata", "metadata_regex", "filename", "file_type", "values_metadata", "exclude_null_metadata", ] fixed_query_params = fix_query_list(request.query_params, query_list_types) serializer = FileQuerySerializer(data=fixed_query_params) if serializer.is_valid(): queryset = FileRepository.all() queryset = time_filter(FileMetadata, request.query_params, time_modal="modified_date", previous_queryset=queryset) file_group = fixed_query_params.get("file_group") path = fixed_query_params.get("path") metadata = fixed_query_params.get("metadata") metadata_regex = fixed_query_params.get("metadata_regex") path_regex = fixed_query_params.get("path_regex") filename = fixed_query_params.get("filename") filename_regex = fixed_query_params.get("filename_regex") file_type = fixed_query_params.get("file_type") values_metadata = fixed_query_params.get("values_metadata") exclude_null_metadata = fixed_query_params.get( "exclude_null_metadata") order_by = fixed_query_params.get("order_by") distinct_metadata = fixed_query_params.get("distinct_metadata") kwargs = {"queryset": queryset} if file_group: if len(file_group) == 1: kwargs["file_group"] = file_group[0] else: kwargs["file_group_in"] = file_group if path: if len(path) == 1: kwargs["path"] = path[0] else: kwargs["path_in"] = path if metadata: filter_query = dict() for val in metadata: k, v = val.split(":") metadata_field = k.strip() if metadata_field not in filter_query: filter_query[metadata_field] = [v.strip()] else: filter_query[metadata_field].append(v.strip()) if filter_query: kwargs["metadata"] = filter_query if metadata_regex: filter_query = [] for single_reqex_query in metadata_regex: single_value = single_reqex_query.split("|") single_reqex_filters = [] for val in single_value: k, v = val.split(":") single_reqex_filters.append((k.strip(), v.strip())) filter_query.append(single_reqex_filters) if filter_query: kwargs["metadata_regex"] = filter_query if path_regex: kwargs["path_regex"] = path_regex if filename: if len(filename) == 1: kwargs["file_name"] = filename[0] else: kwargs["file_name_in"] = filename if filename_regex: kwargs["file_name_regex"] = filename_regex if file_type: if len(file_type) == 1: kwargs["file_type"] = file_type[0] else: kwargs["file_type_in"] = file_type if exclude_null_metadata: kwargs["exclude"] = exclude_null_metadata if order_by: kwargs["order_by"] = order_by if distinct_metadata: kwargs["distinct"] = distinct_metadata if values_metadata: if len(values_metadata) == 1: kwargs["values_metadata"] = values_metadata[0] else: kwargs["values_metadata_list"] = values_metadata try: queryset = FileRepository.filter(**kwargs) except Exception as e: return Response({"details": str(e)}, status=status.HTTP_400_BAD_REQUEST) page = self.paginate_queryset(queryset) if page is not None: if values_metadata: return self.get_paginated_response(page) else: serializer = FileSerializer(page, many=True, context={"request": request}) return self.get_paginated_response(serializer.data) else: return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def list(self, request, *args, **kwargs): query_list_types = [ 'job_groups', 'request_ids', 'inputs', 'tags', 'jira_ids', 'run_ids', 'apps', 'run', 'values_run', 'ports' ] fixed_query_params = fix_query_list(request.query_params, query_list_types) serializer = RunApiListSerializer(data=fixed_query_params) if serializer.is_valid(): queryset = time_filter(Run, fixed_query_params) queryset = time_filter(Run, request.query_params, time_modal='modified_date', previous_queryset=queryset) job_groups = fixed_query_params.get('job_groups') jira_ids = fixed_query_params.get('jira_ids') run_ids = fixed_query_params.get('run_ids') status_param = fixed_query_params.get('status') ports = fixed_query_params.get('ports') tags = fixed_query_params.get('tags') request_ids = fixed_query_params.get('request_ids') apps = fixed_query_params.get('apps') values_run = fixed_query_params.get('values_run') run = fixed_query_params.get('run') run_distribution = fixed_query_params.get('run_distribution') count = fixed_query_params.get('count') full = fixed_query_params.get('full') if full: full = bool(strtobool(full)) if job_groups: queryset = queryset.filter(job_group__in=job_groups) if jira_ids: queryset = queryset.filter(job_group__jira_id__in=jira_ids) if run_ids: queryset = queryset.filter(id__in=run_ids) if status_param: queryset = queryset.filter( status=RunStatus[status_param].value) if ports: queryset = self.query_from_dict("port__%s__exact", queryset, ports) if tags: queryset = self.query_from_dict("tags__%s__contains", queryset, tags) if request_ids: queryset = queryset.filter(tags__requestId__in=request_ids) if apps: queryset = queryset.filter(app__in=apps) if run: filter_query = dict() for single_run in run: key, value = single_run.split(':') if value == 'True' or value == 'true': value = True if value == 'False' or value == 'false': value = False filter_query[key] = value if filter_query: queryset = queryset.filter(**filter_query) if values_run: if len(values_run) == 1: ret_str = values_run[0] queryset = queryset.values_list( ret_str, flat=True).order_by(ret_str).distinct(ret_str) else: values_run_query_list = [ single_run for single_run in values_run ] values_run_query_set = set(values_run_query_list) sorted_query_list = sorted(values_run_query_set) queryset = queryset.values_list( *sorted_query_list).distinct() if run_distribution: distribution_dict = {} run_query = run_distribution run_ids = queryset.values_list('id', flat=True) queryset = Run.objects.all() queryset = queryset.filter( id__in=run_ids).values(run_query).order_by().annotate( Count(run_query)) for single_arg in queryset: single_arg_name = None single_arg_count = 0 for single_key, single_value in single_arg.items(): if 'count' in single_key: single_arg_count = single_value else: single_arg_name = single_value if single_arg_name is not None: distribution_dict[single_arg_name] = single_arg_count return Response(distribution_dict, status=status.HTTP_200_OK) if count: count = bool(strtobool(count)) if count: return Response(queryset.count(), status=status.HTTP_200_OK) try: page = self.paginate_queryset(queryset.all()) except ValidationError as e: return Response(e, status=status.HTTP_400_BAD_REQUEST) if page is not None: if values_run: return self.get_paginated_response(page) if full: serializer = RunSerializerFull(page, many=True) else: serializer = RunSerializerPartial(page, many=True) return self.get_paginated_response(serializer.data) return Response([], status=status.HTTP_200_OK) else: return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def list(self, request, *args, **kwargs): query_list_types = ['job_group','values_args','args'] fixed_query_params = fix_query_list(request.query_params, query_list_types) serializer = JobQuerySerializer(data=fixed_query_params) if serializer.is_valid(): queryset = time_filter(Job, request.query_params) queryset = time_filter(Job, request.query_params,time_modal='modified_date', previous_queryset=queryset) job_group = fixed_query_params.get('job_group') job_type = fixed_query_params.get('type') sample_id = fixed_query_params.get('sample_id') request_id = fixed_query_params.get('request_id') st = fixed_query_params.get('status') values_args = fixed_query_params.get('values_args') args = fixed_query_params.get('args') args_distribution = fixed_query_params.get('args_distribution') count = fixed_query_params.get('count') if job_group: queryset = queryset.filter(job_group__in=job_group) if job_type: queryset = queryset.filter(run=TYPES[job_type]) if sample_id: queryset = queryset.filter(args__sample_id=sample_id) if request_id: queryset = queryset.filter(args__request_id=request_id) if st: queryset = queryset.filter(status=JobStatus[st].value) if args: filter_query = dict() for single_arg in args: key, value = single_arg.split(':') key = 'args__%s' % key if value == 'True' or value == 'true': value = True if value == 'False' or value == 'false': value = False filter_query[key] = value if filter_query: queryset = queryset.filter(**filter_query) if values_args: if len(values_args) == 1: ret_str = 'args__%s' % values_args[0] queryset = queryset.values_list(ret_str, flat=True).order_by(ret_str).distinct(ret_str) else: values_args_query_list = ['args__%s' % single_arg for single_arg in values_args ] values_args_query_set = set(values_args_query_list) queryset = queryset.values_list(*values_args_query_set).order_by(values_args_query_list[0]).distinct() if args_distribution: distribution_dict = {} args_query = 'args__%s' % args_distribution job_ids = queryset.values_list('id',flat=True) queryset = Job.objects.all() queryset = queryset.filter(id__in=job_ids).values(args_query).order_by().annotate(Count(args_query)) for single_arg in queryset: single_arg_name = None single_arg_count = 0 for single_key, single_value in single_arg.items(): if 'count' in single_key: single_arg_count = single_value else: single_arg_name = single_value if single_arg_name is not None: distribution_dict[single_arg_name] = single_arg_count return Response(distribution_dict, status=status.HTTP_200_OK) if count: count = bool(strtobool(count)) if count: return Response(queryset.count(), status=status.HTTP_200_OK) page = self.paginate_queryset(queryset.all()) if page is not None: if values_args: return self.get_paginated_response(page) else: serializer = JobSerializer(page, many=True) return self.get_paginated_response(serializer.data) else: return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)