Exemple #1
0
 def test_constructor(self):
     """Runs class constructor checks."""
     # name and set of parameters are mandatory, even if they're invalid
     self.assertRaises(Exception, DsgToolsProcessingModel)
     self.assertRaises(Exception, DsgToolsProcessingModel, parameters={})
     self.assertRaises(Exception, DsgToolsProcessingModel, name="")
     model = DsgToolsProcessingModel({}, "Invalid model")
     self.assertFalse(model.isValid())
     self.assertEquals(model.name(), "Invalid model")
Exemple #2
0
 def hasInvalidModel(self):
     """
     Checks if any of the nested models is invalid.
     :return: (bool) if there are invalid models.
     """
     models = dict()
     for modelName, modelParam in self._param["models"].items():
         model = DsgToolsProcessingModel(modelParam, modelName)
         if not model.isValid():
             return True
     return False
Exemple #3
0
 def invalidModels(self):
     """
     Returns all valid models from workflow parameters.
     :return: (dict) models maps invalid models to their invalidation reason.
     """
     models = dict()
     self._multiStepFeedback = QgsProcessingMultiStepFeedback(
         len(self._param["models"]), self.feedback)
     self._multiStepFeedback.setCurrentStep(0)
     for modelName, modelParam in self._param["models"].items():
         model = DsgToolsProcessingModel(modelParam,
                                         modelName,
                                         feedback=self._multiStepFeedback)
         if not model.isValid():
             models[modelName] = model.validateParameters(modelParam)
     return models
Exemple #4
0
 def validModels(self):
     """
     Returns all valid models from workflow parameters.
     :return: (dict) models maps to valid and invalid models.
     """
     models = dict()
     self._multiStepFeedback = QgsProcessingMultiStepFeedback(
         len(self._param["models"]), self.feedback)
     self._multiStepFeedback.setCurrentStep(0)
     for idx, (modelName,
               modelParam) in enumerate(self._param["models"].items()):
         model = DsgToolsProcessingModel(modelParam,
                                         modelName,
                                         feedback=self._multiStepFeedback)
         if model.isValid():
             models[modelName] = model
         self._modelOrderMap[modelName] = idx
     return models
Exemple #5
0
 def models(self):
     """
     Model parameters defined to run in this workflow.
     :return: (dict) models maps to valid and invalid models.
     """
     models = {"valid": dict(), "invalid": dict()}
     self._multiStepFeedback = QgsProcessingMultiStepFeedback(
         len(self._param["models"]), self.feedback)
     self._multiStepFeedback.setCurrentStep(0)
     for modelName, modelParam in self._param["models"].items():
         model = DsgToolsProcessingModel(modelParam,
                                         modelName,
                                         feedback=self._multiStepFeedback)
         if not model.isValid():
             models["invalid"][modelName] = model.validateParameters(
                 modelParam)
         else:
             models["valid"][modelName] = model
     return models
Exemple #6
0
 def validateParameters(self, parameters):
     """
     Validates a set of parameters for a valid Workflow.
     :param parameters: (dict) map of workflow attributes to be validated.
     :return: (str) invalidation reason.
     """
     if "displayName" not in parameters or not parameters["displayName"]:
         # this is not a mandatory item, but it defaults to a value
         parameters["displayName"] = self.tr("DSGTools Validation Workflow")
     if "models" not in parameters or not parameters["models"]:
         return self.tr("Workflow seems to have no models associated with it.")
     for modelName, modelParam in parameters["models"].items():
         model=DsgToolsProcessingModel(modelParam, modelName)
         if not model.isValid():
             return self.tr("Model {model} is invalid: '{reason}'.").format(
                 model=modelName, reason=model.validateParameters(modelParam)
             )
     # if "flagLayer" not in parameters or not parameters["flagLayer"]:
     #     self.tr("No flag layer was provided.")
     # if "historyLayer" not in parameters or not parameters["historyLayer"]:
     #     self.tr("No history layer was provided.")
     return ""