Example #1
0
    def test_export_data_in_pg(self):
        print("\nINFO: Validate Export Data in PG...")
        restore_schema('test_export_data')
        db_pg = get_pg_conn('test_export_data')

        base_config = BaseConfiguration()
        base_config.custom_model_directories = testdata_path(MODELS_PATH)
        base_config.custom_model_directories_enabled = True

        configuration = ExportConfiguration()
        configuration.base_configuration = base_config
        configuration.dbhost = 'postgres'
        configuration.dbusr = '******'
        configuration.dbpwd = 'clave_ladm_col'
        configuration.database = 'ladm_col'
        configuration.dbschema = 'test_export_data'
        configuration.delete_data = True
        configuration.ilimodels = ';'.join([self.ladmcol_models.model(LADMNames.LADM_COL_MODEL_KEY).full_name(),
                                            self.ladmcol_models.model(LADMNames.SNR_DATA_SUPPLIES_MODEL_KEY).full_name(),
                                            self.ladmcol_models.model(LADMNames.SUPPLIES_MODEL_KEY).full_name(),
                                            self.ladmcol_models.model(LADMNames.SUPPLIES_INTEGRATION_MODEL_KEY).full_name(),
                                            self.ladmcol_models.model(LADMNames.SURVEY_MODEL_KEY).full_name()])

        exporter = iliexporter.Exporter()
        exporter.tool = DbIliMode.ili2pg
        exporter.configuration = configuration
        exporter.configuration.xtffile = os.path.join(tempfile.mkdtemp(), 'test_export_data.xtf')
        self.assertEqual(exporter.run(), iliexporter.Exporter.SUCCESS)
        self.check_export_xtf(exporter.configuration.xtffile)
        db_pg.conn.close()
Example #2
0
    def test_export_data_in_gpkg(self):
        print("\nINFO: Validate Export Data in GPKG...")
        gpkg_path = get_test_copy_path(
            'geopackage/test_export_data_ladm_v1_0.gpkg')

        base_config = BaseConfiguration()
        base_config.custom_model_directories = testdata_path(MODELS_PATH)
        base_config.custom_model_directories_enabled = True

        configuration = ExportConfiguration()
        configuration.base_configuration = base_config
        configuration.ilimodels = ';'.join([
            self.ladmcol_models.model(
                LADMNames.LADM_COL_MODEL_KEY).full_name(),
            self.ladmcol_models.model(
                LADMNames.SNR_DATA_SUPPLIES_MODEL_KEY).full_name(),
            self.ladmcol_models.model(
                LADMNames.SUPPLIES_MODEL_KEY).full_name(),
            self.ladmcol_models.model(
                LADMNames.SUPPLIES_INTEGRATION_MODEL_KEY).full_name(),
            self.ladmcol_models.model(LADMNames.SURVEY_MODEL_KEY).full_name()
        ])
        configuration.dbfile = gpkg_path

        exporter = iliexporter.Exporter()
        exporter.tool = DbIliMode.ili2gpkg
        exporter.configuration = configuration
        exporter.configuration.xtffile = os.path.join(self.base_test_path,
                                                      'test_export_data.xtf')
        # exporter.stderr.connect(self.on_stderr)
        self.assertEqual(exporter.run(), iliexporter.Exporter.SUCCESS)
        self.check_export_xtf(exporter.configuration.xtffile)
    def test_export_data_in_gpkg(self):
        print("\nINFO: Validate Export Data in GPKG...")
        gpkg_path = get_test_copy_path('geopackage/test_export_data.gpkg')

        base_config = BaseConfiguration()
        base_config.custom_model_directories = testdata_path('models/LADM_COL')
        base_config.custom_model_directories_enabled = True

        configuration = ExportConfiguration()
        configuration.base_configuration = base_config
        configuration.ilimodels = ';'.join([
            LADMNames.SUPPORTED_LADM_MODEL, LADMNames.SUPPORTED_SNR_DATA_MODEL,
            LADMNames.SUPPORTED_SUPPLIES_MODEL,
            LADMNames.SUPPORTED_SUPPLIES_INTEGRATION_MODEL,
            LADMNames.SUPPORTED_OPERATION_MODEL, LADMNames.SUPPORTED_ANT_MODEL,
            LADMNames.SUPPORTED_CADASTRAL_FORM_MODEL,
            LADMNames.SUPPORTED_VALUATION_MODEL
        ])
        configuration.dbfile = gpkg_path

        exporter = iliexporter.Exporter()
        exporter.tool = DbIliMode.ili2gpkg
        exporter.configuration = configuration
        exporter.configuration.xtffile = os.path.join(self.base_test_path,
                                                      'test_export_data.xtf')
        self.assertEqual(exporter.run(), iliexporter.Exporter.SUCCESS)
        self.check_export_xtf(exporter.configuration.xtffile)
