Exemple #1
0
    def test_import_schema_in_gpkg(self):
        print("\nINFO: Validate Import Schema in GPKG...")
        base_config = BaseConfiguration()
        base_config.custom_model_directories = testdata_path(MODELS_PATH)
        base_config.custom_model_directories_enabled = True

        configuration = SchemaImportConfiguration()
        configuration.base_configuration = base_config
        configuration.tool = DbIliMode.ili2gpkg
        configuration.dbfile = os.path.join(self.base_test_path, 'tmp_import_schema.gpkg')
        configuration.tomlfile = TOML_FILE_DIR
        configuration.srs_code = 3116
        configuration.inheritance = ILI2DBNames.DEFAULT_INHERITANCE
        configuration.create_basket_col = ILI2DBNames.CREATE_BASKET_COL
        configuration.create_import_tid = ILI2DBNames.CREATE_IMPORT_TID
        configuration.stroke_arcs = ILI2DBNames.STROKE_ARCS
        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(),
                                            self.ladmcol_models.model(LADMNames.CADASTRAL_CARTOGRAPHY_MODEL_KEY).full_name(),
                                            self.ladmcol_models.model(LADMNames.VALUATION_MODEL_KEY).full_name()])

        importer = iliimporter.Importer()
        importer.tool = DbIliMode.ili2gpkg
        importer.configuration = configuration

        self.assertEqual(importer.run(), iliimporter.Importer.SUCCESS)

        config_manager = GpkgCommandConfigManager(importer.configuration)
        generator = Generator(DbIliMode.ili2gpkg, config_manager.get_uri(), configuration.inheritance)

        available_layers = generator.layers()
        self.assertEqual(len(available_layers), 184)
Exemple #2
0
    def test_import_data_in_mssql(self):
        print("\nINFO: Validate Import Data in MS SQL Server...")

        schema = 'test_ladm_col'
        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 = ImportDataConfiguration()
        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)

        configuration.inheritance = ILI2DBNames.DEFAULT_INHERITANCE

        configuration.create_basket_col = ILI2DBNames.CREATE_BASKET_COL
        configuration.create_import_tid = ILI2DBNames.CREATE_IMPORT_TID
        configuration.stroke_arcs = ILI2DBNames.STROKE_ARCS

        importer = iliimporter.Importer(dataImport=True)
        importer.tool = DbIliMode.ili2mssql
        importer.configuration = configuration
        importer.configuration.xtffile = testdata_path('xtf/test_ladm_col_queries_v1_0.xtf')
        self.assertEqual(importer.run(), iliimporter.Importer.SUCCESS)

        generator = Generator(DbIliMode.ili2mssql,
                              'DRIVER={{ODBC Driver 17 for SQL Server}};SERVER={host},1433;DATABASE={db};UID={user};PWD={pwd}'
                              .format(db=configuration.database, user=configuration.dbusr, pwd=configuration.dbpwd,
                                      host=configuration.dbhost, port=configuration.dbport), configuration.inheritance,
                              importer.configuration.dbschema)

        available_layers = generator.layers()
        self.assertEqual(len(available_layers), 156)

        res, code, msg = db_conn.test_connection()
        self.assertTrue(res, msg)
        test_layer = self.app.core.get_layer(db_conn, db_conn.names.LC_BOUNDARY_POINT_T, load=True)

        self.assertEqual(test_layer.featureCount(), 390)
        db_conn.conn.close()
