コード例 #1
0
    def validate(self) -> None:
        exceptions: List[ValidationError] = list()
        layer_id: Optional[int] = self._properties.get("layer")
        short_descr: str = self._properties.get("short_descr", "")

        # Validate/populate model exists
        self._model = AnnotationDAO.find_by_id(self._model_id)
        if not self._model:
            raise AnnotationNotFoundError()
        # Validate/populate layer exists
        if layer_id:
            annotation_layer = AnnotationLayerDAO.find_by_id(layer_id)
            if not annotation_layer:
                raise AnnotationLayerNotFoundError()
            self._properties["layer"] = annotation_layer

            # Validate short descr uniqueness on this layer
            if not AnnotationDAO.validate_update_uniqueness(
                layer_id, short_descr, annotation_id=self._model_id,
            ):
                exceptions.append(AnnotationUniquenessValidationError())
        else:
            self._properties["layer"] = self._model.layer

        # validate date time sanity
        start_dttm: Optional[datetime] = self._properties.get("start_dttm")
        end_dttm: Optional[datetime] = self._properties.get("end_dttm")

        if start_dttm and end_dttm and end_dttm < start_dttm:
            exceptions.append(AnnotationDatesValidationError())

        if exceptions:
            exception = AnnotationInvalidError()
            exception.add_list(exceptions)
            raise exception
コード例 #2
0
ファイル: bulk_delete.py プロジェクト: yike5460/superset
 def run(self) -> None:
     self.validate()
     try:
         AnnotationDAO.bulk_delete(self._models)
         return None
     except DAODeleteFailedError as ex:
         logger.exception(ex.exception)
         raise AnnotationBulkDeleteFailedError()
コード例 #3
0
ファイル: create.py プロジェクト: EBoisseauSierra/superset
    def validate(self) -> None:
        exceptions: List[ValidationError] = []
        layer_id: Optional[int] = self._properties.get("layer")
        start_dttm: Optional[datetime] = self._properties.get("start_dttm")
        end_dttm: Optional[datetime] = self._properties.get("end_dttm")
        short_descr = self._properties.get("short_descr", "")

        # Validate/populate model exists
        if not layer_id and not isinstance(layer_id, int):
            raise AnnotationLayerNotFoundError()
        annotation_layer = AnnotationLayerDAO.find_by_id(layer_id)
        if not annotation_layer:
            raise AnnotationLayerNotFoundError()
        self._properties["layer"] = annotation_layer

        # Validate short descr uniqueness on this layer
        if not AnnotationDAO.validate_update_uniqueness(layer_id, short_descr):
            exceptions.append(AnnotationUniquenessValidationError())

        # validate date time sanity
        if start_dttm and end_dttm and end_dttm < start_dttm:
            exceptions.append(AnnotationDatesValidationError)

        if exceptions:
            exception = AnnotationInvalidError()
            exception.add_list(exceptions)
            raise exception
コード例 #4
0
ファイル: update.py プロジェクト: ws1993/superset
 def run(self) -> Model:
     self.validate()
     try:
         annotation = AnnotationDAO.update(self._model, self._properties)
     except DAOUpdateFailedError as ex:
         logger.exception(ex.exception)
         raise AnnotationUpdateFailedError() from ex
     return annotation
コード例 #5
0
ファイル: delete.py プロジェクト: EBoisseauSierra/superset
 def run(self) -> Model:
     self.validate()
     try:
         annotation = AnnotationDAO.delete(self._model)
     except DAODeleteFailedError as ex:
         logger.exception(ex.exception)
         raise AnnotationDeleteFailedError() from ex
     return annotation
コード例 #6
0
 def run(self) -> Model:
     self.validate()
     try:
         annotation = AnnotationDAO.create(self._properties)
     except DAOCreateFailedError as ex:
         logger.exception(ex.exception)
         raise AnnotationCreateFailedError()
     return annotation
コード例 #7
0
ファイル: bulk_delete.py プロジェクト: yike5460/superset
 def validate(self) -> None:
     # Validate/populate model exists
     self._models = AnnotationDAO.find_by_ids(self._model_ids)
     if not self._models or len(self._models) != len(self._model_ids):
         raise AnnotationNotFoundError()
コード例 #8
0
ファイル: delete.py プロジェクト: EBoisseauSierra/superset
 def validate(self) -> None:
     # Validate/populate model exists
     self._model = AnnotationDAO.find_by_id(self._model_id)
     if not self._model:
         raise AnnotationNotFoundError()