Example #4
0
    def test_export_data_in_mssql(self):
        print("\nINFO: Validate Export Data in MS SQL Server...")

        schema = 'test_export_data'
        reset_db_mssql(schema)
        restore_schema_mssql(schema)

        db_conn = get_mssql_conn(schema)

        base_config = BaseConfiguration()
        base_config.custom_model_directories = testdata_path(MODELS_PATH)
        base_config.custom_model_directories_enabled = True

        model_list = [
            self.ladmcol_models.model(
                LADMNames.LADM_COL_MODEL_KEY).full_name(),
            self.ladmcol_models.model(
                LADMNames.SNR_DATA_SUPPLIES_MODEL_KEY).full_name(),
            self.ladmcol_models.model(
                LADMNames.SUPPLIES_MODEL_KEY).full_name(),
            self.ladmcol_models.model(
                LADMNames.SUPPLIES_INTEGRATION_MODEL_KEY).full_name(),
            self.ladmcol_models.model(LADMNames.SURVEY_MODEL_KEY).full_name()
        ]

        configuration = ExportConfiguration()
        configuration.base_configuration = base_config
        configuration.dbhost = 'mssql'
        configuration.dbusr = '******'
        configuration.dbpwd = '<YourStrong!Passw0rd>'
        configuration.dbport = '1433'
        configuration.database = schema  # use schema because delete schemas in mssql is difficult
        configuration.dbschema = schema
        configuration.db_odbc_driver = 'ODBC Driver 17 for SQL Server'
        configuration.delete_data = True
        configuration.ilimodels = ';'.join(model_list)

        exporter = iliexporter.Exporter()
        exporter.tool = DbIliMode.ili2mssql
        exporter.configuration = configuration
        exporter.configuration.xtffile = os.path.join(tempfile.mkdtemp(),
                                                      'test_export_data.xtf')
        # exporter.stderr.connect(self.on_stderr)
        self.assertEqual(exporter.run(), iliexporter.Exporter.SUCCESS)
        self.check_export_xtf(exporter.configuration.xtffile)
        db_conn.conn.close()
    def accepted(self):
        self._running_tool = True
        self.bar.clearWidgets()

        java_home_set = self.java_utils.set_java_home()
        if not java_home_set:
            message_java = QCoreApplication.translate(
                "DialogExportData",
                """Configuring Java {}...""").format(JAVA_REQUIRED_VERSION)
            self.txtStdout.setTextColor(QColor('#000000'))
            self.txtStdout.clear()
            self.txtStdout.setText(message_java)
            self.java_utils.get_java_on_demand()
            self.disable()
            return

        configuration = self.update_configuration()

        if not self.xtf_file_line_edit.validator().validate(
                configuration.xtffile, 0)[0] == QValidator.Acceptable:
            self._running_tool = False
            message_error = QCoreApplication.translate(
                "DialogExportData",
                "Please set a valid XTF file before exporting data.")
            self.txtStdout.setText(message_error)
            self.show_message(message_error, Qgis.Warning)
            self.xtf_file_line_edit.setFocus()
            return

        if not self.get_ili_models():
            self._running_tool = False
            message_error = QCoreApplication.translate(
                "DialogExportData",
                "Please set a valid schema to export. This schema does not have information to export."
            )
            self.txtStdout.setText(message_error)
            self.show_message(message_error, Qgis.Warning)
            self.export_models_list_view.setFocus()
            return

        if not configuration.iliexportmodels:
            self._running_tool = False
            message_error = QCoreApplication.translate(
                "DialogExportData",
                "Please set a model before exporting data.")
            self.txtStdout.setText(message_error)
            self.show_message(message_error, Qgis.Warning)
            self.export_models_list_view.setFocus()
            return

        # If xtf browser was opened and the file exists, the user already chose
        # to overwrite the file
        if os.path.isfile(self.xtf_file_line_edit.text().strip()
                          ) and not self.xtf_browser_was_opened:
            self.msg = QMessageBox()
            self.msg.setIcon(QMessageBox.Warning)
            self.msg.setText(
                QCoreApplication.translate(
                    "DialogExportData",
                    "{filename} already exists.\nDo you want to replace it?").
                format(filename=os.path.basename(
                    self.xtf_file_line_edit.text().strip())))
            self.msg.setWindowTitle(
                QCoreApplication.translate("DialogExportData",
                                           "Save in XTF Transfer File"))
            self.msg.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
            msg_box = self.msg.exec_()
            if msg_box == QMessageBox.No:
                self._running_tool = False
                return

        with OverrideCursor(Qt.WaitCursor):
            self.progress_bar.show()

            self.disable()
            self.txtStdout.setTextColor(QColor('#000000'))
            self.txtStdout.clear()

            exporter = iliexporter.Exporter()

            db_factory = self._dbs_supported.get_db_factory(self.db.engine)

            exporter.tool = db_factory.get_mbaker_db_ili_mode()
            exporter.configuration = configuration

            self.save_configuration(configuration)

            exporter.stdout.connect(self.print_info)
            exporter.stderr.connect(self.on_stderr)
            exporter.process_started.connect(self.on_process_started)
            exporter.process_finished.connect(self.on_process_finished)

            self.progress_bar.setValue(25)

            try:
                if exporter.run() != iliexporter.Exporter.SUCCESS:
                    self._running_tool = False
                    self.show_message(
                        QCoreApplication.translate(
                            "DialogExportData",
                            "An error occurred when exporting the data. For more information see the log..."
                        ), Qgis.Warning)
                    self.on_result.emit(
                        False
                    )  # Inform other classes that the execution was not successful
                    return
            except JavaNotFoundError:
                self._running_tool = False
                message_error_java = QCoreApplication.translate(
                    "DialogExportData",
                    "Java {} could not be found. You can configure the JAVA_HOME environment variable manually, restart QGIS and try again."
                ).format(JAVA_REQUIRED_VERSION)
                self.txtStdout.setTextColor(QColor('#000000'))
                self.txtStdout.clear()
                self.txtStdout.setText(message_error_java)
                self.show_message(message_error_java, Qgis.Warning)
                return

            self._running_tool = False
            self.buttonBox.clear()
            self.buttonBox.setEnabled(True)
            self.buttonBox.addButton(QDialogButtonBox.Close)
            self.progress_bar.setValue(100)
            self.show_message(
                QCoreApplication.translate(
                    "DialogExportData",
                    "Export of the data was successfully completed."),
                Qgis.Success)
            self.on_result.emit(
                True)  # Inform other classes that the execution was successful