Exemple #3
0
    def test_import_schema_in_mssql(self):
        schema = 'test_import_schema'
        reset_db_mssql(schema)

        print("\nINFO: Validate Import Schema in MS SQL Server")
        base_config = BaseConfiguration()
        base_config.custom_model_directories = testdata_path(
            'xtf') + ';' + testdata_path(MODELS_PATH)
        base_config.custom_model_directories_enabled = True

        configuration = SchemaImportConfiguration()
        configuration.base_configuration = base_config
        configuration.tool = DbIliMode.ili2mssql
        configuration.dbhost = 'mssql'
        configuration.dbusr = '******'
        configuration.dbpwd = '<YourStrong!Passw0rd>'
        configuration.dbport = '1433'
        configuration.database = schema
        configuration.dbschema = schema
        configuration.db_odbc_driver = 'ODBC Driver 17 for SQL Server'

        configuration.tomlfile = TOML_FILE_DIR
        configuration.epsg = 9377
        configuration.inheritance = ILI2DBNames.DEFAULT_INHERITANCE
        configuration.create_basket_col = ILI2DBNames.CREATE_BASKET_COL
        configuration.create_import_tid = ILI2DBNames.CREATE_IMPORT_TID
        configuration.stroke_arcs = ILI2DBNames.STROKE_ARCS
        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()
        ])

        importer = iliimporter.Importer()
        importer.tool = DbIliMode.ili2mssql
        importer.configuration = configuration
        # importer.stderr.connect(self.on_stderr)
        self.assertEqual(importer.run(), iliimporter.Importer.SUCCESS)

        generator = Generator(
            DbIliMode.ili2mssql,
            'DRIVER={{ODBC Driver 17 for SQL Server}};SERVER={host},1433;DATABASE={db};UID={user};PWD={pwd}'
            .format(db=configuration.database,
                    user=configuration.dbusr,
                    pwd=configuration.dbpwd,
                    host=configuration.dbhost,
                    port=configuration.dbport), configuration.inheritance,
            importer.configuration.dbschema)

        available_layers = generator.layers()
        self.assertEqual(len(available_layers), 156)
Exemple #4
0
    def test_import_data_in_gpkg(self):
        print("\nINFO: Validate Import Data in GPKG...")

        gpkg_path = get_test_copy_path(
            'geopackage/test_import_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 = ImportDataConfiguration()
        configuration.base_configuration = base_config

        configuration.tool = DbIliMode.ili2gpkg
        configuration.dbfile = gpkg_path
        configuration.srs_auth = DEFAULT_SRS_AUTH
        configuration.srs_code = DEFAULT_SRS_CODE
        configuration.inheritance = ILI2DBNames.DEFAULT_INHERITANCE
        configuration.create_basket_col = ILI2DBNames.CREATE_BASKET_COL
        configuration.create_import_tid = ILI2DBNames.CREATE_IMPORT_TID
        configuration.stroke_arcs = ILI2DBNames.STROKE_ARCS
        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()
        ])
        importer = iliimporter.Importer(dataImport=True)
        importer.tool = DbIliMode.ili2gpkg
        importer.configuration = configuration
        importer.configuration.xtffile = testdata_path(
            'xtf/test_ladm_col_queries_v1_0.xtf')
        # importer.stderr.connect(self.on_stderr)
        self.assertEqual(importer.run(), iliimporter.Importer.SUCCESS)

        config_manager = GpkgCommandConfigManager(importer.configuration)
        generator = Generator(DbIliMode.ili2gpkg, config_manager.get_uri(),
                              configuration.inheritance)

        available_layers = generator.layers()
        self.assertEqual(len(available_layers), 156)

        db_gpkg = get_gpkg_conn_from_path(config_manager.get_uri())
        res, code, msg = db_gpkg.test_connection()
        self.assertTrue(res, msg)
        test_layer = self.app.core.get_layer(db_gpkg,
                                             db_gpkg.names.LC_BOUNDARY_POINT_T,
                                             load=True)
        self.assertEqual(test_layer.featureCount(), 390)
        db_gpkg.conn.close()
    def test_import_data_in_pg(self):
        print("\nINFO: Validate Import Data in PG...")

        restore_schema('test_import_data')
        db_pg = get_pg_conn('test_import_data')

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

        configuration = ImportDataConfiguration()
        configuration.base_configuration = base_config
        configuration.dbhost = 'postgres'
        configuration.dbusr = '******'
        configuration.dbpwd = 'clave_ladm_col'
        configuration.database = 'ladm_col'
        configuration.epsg = DEFAULT_EPSG
        configuration.inheritance = LADMNames.DEFAULT_INHERITANCE
        configuration.create_basket_col = LADMNames.CREATE_BASKET_COL
        configuration.create_import_tid = LADMNames.CREATE_IMPORT_TID
        configuration.stroke_arcs = LADMNames.STROKE_ARCS
        configuration.dbschema = 'test_import_data'
        configuration.delete_data = True
        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
        ])

        importer = iliimporter.Importer(dataImport=True)
        importer.tool = DbIliMode.ili2pg
        importer.configuration = configuration
        importer.configuration.xtffile = testdata_path(
            'xtf/test_ladm_col_queries_v2.9.6.xtf')
        self.assertEqual(importer.run(), iliimporter.Importer.SUCCESS)

        generator = Generator(
            DbIliMode.ili2pg, 'dbname={} user={} password={} host={}'.format(
                configuration.database, configuration.dbusr,
                configuration.dbpwd, configuration.dbhost),
            configuration.inheritance, importer.configuration.dbschema)

        available_layers = generator.layers()
        self.assertEqual(len(available_layers), 189)

        res, code, msg = db_pg.test_connection()
        self.assertTrue(res, msg)
        test_layer = self.qgis_utils.get_layer(db_pg,
                                               db_pg.names.OP_BOUNDARY_POINT_T,
                                               load=True)

        self.assertEqual(test_layer.featureCount(), 390)
        db_pg.conn.close()
