From ef4f90773fa7d941bd6e48c38afc7d38b749a54c Mon Sep 17 00:00:00 2001 From: Jorrit Schaap <schaap@astron.nl> Date: Fri, 19 Jun 2020 16:24:43 +0200 Subject: [PATCH] TMSS-207: added methods to get input- and output-dataproducts --- SAS/TMSS/client/lib/tmss_http_rest_client.py | 8 +++++++ .../src/tmss/tmssapp/viewsets/scheduling.py | 21 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/SAS/TMSS/client/lib/tmss_http_rest_client.py b/SAS/TMSS/client/lib/tmss_http_rest_client.py index 1f426c0b52a..68d256dc8d3 100644 --- a/SAS/TMSS/client/lib/tmss_http_rest_client.py +++ b/SAS/TMSS/client/lib/tmss_http_rest_client.py @@ -204,6 +204,14 @@ class TMSSsession(object): return None return result + def get_subtask_output_dataproducts(self, subtask_id: int) -> []: + '''get the output dataproducts of the subtask with the given subtask_id''' + return self.get_path_as_json_object('subtask/%s/output_dataproducts' % subtask_id) + + def get_subtask_input_dataproducts(self, subtask_id: int) -> []: + '''get the input dataproducts of the subtask with the given subtask_id''' + return self.get_path_as_json_object('subtask/%s/input_dataproducts' % subtask_id) + def specify_observation_task(self, task_id: int) -> requests.Response: """specify observation for the given draft task by just doing a REST API call """ result = self.session.get(url='%s/api/task/%s/specify_observation' % (self.base_url, task_id)) diff --git a/SAS/TMSS/src/tmss/tmssapp/viewsets/scheduling.py b/SAS/TMSS/src/tmss/tmssapp/viewsets/scheduling.py index a8b6c5f55de..359342b1c9c 100644 --- a/SAS/TMSS/src/tmss/tmssapp/viewsets/scheduling.py +++ b/SAS/TMSS/src/tmss/tmssapp/viewsets/scheduling.py @@ -224,6 +224,27 @@ class SubtaskViewSet(LOFARViewSet): context={'request': request}) return RestResponse(serializer.data) + + @swagger_auto_schema(responses={200: 'The input dataproducts of this subtask.', + 403: 'forbidden'}, + operation_description="Get the input dataproducts of this subtask.") + @action(methods=['get'], detail=True, url_name='input_dataproducts') + def input_dataproducts(self, request, pk=None): + dataproducts = models.Dataproduct.objects.filter(subtaskinput__subtask_id=pk) + serializer = serializers.DataproductSerializer(dataproducts, many=True, context={'request': request}) + return RestResponse(serializer.data) + + + @swagger_auto_schema(responses={200: 'The output dataproducts of this subtask.', + 403: 'forbidden'}, + operation_description="Get the output dataproducts of this subtask.") + @action(methods=['get'], detail=True, url_name='output_dataproducts') + def output_dataproducts(self, request, pk=None): + dataproducts = models.Dataproduct.objects.filter(producer__subtask_id=pk) + serializer = serializers.DataproductSerializer(dataproducts, many=True, context={'request': request}) + return RestResponse(serializer.data) + + class SubtaskNestedViewSet(LOFARNestedViewSet): queryset = models.Subtask.objects.all() serializer_class = serializers.SubtaskSerializer -- GitLab