Example #6
0
    def accepted(self):
        configuration = self.update_configuration()

        if not self.xtf_file_line_edit.validator().validate(
                configuration.xtffile, 0)[0] == QValidator.Acceptable:
            message_error = QCoreApplication.translate(
                "DialogExportData",
                "Please set a valid XTF file before exporting data.")
            self.txtStdout.setText(message_error)
            self.show_message(message_error, Qgis.Warning)
            self.xtf_file_line_edit.setFocus()
            return

        if not self.get_ili_models():
            message_error = QCoreApplication.translate(
                "DialogExportData",
                "Please set a valid schema to export. This schema does not have information to export."
            )
            self.txtStdout.setText(message_error)
            self.show_message(message_error, Qgis.Warning)
            self.export_models_list_view.setFocus()
            return

        if not configuration.iliexportmodels:
            message_error = QCoreApplication.translate(
                "DialogExportData",
                "Please set a model before exporting data.")
            self.txtStdout.setText(message_error)
            self.show_message(message_error, Qgis.Warning)
            self.export_models_list_view.setFocus()
            return

        # If xtf browser was opened and the file exists, the user already chose
        # to overwrite the file
        if os.path.isfile(self.xtf_file_line_edit.text().strip()
                          ) and not self.xtf_browser_was_opened:
            self.msg = QMessageBox()
            self.msg.setIcon(QMessageBox.Warning)
            self.msg.setText(
                QCoreApplication.translate(
                    "DialogExportData",
                    "{filename} already exists.\nDo you want to replace it?").
                format(filename=os.path.basename(
                    self.xtf_file_line_edit.text().strip())))
            self.msg.setWindowTitle(
                QCoreApplication.translate("DialogExportData",
                                           "Save in XTF Transfer File"))
            self.msg.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
            msg_box = self.msg.exec_()
            if msg_box == QMessageBox.No:
                return

        with OverrideCursor(Qt.WaitCursor):
            self.progress_bar.show()
            self.progress_bar.setValue(0)

            self.disable()
            self.txtStdout.setTextColor(QColor('#000000'))
            self.txtStdout.clear()

            exporter = iliexporter.Exporter()

            item_db = self._conf_db.get_db_items()[self.db.mode]

            exporter.tool = item_db.get_mbaker_db_ili_mode()
            exporter.configuration = configuration

            self.save_configuration(configuration)

            exporter.stdout.connect(self.print_info)
            exporter.stderr.connect(self.on_stderr)
            exporter.process_started.connect(self.on_process_started)
            exporter.process_finished.connect(self.on_process_finished)

            self.progress_bar.setValue(25)

            try:
                if exporter.run() != iliexporter.Exporter.SUCCESS:
                    self.enable()
                    self.progress_bar.hide()
                    self.show_message(
                        QCoreApplication.translate(
                            "DialogExportData",
                            "An error occurred when exporting the data. For more information see the log..."
                        ), Qgis.Warning)
                    return
            except JavaNotFoundError:
                # Set JAVA PATH
                get_java_path_dlg = GetJavaPathDialog()
                get_java_path_dlg.setModal(True)
                if get_java_path_dlg.exec_():
                    configuration = self.update_configuration()

                if not get_java_path_from_qgis_model_baker():
                    message_error_java = QCoreApplication.translate(
                        "DialogExportData",
                        """Java could not be found. You can configure the JAVA_HOME environment variable, restart QGIS and try again."""
                    )
                    self.txtStdout.setTextColor(QColor('#000000'))
                    self.txtStdout.clear()
                    self.txtStdout.setText(message_error_java)
                    self.show_message(message_error_java, Qgis.Warning)
                self.enable()
                self.progress_bar.hide()
                return

            self.buttonBox.clear()
            self.buttonBox.setEnabled(True)
            self.buttonBox.addButton(QDialogButtonBox.Close)
            self.progress_bar.setValue(100)
            self.show_message(
                QCoreApplication.translate(
                    "DialogExportData",
                    "Export of the data was successfully completed."),
                Qgis.Success)