Exemple #6
0
    def test_import_data_in_pg(self):
        print("\nINFO: Validate Import Data in PG...")

        restore_schema('test_import_data')
        db_pg = get_pg_conn('test_import_data')

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

        configuration = ImportDataConfiguration()
        configuration.base_configuration = base_config
        configuration.dbhost = 'postgres'
        configuration.dbusr = '******'
        configuration.dbpwd = 'clave_ladm_col'
        configuration.database = 'ladm_col'
        configuration.srs_auth = DEFAULT_SRS_AUTH
        configuration.srs_code = DEFAULT_SRS_CODE
        configuration.inheritance = ILI2DBNames.DEFAULT_INHERITANCE
        configuration.create_basket_col = ILI2DBNames.CREATE_BASKET_COL
        configuration.create_import_tid = ILI2DBNames.CREATE_IMPORT_TID
        configuration.stroke_arcs = ILI2DBNames.STROKE_ARCS
        configuration.dbschema = 'test_import_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()])

        importer = iliimporter.Importer(dataImport=True)
        importer.tool = DbIliMode.ili2pg
        importer.configuration = configuration
        importer.configuration.xtffile = testdata_path('xtf/test_ladm_col_queries_v1_0.xtf')
        self.assertEqual(importer.run(), iliimporter.Importer.SUCCESS)

        generator = Generator(
            DbIliMode.ili2pg,
            'dbname={} user={} password={} host={}'.format(configuration.database, configuration.dbusr,
                                                           configuration.dbpwd, configuration.dbhost),
            configuration.inheritance,
            importer.configuration.dbschema)

        available_layers = generator.layers()
        self.assertEqual(len(available_layers), 156)

        res, code, msg = db_pg.test_connection()
        self.assertTrue(res, msg)
        test_layer = self.app.core.get_layer(db_pg, db_pg.names.LC_BOUNDARY_POINT_T, load=True)

        self.assertEqual(test_layer.featureCount(), 390)
        db_pg.conn.close()
