diff --git a/LTA/sip/lib/siplib.py b/LTA/sip/lib/siplib.py index af6c39adf031d466fdcbb4c8d7e4e06ca46ee3c3..ffc620a2d785c8e8534c0dac70fd102052b4ee15 100644 --- a/LTA/sip/lib/siplib.py +++ b/LTA/sip/lib/siplib.py @@ -1421,7 +1421,7 @@ class Sip(object): observingmode, description, process_map, - ): + return_xml=True): up = ltasip.UnspecifiedProcess( observingMode=observingmode, @@ -1429,22 +1429,23 @@ class Sip(object): **process_map.get_dict() ) self.__sip.unspecifiedProcess.append(up) - - return self.get_prettyxml() + if return_xml: + return self.get_prettyxml() def add_parset(self, identifier, - contents): + contents, + return_xml=True): self.__sip.parset.append(ltasip.Parset( identifier=identifier._get_pyxb_identifier(suppress_warning=True), contents=contents )) + if return_xml: + return self.get_prettyxml() - return self.get_prettyxml() - - def add_related_dataproduct_with_history(self, relateddataproduct_sip): + def add_related_dataproduct_with_history(self, relateddataproduct_sip, return_xml=True): # add the dataproduct described by the SIP (if not there) if not any(x.dataProductIdentifier.identifier == relateddataproduct_sip.__sip.dataProduct.dataProductIdentifier.identifier for x in self.__sip.relatedDataProduct): self.__sip.relatedDataProduct.append(relateddataproduct_sip.__sip.dataProduct) @@ -1475,7 +1476,8 @@ class Sip(object): for par in relateddataproduct_sip.__sip.parset: if not any(x.identifier.identifier == par.identifier.identifier for x in self.__sip.parset): self.__sip.parset.append(par) - return self.get_prettyxml() + if return_xml: + return self.get_prettyxml() def get_dataproduct_identifier(self): diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/adapters/sip.py b/SAS/TMSS/backend/src/tmss/tmssapp/adapters/sip.py index fd30e6699297261f9de5a820c35333e998aa5d32..5432e71855e37d17f0ddb395c0968f6ee1c9f9e6 100644 --- a/SAS/TMSS/backend/src/tmss/tmssapp/adapters/sip.py +++ b/SAS/TMSS/backend/src/tmss/tmssapp/adapters/sip.py @@ -8,6 +8,7 @@ import uuid import logging import isodate import datetime +from functools import lru_cache logger = logging.getLogger(__name__) mapping_antennaset_type_TMSS_2_SIP = { @@ -116,9 +117,9 @@ def add_subbtask_and_input_dataproducts_to_sip(subtask: Subtask, sip: siplib.Sip logger.info("Adding subtask id %s of type %s to sip." % (subtask.id, subtask.specifications_template.type.value)) sip_subtask = create_sip_representation_for_subtask(subtask) if isinstance(sip_subtask, siplib.Observation): - sip.add_observation(observation=sip_subtask) + sip.add_observation(observation=sip_subtask, return_xml=False) else: - sip.add_pipelinerun(pipeline=sip_subtask) + sip.add_pipelinerun(pipeline=sip_subtask, return_xml=False) for input in subtask.inputs.all(): logger.info("Adding %d related input dataproducts for subtask id %s to sip." % (input.dataproducts.count(), subtask.id)) for dataproduct in input.dataproducts.all(): @@ -272,6 +273,7 @@ def create_sip_representation_for_subtask(subtask: Subtask): raise TMSSException("The Subtask type %s cannot be represented in a SIP" % subtask.specifications_template.type.value) +@lru_cache(maxsize=256, typed=False) def create_sip_representation_for_dataproduct(dataproduct: Dataproduct): """ Extract info from the TMSS dataproduct and creates a SIP object representation @@ -548,7 +550,7 @@ def recursively_add_subbtask_and_input_dataproducts_to_sip(subtask: Subtask, sip recursively_add_subbtask_and_input_dataproducts_to_sip(predecessor, sip) -def generate_sip_for_dataproduct(dataproduct: Dataproduct) -> siplib.Sip: +def generate_sip_for_dataproduct(dataproduct): """ generate_sip_from_dataproduct :param dataproduct: The dataproduct to create the SIP for diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/models/scheduling.py b/SAS/TMSS/backend/src/tmss/tmssapp/models/scheduling.py index 9f1dc953a20a865a13c4fefb49f2c80bcb072b32..217a9771841cba96801c56c0a2bd5316468ef18a 100644 --- a/SAS/TMSS/backend/src/tmss/tmssapp/models/scheduling.py +++ b/SAS/TMSS/backend/src/tmss/tmssapp/models/scheduling.py @@ -475,6 +475,8 @@ class Dataproduct(BasicCommon, TemplateSchemaMixin): self.annotate_validate_add_defaults_to_doc_using_template('feedback_doc', 'feedback_template') SIPidentifier.assign_new_id_to_model(self) + from lofar.sas.tmss.tmss.tmssapp.adapters.sip import create_sip_representation_for_dataproduct + create_sip_representation_for_dataproduct.cache_clear() super().save(force_insert, force_update, using, update_fields) @property