Example #7
0
    def export_baskets(self):
        java_home_set = self.java_dependency.set_java_home()
        if not java_home_set:
            message_java = QCoreApplication.translate(
                "BasketExporter",
                """Configuring Java {}...""").format(JAVA_REQUIRED_VERSION)
            self.logger.status(message_java)
            self.java_dependency.get_java_on_demand()
            return

        self.base_configuration = BaseConfiguration()
        self.ilicache = IliCache(self.base_configuration)
        self.ilicache.refresh()

        db_factory = self._dbs_supported.get_db_factory(self._db.engine)
        self.configuration = ExportConfiguration()
        db_factory.set_ili2db_configuration_params(self._db.dict_conn_params,
                                                   self.configuration)
        self.configuration.with_exporttid = True
        full_java_exe_path = JavaDependency.get_full_java_exe_path()
        if full_java_exe_path:
            self.base_configuration.java_path = full_java_exe_path

        # Check custom model directories
        if QSettings().value(
                'Asistente-LADM-COL/models/custom_model_directories_is_checked',
                DEFAULT_USE_CUSTOM_MODELS,
                type=bool):
            custom_model_directories = QSettings().value(
                'Asistente-LADM-COL/models/custom_models', DEFAULT_MODELS_DIR)
            if not custom_model_directories:
                self.base_configuration.custom_model_directories_enabled = False
            else:
                self.base_configuration.custom_model_directories = custom_model_directories
                self.base_configuration.custom_model_directories_enabled = True

        self.configuration.base_configuration = self.base_configuration
        if self.get_ili_models():
            self.configuration.ilimodels = ';'.join(self.get_ili_models())

        self.exporter = iliexporter.Exporter()
        self.exporter.tool = db_factory.get_model_baker_db_ili_mode()
        self.exporter.process_started.connect(self.on_process_started)
        self.exporter.stderr.connect(self.on_stderr)
        #self.exporter.process_finished.connect(self.on_process_finished)

        res = dict()
        count = 0
        total = len(self._basket_dict)

        with OverrideCursor(Qt.WaitCursor):
            for basket, name in self._basket_dict.items():
                self.log = ''
                self.configuration.xtffile = os.path.join(
                    self._export_dir, "{}.xtf".format(name))
                self.configuration.baskets = basket
                self.exporter.configuration = self.configuration

                try:
                    if self.exporter.run() != iliexporter.Exporter.SUCCESS:
                        msg = QCoreApplication.translate(
                            "BasketExporter",
                            "An error occurred when exporting the data for '{}' (check the QGIS log panel)."
                        ).format(name)
                        res[basket] = (False, msg)
                        QgsMessageLog.logMessage(
                            self.log,
                            QCoreApplication.translate(
                                "BasketExporter", "Allocate to coordinators"),
                            Qgis.Critical)
                    else:
                        res[basket] = (True,
                                       QCoreApplication.translate(
                                           "BasketExporter",
                                           "XTF export for '{}' successful!").
                                       format(name))
                except JavaNotFoundError:
                    msg = QCoreApplication.translate(
                        "BasketExporter",
                        "Java {} could not be found. You can configure the JAVA_HOME environment variable manually, restart QGIS and try again."
                    ).format(JAVA_REQUIRED_VERSION)
                    res[basket] = (False, msg)

                count += 1
                self.total_progress_updated.emit(count / total * 100)

        return res