Exemple #7
0
    def test_import_schema_in_pg(self):
        print("\nINFO: Validate Import Schema in PG...")
        base_config = BaseConfiguration()
        base_config.custom_model_directories = testdata_path(
            'xtf') + ';' + testdata_path(MODELS_PATH)
        base_config.custom_model_directories_enabled = True

        configuration = SchemaImportConfiguration()
        configuration.base_configuration = base_config
        configuration.tool = DbIliMode.ili2pg
        configuration.dbhost = 'postgres'
        configuration.dbusr = '******'
        configuration.dbpwd = 'clave_ladm_col'
        configuration.database = 'ladm_col'
        configuration.dbschema = 'test_import_schema'
        configuration.tomlfile = TOML_FILE_DIR
        configuration.srs_code = 3116
        configuration.inheritance = ILI2DBNames.DEFAULT_INHERITANCE
        configuration.create_basket_col = ILI2DBNames.CREATE_BASKET_COL
        configuration.create_import_tid = ILI2DBNames.CREATE_IMPORT_TID
        configuration.stroke_arcs = ILI2DBNames.STROKE_ARCS
        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(),
            self.ladmcol_models.model(
                LADMNames.CADASTRAL_CARTOGRAPHY_MODEL_KEY).full_name(),
            self.ladmcol_models.model(
                LADMNames.VALUATION_MODEL_KEY).full_name()
        ])

        importer = iliimporter.Importer()
        importer.tool = DbIliMode.ili2pg
        importer.configuration = configuration
        # importer.stderr.connect(self.on_stderr)
        self.assertEqual(importer.run(), iliimporter.Importer.SUCCESS)

        generator = Generator(
            DbIliMode.ili2pg, 'dbname={} user={} password={} host={}'.format(
                configuration.database, configuration.dbusr,
                configuration.dbpwd, configuration.dbhost),
            configuration.inheritance, importer.configuration.dbschema)

        available_layers = generator.layers()
        self.assertEqual(len(available_layers), 184)
    def test_import_data_in_gpkg(self):
        print("\nINFO: Validate Import Data in GPKG...")

        gpkg_path = get_test_copy_path('geopackage/test_import_data.gpkg')

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

        configuration = ImportDataConfiguration()
        configuration.base_configuration = base_config

        configuration.tool = DbIliMode.ili2gpkg
        configuration.dbfile = gpkg_path
        configuration.epsg = DEFAULT_EPSG
        configuration.inheritance = LADMNames.DEFAULT_INHERITANCE
        configuration.create_basket_col = LADMNames.CREATE_BASKET_COL
        configuration.create_import_tid = LADMNames.CREATE_IMPORT_TID
        configuration.stroke_arcs = LADMNames.STROKE_ARCS
        configuration.delete_data = True
        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
        ])
        importer = iliimporter.Importer(dataImport=True)
        importer.tool = DbIliMode.ili2gpkg
        importer.configuration = configuration
        importer.configuration.xtffile = testdata_path(
            'xtf/test_ladm_col_queries_v2.9.6.xtf')
        self.assertEqual(importer.run(), iliimporter.Importer.SUCCESS)

        config_manager = GpkgCommandConfigManager(importer.configuration)
        generator = Generator(DbIliMode.ili2gpkg, config_manager.get_uri(),
                              configuration.inheritance)

        available_layers = generator.layers()
        self.assertEqual(len(available_layers), 189)

        db_gpkg = get_gpkg_conn_from_path(config_manager.get_uri())
        res, code, msg = db_gpkg.test_connection()
        self.assertTrue(res, msg)
        test_layer = self.qgis_utils.get_layer(
            db_gpkg, db_gpkg.names.OP_BOUNDARY_POINT_T, load=True)
        self.assertEqual(test_layer.featureCount(), 390)
        db_gpkg.conn.close()
    def test_import_schema_in_pg(self):
        print("\nINFO: Validate Import Schema in PG...")
        base_config = BaseConfiguration()
        base_config.custom_model_directories = testdata_path(
            'xtf') + ';' + testdata_path('models/LADM_COL')
        base_config.custom_model_directories_enabled = True

        configuration = SchemaImportConfiguration()
        configuration.base_configuration = base_config
        configuration.tool = DbIliMode.ili2pg
        configuration.dbhost = 'postgres'
        configuration.dbusr = '******'
        configuration.dbpwd = 'clave_ladm_col'
        configuration.database = 'ladm_col'
        configuration.dbschema = 'test_import_schema'
        configuration.tomlfile = TOML_FILE_DIR
        configuration.epsg = DEFAULT_EPSG
        configuration.inheritance = LADMNames.DEFAULT_INHERITANCE
        configuration.create_basket_col = LADMNames.CREATE_BASKET_COL
        configuration.create_import_tid = LADMNames.CREATE_IMPORT_TID
        configuration.stroke_arcs = LADMNames.STROKE_ARCS
        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_REFERENCE_CARTOGRAPHY,
            LADMNames.SUPPORTED_VALUATION_MODEL
        ])

        importer = iliimporter.Importer()
        importer.tool = DbIliMode.ili2pg
        importer.configuration = configuration

        self.assertEqual(importer.run(), iliimporter.Importer.SUCCESS)

        generator = Generator(
            DbIliMode.ili2pg, 'dbname={} user={} password={} host={}'.format(
                configuration.database, configuration.dbusr,
                configuration.dbpwd, configuration.dbhost),
            configuration.inheritance, importer.configuration.dbschema)

        available_layers = generator.layers()
        self.assertEqual(len(available_layers), 207)
    def test_import_schema_in_gpkg(self):
        print("\nINFO: Validate Import Schema in GPKG...")
        base_config = BaseConfiguration()
        base_config.custom_model_directories = testdata_path('models/LADM_COL')
        base_config.custom_model_directories_enabled = True

        configuration = SchemaImportConfiguration()
        configuration.base_configuration = base_config
        configuration.tool = DbIliMode.ili2gpkg
        configuration.dbfile = os.path.join(self.base_test_path,
                                            'tmp_import_schema.gpkg')
        configuration.tomlfile = TOML_FILE_DIR
        configuration.epsg = DEFAULT_EPSG
        configuration.inheritance = LADMNames.DEFAULT_INHERITANCE
        configuration.create_basket_col = LADMNames.CREATE_BASKET_COL
        configuration.create_import_tid = LADMNames.CREATE_IMPORT_TID
        configuration.stroke_arcs = LADMNames.STROKE_ARCS
        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_REFERENCE_CARTOGRAPHY,
            LADMNames.SUPPORTED_VALUATION_MODEL
        ])

        importer = iliimporter.Importer()
        importer.tool = DbIliMode.ili2gpkg
        importer.configuration = configuration

        self.assertEqual(importer.run(), iliimporter.Importer.SUCCESS)

        config_manager = GpkgCommandConfigManager(importer.configuration)
        generator = Generator(DbIliMode.ili2gpkg, config_manager.get_uri(),
                              configuration.inheritance)

        available_layers = generator.layers()
        self.assertEqual(len(available_layers), 207)
