예제 #1
0
def convert_definition_to_v6_json(definition):
    """Returns the v6 dataset definition JSON for the given definition

    :param definition: The dataset definition
    :type definition: :class:`data.dataset.dataset.DataSetDefinition`
    :returns: The v6 dataset definition JSON
    :rtype: :class:`data.dataset.json.dataset_v6.DataSetDefinitionV6`
    """

    def_dict = {
        'version': SCHEMA_VERSION
    }

    if definition.parameters:
        interface_dict = convert_interface_to_v6_json(definition.parameters).get_dict()
        def_dict['parameters'] = rest_utils.strip_schema_version(interface_dict)

    if definition.global_parameters:
        interface_dict = convert_interface_to_v6_json(definition.global_parameters).get_dict()
        def_dict['global_parameters'] = rest_utils.strip_schema_version(interface_dict)

    if definition.global_data:
        data_dict = convert_data_to_v6_json(definition.global_data).get_dict()
        def_dict['global_data'] = rest_utils.strip_schema_version(data_dict)

    return DataSetDefinitionV6(definition=def_dict, do_validate=False)
예제 #2
0
    def get_v6_configuration_json(self):
        """Returns the batch configuration in v6 of the JSON schema

        :returns: The batch configuration in v6 of the JSON schema
        :rtype: dict
        """

        return rest_utils.strip_schema_version(convert_configuration_to_v6(self.get_configuration()).get_dict())
예제 #3
0
파일: views.py 프로젝트: marketboy/scale
    def _post_v6(self, request):
        """The v6 version for validating a new batch

        :param request: the HTTP POST request
        :type request: :class:`rest_framework.request.Request`
        :rtype: :class:`rest_framework.response.Response`
        :returns: the HTTP response to send back to the user
        """

        recipe_type_id = rest_util.parse_int(request, 'recipe_type_id')
        definition_dict = rest_util.parse_dict(request, 'definition')
        configuration_dict = rest_util.parse_dict(request,
                                                  'configuration',
                                                  required=False)

        # Make sure the recipe type exists
        try:
            recipe_type = RecipeType.objects.get(pk=recipe_type_id)
        except RecipeType.DoesNotExist:
            raise BadParameter('Unknown recipe type: %d' % recipe_type_id)

        try:
            definition = BatchDefinitionV6(definition=definition_dict,
                                           do_validate=True).get_definition()
            configuration = BatchConfigurationV6(
                configuration=configuration_dict,
                do_validate=True).get_configuration()
        except InvalidDefinition as ex:
            raise BadParameter(unicode(ex))
        except InvalidConfiguration as ex:
            raise BadParameter(unicode(ex))

        # Validate the batch
        validation = Batch.objects.validate_batch_v6(
            recipe_type, definition, configuration=configuration)
        batch = validation.batch
        recipe_type_serializer = RecipeTypeBaseSerializerV6(batch.recipe_type)
        resp_dict = {
            'is_valid': validation.is_valid,
            'errors': [e.to_dict() for e in validation.errors],
            'warnings': [w.to_dict() for w in validation.warnings],
            'recipes_estimated': definition.estimated_recipes,
            'recipe_type': recipe_type_serializer.data
        }
        if batch.superseded_batch:
            recipe_type_rev_serializer = RecipeTypeRevisionBaseSerializerV6(
                batch.superseded_batch.recipe_type_rev)
            prev_batch_dict = {
                'recipe_type_rev': recipe_type_rev_serializer.data
            }
            resp_dict['prev_batch'] = prev_batch_dict
            if definition.prev_batch_diff:
                diff_v6 = convert_recipe_diff_to_v6_json(
                    definition.prev_batch_diff)
                diff_dict = rest_util.strip_schema_version(diff_v6.get_dict())
                prev_batch_dict['diff'] = diff_dict
        return Response(resp_dict)
예제 #4
0
파일: models.py 프로젝트: kaydoh/scale
    def get_v6_data_json(self):
        """Returns the data for this datasetmember as v6 json with the version stripped

        :returns: The v6 JSON output data dict for this datasetmember
        :rtype: dict
        """

        return rest_utils.strip_schema_version(
            convert_data_to_v6_json(self.get_data()).get_dict())
예제 #5
0
파일: models.py 프로젝트: kaydoh/scale
    def get_v6_definition_json(self):
        """Returns the dataset definition in v6 of the JSON schema

        :returns: The dataset definition in v6 of the JSON schema
        :rtype: dict
        """

        return rest_utils.strip_schema_version(
            convert_definition_to_v6_json(self.get_definition()).get_dict())
예제 #6
0
    def get_v6_configuration_json(self):
        """Returns the scan configuration in v6 of the JSON schema

        :returns: The scan configuration in v6 of the JSON schema
        :rtype: dict
        """

        #schemas are identical except for version number, just return dict with version stripped
        return rest_utils.strip_schema_version(self.configuration)
예제 #7
0
    def get_v6_definition_json(self):
        """Returns the batch definition in v6 of the JSON schema

        :returns: The batch definition in v6 of the JSON schema
        :rtype: dict
        """

        # Handle batches with old (pre-v6) definitions
        if 'version' in self.definition and self.definition['version'] == '1.0':
            return {}

        return rest_utils.strip_schema_version(convert_definition_to_v6(self.get_definition()).get_dict())
예제 #8
0
    def _populate_default_values(self, do_validate=False):
        """Populates any missing JSON fields that have default values
        """

        if 'parameters' not in self._definition:
            self._definition['parameters'] = InterfaceV6().get_dict()
        elif type(self._definition['parameters']) is not dict:
            raise InvalidDataSetDefinition('INVALID_DATASET_DEFINITION', '"parameters" is not a dictionary')
        else:
            self._definition['parameters'] = InterfaceV6(interface=self._definition['parameters'], do_validate=do_validate).get_dict()
        rest_utils.strip_schema_version(self._definition['parameters'])

        if 'global_parameters' not in self._definition:
            self._definition['global_parameters'] = InterfaceV6().get_dict()
        elif type(self._definition['global_parameters']) is not dict:
            raise InvalidDataSetDefinition('INVALID_DATASET_DEFINITION', '"global_parameters" is not a dictionary')
        else:
            self._definition['global_parameters'] = InterfaceV6(interface=self._definition['global_parameters'], do_validate=do_validate).get_dict()
        rest_utils.strip_schema_version(self._definition['global_parameters'])

        if 'global_data' not in self._definition:
            self._definition['global_data'] = DataV6().get_dict()
        elif type(self._definition['global_data']) is not dict:
            raise InvalidDataSetDefinition('INVALID_DATASET_DEFINITION', '"global_data" is not a dictionary')
        else:
            self._definition['global_data'] = DataV6(data=self._definition['global_data'], do_validate=do_validate).get_dict()
        rest_utils.strip_schema_version(self._definition['global_data'])
예제 #9
0
    def _populate_default_values(self):
        """Populates any missing required values with defaults
        """

        if 'input' not in self._definition:
            self._definition['input'] = {}
        if 'nodes' not in self._definition:
            self._definition['nodes'] = {}

        # Populate defaults for input interface
        interface_json = InterfaceV6(self._definition['input'],
                                     do_validate=False)
        self._definition['input'] = strip_schema_version(
            interface_json.get_dict())