Commit b66db243 authored by Jorrit Schaap's avatar Jorrit Schaap

TMSS-153: added little factory to pick the proper conversion method based on...

TMSS-153: added little factory to pick the proper conversion method based on subtask spec template name
parent cd57994d
......@@ -4,3 +4,6 @@ class TMSSException(Exception):
class SpecificationException(TMSSException):
pass
class ConversionException(TMSSException):
pass
......@@ -21,8 +21,9 @@ from lofar.sas.tmss.tmss.tmssapp import models
from lofar.parameterset import parameterset
from lofar.common.datetimeutils import formatDatetime
from lofar.common.json_utils import add_defaults_to_json_object_for_schema
from lofar.sas.tmss.tmss.exceptions import *
def convert_to_parset(subtask: models.Subtask) -> parameterset:
def _convert_to_parset_for_observationcontrol_schema(subtask: models.Subtask) -> parameterset:
# make sure the spec is complete (including all non-filled in properties with default)
spec = add_defaults_to_json_object_for_schema(subtask.specifications_doc, subtask.specifications_template.schema)
......@@ -93,3 +94,17 @@ def convert_to_parset(subtask: models.Subtask) -> parameterset:
parset = parameterset(parset)
return parset
# dict to store conversion methods based on subtask.specifications_template.name
_convertors = {'observationcontrol schema': _convert_to_parset_for_observationcontrol_schema }
def convert_to_parset(subtask: models.Subtask) -> parameterset:
'''
Convert the specifications in the subtask to a LOFAR parset for MAC/COBALT
:raises ConversionException if no proper conversion is available.
'''
try:
convertor = _convertors[subtask.specifications_template.name]
return convertor(subtask)
except KeyError:
raise ConversionException("Cannot convert subtask id=%d to parset. No conversion routine available for specifications_template='%s'",
(subtask.id, subtask.specifications_template.name))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment