Skip to content
Snippets Groups Projects
Commit 1ebda268 authored by Jorrit Schaap's avatar Jorrit Schaap
Browse files

TMSS-142: initial implementation of validation of subtask specification against its schema

parent d98fa10e
No related branches found
No related tags found
2 merge requests!98Resolve TMSS-142 and TMSS-141,!97Resolve TMSS-138
...@@ -8,6 +8,13 @@ from django.contrib.postgres.fields import ArrayField, JSONField ...@@ -8,6 +8,13 @@ from django.contrib.postgres.fields import ArrayField, JSONField
from .specification import AbstractChoice, BasicCommon, Template, NamedCommon # , <TaskBlueprint from .specification import AbstractChoice, BasicCommon, Template, NamedCommon # , <TaskBlueprint
from enum import Enum from enum import Enum
from rest_framework.serializers import HyperlinkedRelatedField from rest_framework.serializers import HyperlinkedRelatedField
from lofar.sas.tmss.tmss.exceptions import *
import json
import fastjsonschema
import jsonschema
# #
# I/O # I/O
# #
...@@ -127,7 +134,6 @@ class DataproductFeedbackTemplate(Template): ...@@ -127,7 +134,6 @@ class DataproductFeedbackTemplate(Template):
# #
# Instance Objects # Instance Objects
# #
class Subtask(BasicCommon): class Subtask(BasicCommon):
""" """
Represents a low-level task, which is an atomic unit of execution, such as running an observation, running Represents a low-level task, which is an atomic unit of execution, such as running an observation, running
...@@ -147,6 +153,21 @@ class Subtask(BasicCommon): ...@@ -147,6 +153,21 @@ class Subtask(BasicCommon):
scheduler_input_doc = JSONField(help_text='Partial specifications, as input for the scheduler.') scheduler_input_doc = JSONField(help_text='Partial specifications, as input for the scheduler.')
# resource_claim = ForeignKey("ResourceClaim", null=False, on_delete=PROTECT) # todo <-- how is this external reference supposed to work? # resource_claim = ForeignKey("ResourceClaim", null=False, on_delete=PROTECT) # todo <-- how is this external reference supposed to work?
def validate_specification_against_schema(self):
try:
# ensure the specification and schema are both valid json in the first place
spec = json.loads(self.specifications_doc) if type(self.specifications_doc) == str else self.specifications_doc
schema = json.loads(self.specifications_template.schema) if type(self.specifications_template.schema) == str else self.specifications_template.schema
jsonschema.validate(spec, schema)
except Exception as e:
raise SpecificationException(str(e))
def save(self, force_insert=False, force_update=False, using=None, update_fields=None):
'''override of normal save method, doing a validation of the specification against the schema first
:raises SpecificationException in case the specification does not validate against the schema'''
self.validate_specification_against_schema()
super().save(force_insert, force_update, using, update_fields)
class SubtaskInput(BasicCommon): class SubtaskInput(BasicCommon):
subtask = ForeignKey('Subtask', null=False, on_delete=CASCADE, help_text='Subtask to which this input specification refers.') subtask = ForeignKey('Subtask', null=False, on_delete=CASCADE, help_text='Subtask to which this input specification refers.')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment