Esempio n. 1
0
    def updated_configuration(self):
        """
        Get the configuration that is updated with the user configuration changes on the dialog.
        :return: Configuration
        """
        configuration = SchemaImportConfiguration()

        mode = self.type_combo_box.currentData()
        db_id = mode & ~DbIliMode.ili

        self._lst_panel[db_id].get_fields(configuration)

        configuration.tool = mode
        configuration.epsg = self.epsg
        configuration.inheritance = self.ili2db_options.inheritance_type()
        configuration.tomlfile = self.ili2db_options.toml_file()
        configuration.create_basket_col = self.ili2db_options.create_basket_col(
        )
        configuration.create_import_tid = self.ili2db_options.create_import_tid(
        )
        configuration.stroke_arcs = self.ili2db_options.stroke_arcs()

        configuration.base_configuration = self.base_configuration
        if self.ili_file_line_edit.text().strip():
            configuration.ilifile = self.ili_file_line_edit.text().strip()

        if self.ili_models_line_edit.text().strip():
            configuration.ilimodels = self.ili_models_line_edit.text().strip()

        return configuration
Esempio n. 2
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)
Esempio n. 3
0
    def update_configuration(self):
        item_db = self._conf_db.get_db_items()[self.db.mode]

        configuration = SchemaImportConfiguration()
        item_db.set_db_configuration_params(self.db.dict_conn_params,
                                            configuration)

        # set custom toml file
        configuration.tomlfile = TOML_FILE_DIR
        configuration.epsg = DEFAULT_EPSG
        configuration.inheritance = DEFAULT_INHERITANCE
        configuration.create_basket_col = CREATE_BASKET_COL
        configuration.create_import_tid = CREATE_IMPORT_TID
        configuration.stroke_arcs = STROKE_ARCS

        java_path = get_java_path_from_qgis_model_baker()
        if java_path:
            self.base_configuration.java_path = java_path

        # Check custom model directories
        if self.use_local_models:
            if self.custom_model_directories is None:
                self.base_configuration.custom_model_directories_enabled = False
            else:
                self.base_configuration.custom_model_directories = self.custom_model_directories
                self.base_configuration.custom_model_directories_enabled = True

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

        return configuration
Esempio n. 4
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)
Esempio n. 5
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 update_configuration(self):
        db_factory = self._dbs_supported.get_db_factory(self.db.engine)

        configuration = SchemaImportConfiguration()
        db_factory.set_ili2db_configuration_params(self.db.dict_conn_params,
                                                   configuration)

        # set custom toml file
        configuration.tomlfile = TOML_FILE_DIR
        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

        # CTM12 support
        configuration.srs_auth = self.srs_auth
        configuration.srs_code = self.srs_code
        if self.srs_auth == DEFAULT_SRS_AUTH and self.srs_code == DEFAULT_SRS_CODE:
            if self.db.engine == 'pg':
                configuration.pre_script = CTM12_PG_SCRIPT_PATH
            elif self.db.engine == 'gpkg':
                # (Ugly, I know) We need to send known parameters, we'll fix this in the post_script
                configuration.srs_auth = 'EPSG'
                configuration.srs_code = 3116
                configuration.post_script = CTM12_GPKG_SCRIPT_PATH

        full_java_exe_path = JavaDependency.get_full_java_exe_path()
        if full_java_exe_path:
            self.base_configuration.java_path = full_java_exe_path

        # User could have changed the default values
        self.use_local_models = QSettings().value(
            'Asistente-LADM-COL/models/custom_model_directories_is_checked',
            DEFAULT_USE_CUSTOM_MODELS,
            type=bool)
        self.custom_model_directories = QSettings().value(
            'Asistente-LADM-COL/models/custom_models', DEFAULT_MODELS_DIR)

        # Check custom model directories
        if self.use_local_models:
            if not self.custom_model_directories:
                self.base_configuration.custom_model_directories_enabled = False
            else:
                self.base_configuration.custom_model_directories = self.custom_model_directories
                self.base_configuration.custom_model_directories_enabled = True

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

        return configuration
    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 update_configuration(self):
        configuration = SchemaImportConfiguration()

        if self.type_combo_box.currentData() == 'pg':
            # PostgreSQL specific options
            configuration.tool_name = 'pg'
            configuration.dbhost = self.db.dict_conn_params['host']
            configuration.dbport = self.db.dict_conn_params['port']
            configuration.dbusr = self.db.dict_conn_params['username']
            configuration.database = self.db.dict_conn_params['database']
            configuration.dbschema = self.schema_name_line_edit.text().strip().lower()
            configuration.dbpwd = self.db.dict_conn_params['password']
        elif self.type_combo_box.currentData() == 'gpkg':
            configuration.tool_name = 'gpkg'
            configuration.dbfile = self.db.dict_conn_params['dbfile']

        # set custom toml file
        configuration.tomlfile = TOML_FILE_DIR
        configuration.epsg = DEFAULT_EPSG
        configuration.inheritance = DEFAULT_INHERITANCE
        configuration.create_basket_col = CREATE_BASKET_COL
        configuration.create_import_tid = CREATE_IMPORT_TID
        configuration.stroke_arcs = STROKE_ARCS

        java_path = get_java_path_from_qgis_model_baker()
        if java_path:
            self.base_configuration.java_path = java_path

        # Check custom model directories
        if self.use_local_models:
            if self.custom_model_directories is None:
                self.base_configuration.custom_model_directories_enabled = False
            else:
                self.base_configuration.custom_model_directories = self.custom_model_directories
                self.base_configuration.custom_model_directories_enabled = True

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

        return configuration
    def update_configuration(self):
        db_factory = self._dbs_supported.get_db_factory(self.db.engine)

        configuration = SchemaImportConfiguration()
        db_factory.set_ili2db_configuration_params(self.db.dict_conn_params,
                                                   configuration)

        # set custom toml file
        configuration.tomlfile = TOML_FILE_DIR
        configuration.epsg = self.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

        full_java_exe_path = JavaUtils.get_full_java_exe_path()
        if full_java_exe_path:
            self.base_configuration.java_path = full_java_exe_path

        # User could have changed the default values
        self.use_local_models = QSettings().value(
            'Asistente-LADM_COL/models/custom_model_directories_is_checked',
            DEFAULT_USE_CUSTOM_MODELS,
            type=bool)
        self.custom_model_directories = QSettings().value(
            'Asistente-LADM_COL/models/custom_models', DEFAULT_MODELS_DIR)

        # Check custom model directories
        if self.use_local_models:
            if not self.custom_model_directories:
                self.base_configuration.custom_model_directories_enabled = False
            else:
                self.base_configuration.custom_model_directories = self.custom_model_directories
                self.base_configuration.custom_model_directories_enabled = True

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

        return configuration
    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)