Exemple #11
0
    def accepted(self):
        self._running_tool = True
        self.txtStdout.clear()
        self.progress_bar.setValue(0)
        self.bar.clearWidgets()

        if not os.path.isfile(self.xtf_file_line_edit.text().strip()):
            self._running_tool = False
            error_msg = QCoreApplication.translate(
                "DialogImportData",
                "Please set a valid XTF file before importing data. XTF file does not exist."
            )
            self.txtStdout.setText(error_msg)
            self.show_message(error_msg, Qgis.Warning)
            self.xtf_file_line_edit.setFocus()
            return

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

        configuration = self.update_configuration()

        if configuration.disable_validation:  # If data validation at import is disabled, we ask for confirmation
            self.msg = QMessageBox()
            self.msg.setIcon(QMessageBox.Question)
            self.msg.setText(
                QCoreApplication.translate(
                    "DialogImportData",
                    "Are you sure you want to import your data without validation?"
                ))
            self.msg.setWindowTitle(
                QCoreApplication.translate("DialogImportData",
                                           "Import XTF without validation?"))
            self.msg.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
            res = self.msg.exec_()
            if res == QMessageBox.No:
                self._running_tool = False
                return

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

        if not self.get_ili_models():
            self._running_tool = False
            error_msg = QCoreApplication.translate(
                "DialogImportData",
                "The selected XTF file does not have information according to the LADM-COL model to import."
            )
            self.txtStdout.setText(error_msg)
            self.show_message(error_msg, Qgis.Warning)
            self.import_models_list_view.setFocus()
            return

        # Get list of models present in the XTF file, in the DB and in the list of required models (by the plugin)
        ili_models = set([ili_model for ili_model in self.get_ili_models()])

        supported_models_in_ili = set([
            m.full_name() for m in self.__ladmcol_models.supported_models()
        ]).intersection(ili_models)

        if not supported_models_in_ili:
            self._running_tool = False
            error_msg = QCoreApplication.translate("DialogImportData",
                                                   "The selected XTF file does not have data from any LADM-COL model supported by the LADM-COL Assistant. " \
                                                   "Therefore, you cannot import it! These are the models supported:\n\n * {}").format(" \n * ".join([m.full_alias() for m in self.__ladmcol_models.supported_models()]))
            self.txtStdout.setText(error_msg)
            self.show_message(error_msg, Qgis.Warning)
            self.import_models_list_view.setFocus()
            return

        db_models = set(self.db.get_models())
        suggested_models = sorted(ili_models.difference(db_models))

        if not ili_models.issubset(db_models):
            self._running_tool = False
            error_msg = QCoreApplication.translate("DialogImportData",
                                                   "IMPORT ERROR: The XTF file to import does not have the same models as the target database schema. " \
                                                   "Please create a schema that also includes the following missing modules:\n\n * {}").format(
                " \n * ".join(suggested_models))
            self.txtStdout.clear()
            self.txtStdout.setTextColor(QColor('#000000'))
            self.txtStdout.setText(error_msg)
            self.show_message(error_msg, Qgis.Warning)
            self.xtf_file_line_edit.setFocus()

            # button is removed to define order in GUI
            for button in self.buttonBox.buttons():
                if button.text() == self.BUTTON_NAME_IMPORT_DATA:
                    self.buttonBox.removeButton(button)

            # Check if button was previously added
            self.remove_create_structure_button()

            if self.link_to_import_schema:
                self.buttonBox.addButton(
                    self.BUTTON_NAME_GO_TO_CREATE_STRUCTURE,
                    QDialogButtonBox.AcceptRole).setStyleSheet(
                        "color: #aa2222;")
            self.buttonBox.addButton(self.BUTTON_NAME_IMPORT_DATA,
                                     QDialogButtonBox.AcceptRole)

            return

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

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

            dataImporter = iliimporter.Importer(dataImport=True)

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

            dataImporter.tool = db_factory.get_model_baker_db_ili_mode()
            dataImporter.configuration = configuration

            self.save_configuration(configuration)

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

            self.progress_bar.setValue(25)

            try:
                if dataImporter.run() != iliimporter.Importer.SUCCESS:
                    self._running_tool = False
                    self.show_message(
                        QCoreApplication.translate(
                            "DialogImportData",
                            "An error occurred when importing the data. For more information see the log..."
                        ), Qgis.Warning)
                    return
            except JavaNotFoundError:
                self._running_tool = False
                error_msg_java = QCoreApplication.translate(
                    "DialogImportData",
                    "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(error_msg_java)
                self.show_message(error_msg_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(
                    "DialogImportData",
                    "Import of the data was successfully completed"),
                Qgis.Success)
Exemple #12
0
    def accepted(self):
        configuration = self.update_configuration()

        if not self.get_checked_models():
            message_error = QCoreApplication.translate(
                "DialogImportSchema",
                "Please set a valid model(s) before creating the LADM-COL structure."
            )
            self.txtStdout.setText(message_error)
            self.show_message(message_error, Qgis.Warning)
            self.import_models_list_widget.setFocus()
            return

        self.save_configuration(configuration)

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

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

            importer = iliimporter.Importer()

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

            importer.tool_name = item_db.get_model_baker_tool_name()
            importer.configuration = configuration
            importer.stdout.connect(self.print_info)
            importer.stderr.connect(self.on_stderr)
            importer.process_started.connect(self.on_process_started)
            importer.process_finished.connect(self.on_process_finished)

            try:
                if importer.run() != iliimporter.Importer.SUCCESS:
                    self.enable()
                    self.progress_bar.hide()
                    self.show_message(
                        QCoreApplication.translate(
                            "DialogImportSchema",
                            "An error occurred when creating the LADM-COL structure. For more information see the log..."
                        ), Qgis.Warning)
                    return
            except JavaNotFoundError:
                # Set JAVA PATH
                get_java_path_dlg = DialogGetJavaPath()
                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(
                        "DialogImportSchema",
                        """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.print_info(
                QCoreApplication.translate("DialogImportSchema", "\nDone!"),
                '#004905')
            self.show_message(
                QCoreApplication.translate(
                    "DialogImportSchema",
                    "Creation of the LADM-COL structure was successfully completed"
                ), Qgis.Success)

            self.models_have_changed.emit(self.db, True)
    def accepted(self):
        configuration = self.update_configuration()

        if not os.path.isfile(self.xtf_file_line_edit.text().strip()):
            message_error = 'Please set a valid XTF file before importing data. XTF file does not exist'
            self.txtStdout.setText(
                QCoreApplication.translate("DialogImportData", message_error))
            self.show_message(message_error, Qgis.Warning)
            self.xtf_file_line_edit.setFocus()
            return

        if not self.xtf_file_line_edit.validator().validate(
                configuration.xtffile, 0)[0] == QValidator.Acceptable:
            message_error = 'Please set a valid XTF before importing data.'
            self.txtStdout.setText(
                QCoreApplication.translate("DialogImportData", 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(
                "DialogImportData",
                "The selected XTF file does not have information according to the LADM-COL model to import."
            )
            self.txtStdout.setText(message_error)
            self.show_message(message_error, Qgis.Warning)
            self.import_models_list_view.setFocus()
            return

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

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

            dataImporter = iliimporter.Importer(dataImport=True)

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

            dataImporter.tool_name = item_db.get_model_baker_tool_name()
            dataImporter.configuration = configuration

            self.save_configuration(configuration)

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

            self.progress_bar.setValue(25)

            try:
                if dataImporter.run() != iliimporter.Importer.SUCCESS:
                    self.enable()
                    self.progress_bar.hide()
                    self.show_message(
                        QCoreApplication.translate(
                            "DialogImportData",
                            "An error occurred when importing the data. For more information see the log..."
                        ), Qgis.Warning)
                    return
            except JavaNotFoundError:

                # Set JAVA PATH
                get_java_path_dlg = DialogGetJavaPath()
                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(
                        "DialogImportData",
                        """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(
                    "DialogImportData",
                    "Import of the data was successfully completed"),
                Qgis.Success)
    def accepted(self):
        configuration = self.update_configuration()

        if not self.get_checked_models():
            message_error = QCoreApplication.translate("DialogImportSchema", "Please set a valid model(s) before creating the LADM-COL structure.")
            self.txtStdout.setText(message_error)
            self.show_message(message_error, Qgis.Warning)
            self.import_models_list_widget.setFocus()
            return

        if self.type_combo_box.currentData() == 'pg':
            if not self.schema_name_line_edit.text().strip():
                message_error = QCoreApplication.translate("DialogImportSchema", "Please set a valid schema name before creating the LADM-COL structure.")
                self.txtStdout.setText(message_error)
                self.show_message(message_error, Qgis.Warning)
                self.schema_name_line_edit.setFocus()
                return
        elif self.type_combo_box.currentData() == 'gpkg':
            if not configuration.dbfile or self.gpkg_file_line_edit.validator().validate(configuration.dbfile, 0)[0] != QValidator.Acceptable:
                message_error = QCoreApplication.translate("DialogImportSchema", 'Please set a valid database file before creating the LADM-COL structure.')
                self.txtStdout.setText(message_error)
                self.show_message(message_error, Qgis.Warning)
                self.gpkg_file_line_edit.setFocus()
                return

        configuration.dbschema = self.schema_name_line_edit.text().strip().lower()
        self.save_configuration(configuration)

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

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

            importer = iliimporter.Importer()

            importer.tool_name = 'ili2pg' if self.type_combo_box.currentData() == 'pg' else 'ili2gpkg'
            importer.configuration = configuration
            importer.stdout.connect(self.print_info)
            importer.stderr.connect(self.on_stderr)
            importer.process_started.connect(self.on_process_started)
            importer.process_finished.connect(self.on_process_finished)

            try:
                if importer.run() != iliimporter.Importer.SUCCESS:
                    self.enable()
                    self.progress_bar.hide()
                    self.show_message(QCoreApplication.translate("DialogImportSchema", "An error occurred when creating the LADM-COL structure. For more information see the log..."), Qgis.Warning)
                    return
            except JavaNotFoundError:
                # Set JAVA PATH
                get_java_path_dlg = DialogGetJavaPath()
                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("DialogImportSchema",
                                                                    """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.print_info(QCoreApplication.translate("DialogImportSchema", "\nDone!"), '#004905')
            self.show_message(QCoreApplication.translate("DialogImportSchema", "Creation of the LADM-COL structure was successfully completed"), Qgis.Success)
    def accepted(self):
        self._running_tool = True
        self.txtStdout.clear()
        self.progress_bar.setValue(0)
        self.bar.clearWidgets()

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

        configuration = self.update_configuration()
        configuration = self.apply_role_model_configuration(configuration)

        if not self.get_checked_models():
            self._running_tool = False
            message_error = QCoreApplication.translate(
                "DialogImportSchema",
                "You should select a valid model(s) before creating the LADM-COL structure."
            )
            self.txtStdout.setText(message_error)
            self.show_message(message_error, Qgis.Warning)
            self.import_models_list_widget.setFocus()
            return

        self.save_configuration(configuration)

        with OverrideCursor(Qt.WaitCursor):
            self.progress_bar.show()
            self.disable()
            self.txtStdout.setTextColor(QColor('#000000'))
            self.txtStdout.clear()

            importer = iliimporter.Importer()

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

            importer.tool = db_factory.get_model_baker_db_ili_mode()
            importer.configuration = configuration
            importer.stdout.connect(self.print_info)
            importer.stderr.connect(self.on_stderr)
            importer.process_started.connect(self.on_process_started)
            importer.process_finished.connect(self.on_process_finished)

            try:
                if importer.run() != iliimporter.Importer.SUCCESS:
                    self._running_tool = False
                    self.show_message(
                        QCoreApplication.translate(
                            "DialogImportSchema",
                            "An error occurred when creating the LADM-COL structure. 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(
                    "DialogImportSchema",
                    "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()
            if self.link_to_import_data:
                self.buttonBox.addButton(
                    self.BUTTON_NAME_GO_TO_IMPORT_DATA,
                    QDialogButtonBox.AcceptRole).setStyleSheet(
                        "color: #007208;")
            self.buttonBox.setEnabled(True)
            self.buttonBox.addButton(QDialogButtonBox.Close)
            self.progress_bar.setValue(100)
            self.print_info(
                QCoreApplication.translate("DialogImportSchema", "\nDone!"),
                '#004905')
            self.show_message(
                QCoreApplication.translate(
                    "DialogImportSchema",
                    "LADM-COL structure was successfully created!"),
                Qgis.Success)
            self.on_result.emit(
                True)  # Inform other classes that the execution was successful
            self._db_was_changed = True  # Schema could become LADM compliant after a schema import

            if self.db_source == COLLECTED_DB_SOURCE:
                self.logger.info(
                    __name__,
                    "Schedule a call to refresh db relations cache since a Schema Import was run on the current 'collected' DB."
                )
                self._schedule_layers_and_relations_refresh = True
Exemple #16
0
    def accepted(self):
        configuration = self.update_configuration()

        if not os.path.isfile(self.xtf_file_line_edit.text().strip()):
            message_error = 'Please set a valid XTF file before importing data. XTF file does not exist'
            self.txtStdout.setText(
                QCoreApplication.translate("DialogImportData", message_error))
            self.show_message(message_error, Qgis.Warning)
            self.xtf_file_line_edit.setFocus()
            return

        if not self.xtf_file_line_edit.validator().validate(
                configuration.xtffile, 0)[0] == QValidator.Acceptable:
            message_error = 'Please set a valid XTF before importing data.'
            self.txtStdout.setText(
                QCoreApplication.translate("DialogImportData", 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(
                "DialogImportData",
                "The selected XTF file does not have information according to the LADM-COL model to import."
            )
            self.txtStdout.setText(message_error)
            self.show_message(message_error, Qgis.Warning)
            self.import_models_list_view.setFocus()
            return

        # Get list models in db and xtf
        ili_models = set([ili_model for ili_model in self.get_ili_models()])

        db_models = list()
        for db_model in self.db.get_models():
            model_name_with_dependencies = db_model['modelname']
            model_name = model_name_with_dependencies.split('{')[0]
            db_models.append(model_name)
        db_models = set(db_models)

        if not ili_models.issubset(db_models):
            message_error = "The XTF file to import does not have the same models as the target database schema. " \
                            "Please create a schema that also includes the following missing modules:\n\n * {}".format(" \n * ".join(sorted(ili_models.difference(db_models))))
            self.txtStdout.clear()
            self.txtStdout.setTextColor(QColor('#000000'))
            self.txtStdout.setText(
                QCoreApplication.translate("DialogImportData", message_error))
            self.show_message(message_error, Qgis.Warning)
            self.xtf_file_line_edit.setFocus()

            # button is removed to define order in GUI
            for button in self.buttonBox.buttons():
                if button.text() == self.BUTTON_NAME_IMPORT_DATA:
                    self.buttonBox.removeButton(button)

            # Check if button was previously added
            self.remove_create_structure_button()

            self.buttonBox.addButton(
                self.BUTTON_NAME_GO_TO_CREATE_STRUCTURE,
                QDialogButtonBox.AcceptRole).setStyleSheet("color: #aa2222;")
            self.buttonBox.addButton(self.BUTTON_NAME_IMPORT_DATA,
                                     QDialogButtonBox.AcceptRole)

            return

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

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

            dataImporter = iliimporter.Importer(dataImport=True)

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

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

            self.save_configuration(configuration)

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

            self.progress_bar.setValue(25)

            try:
                if dataImporter.run() != iliimporter.Importer.SUCCESS:
                    self.enable()
                    self.progress_bar.hide()
                    self.show_message(
                        QCoreApplication.translate(
                            "DialogImportData",
                            "An error occurred when importing 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(
                        "DialogImportData",
                        """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(
                    "DialogImportData",
                    "Import of the data was successfully completed"),
                Qgis.Success)