示例#1
0
    def test_compare_tables(self):
        params = self.params
        SQL_Table = params["sql_table"]
        GDB_Table = params["gdb_table"]
        for x in [SQL_Table, GDB_Table]:
            if not arcpy.Exists(x):
                self.fail()
        compare = Code.compare_tables(sql_table=SQL_Table, gdb_table=GDB_Table)
        keys = list(compare.keys())
        keys.sort()
        # these items must be in alphabetical order!
        self.assertListEqual(["add_rows", "compare_result", "exist_rows", "folioIds",
                             "match_fields"], keys)

        if compare["compare_result"] == 0:
            for x in [compare["add_rows"], compare["exist_rows"]]:
                print("length should be 0 :: {}".format(len(x)))
                self.assertEquals(len(x), 0)

        elif compare["compare_result"] >= 1:
            rows = len(compare["add_rows"]) + len(compare["exist_rows"])
            print("length should be greater than 0 :: {}".format(rows))
            self.assertGreaterEqual(rows, 1)
            # check that foliosIds are snagged
            self.assertGreaterEqual(len(compare["folioIds"]), 1)
    def setUpClass(cls):
        tool = PythonTool()
        parameters = tool.getParameterInfo()
        params = tool.processParameters(parameters=parameters)
        out_f = params["connection_folder"]
        out_n = params["edit_connection_name"]
        plat = params["platform"]
        inst = params["instance"]

        cls.weaver_attributes = params["table_attributes"]

        edit_version_name = params["edit_version_name"]
        sql_table = params["sql_table"]
        gdb_table = params["gdb_table"]
        gdb_table_name = params["gdb_table_name"]
        opt = params["opt"]

        cls.sde_file = params["gis_gdb"]
        manager = Manager(opt=opt, connection_folder=out_f, target_sde=cls.sde_file,
                          new_version=edit_version_name, new_connection=out_n, platform=plat, instance=inst)
        manager.clean_previous()
        cls.version_sde_file = manager.connect_version()

        result = Tool.compare_tables(sql_table=sql_table, gdb_table=gdb_table)

        cls.match_fields = result["match_fields"]
        cls.add_rows = result["add_rows"]
        cls.exist_rows = result["exist_rows"]
        cls.folio_ids = result["folioIds"]

        env.workspace = cls.version_sde_file
        cls.editor = da.Editor(cls.version_sde_file)
        cls.version_gdb_table = arcpy.ListTables("*{}*".format(gdb_table_name))[0]
示例#3
0
    def setUp(self):

        GDB_Table = self.params["gdb_table"]
        SQL_Table = self.params["sql_table"]
        weav_atts = self.params["weaver_attributes"]
        bldg_atts = self.params["building_attributes"]
        bldgs = self.versioned_buildings
        result = Tool.compare_tables(sql_table=SQL_Table, gdb_table=GDB_Table)
        folioIds = result["folioIds"]
        # folioIds, bldgs, rel_table, bldg_atts, weav_atts, version_sde, editor
        self.updater = Updater(folioIds=folioIds, bldgs=bldgs, rel_table=GDB_Table, bldg_atts=bldg_atts,
                               weav_atts=weav_atts, version_sde=self.version_sde, editor=self.edit)
    def setUp(self):

        GDB_Table = self.params["gdb_table"]
        SQL_Table = self.params["sql_table"]
        table_atts = self.params["table_attributes"]
        bldg_atts = self.params["building_attributes"]
        comb_atts = self.params["combination_attributes"]
        domains = self.params["domains"]
        bldgs = self.versioned_buildings
        result = Tool.compare_tables(sql_table=SQL_Table, gdb_table=GDB_Table)
        folioIds = result["folioIds"]
        # folioIds, bldgs, rel_table, bldg_atts, weav_atts, version_sde, editor
        self.updater = Updater(domains=domains, folioIds=folioIds, bldgs=bldgs, rel_table=GDB_Table, bldg_atts=bldg_atts,
                               table_atts=table_atts, combination_atts=comb_atts, version_sde=self.version_sde, editor=self.edit)
示例#5
0
    def execute(self, parameters, messages):
        """The method calls classes defined in external files."""
        arcpy.AddMessage("WeaverGDBUpdate.execute()")
        params = self.process_parameters(parameters=parameters)
        connection_folder = params["connection_folder"]
        platform = params["platform"]
        instance = params["instance"]
        sde_file = params["gis_gdb"]
        table_db = params["table_db"]
        bldgs = params["bldgs"]
        sql_table = params["sql_table"]
        gdb_table = params["gdb_table"]
        gdb_table_name = params["gdb_table_name"]
        buildings_name = params["buildings_name"]
        edit_connection_name = params["edit_connection_name"]
        edit_version_name = params["edit_version_name"]
        building_attributes = params["building_attributes"]
        weaver_attributes = params["weaver_attributes"]
        opt = params["opt"]

        try:

            # These values need to be removed when the user parameters are created
            result = UpdateNoiseMitSDE.compare_tables(sql_table=sql_table, gdb_table=gdb_table)

            compare_result = result["compare_result"]
            folioIds = result["folioIds"]
            match_fields = result["match_fields"]
            add_rows = result["add_rows"]
            exist_rows = result["exist_rows"]

            # compare result if True means that changes need to be made to the GDB Table and thus the Buildings
            if compare_result:
                arcpy.AddMessage({"# rows to add": len(add_rows),
                                  "# rows to remove": len(exist_rows)})
                # create VersionManager class object to create new version, connect to it,
                # and create an sde connection file, set as current workspace

                version_manager = VersionManager(opt, connection_folder, sde_file, edit_version_name, edit_connection_name, platform, instance)
                version_manager.clean_previous()
                version_sde_file = version_manager.connect_version()

                if os.path.exists(version_sde_file):
                    arcpy.AddMessage(version_sde_file)
                else:
                    raise Exception("version_sde_file not created")

                editor = da.Editor(version_sde_file)
                editor.startEditing()
                env.workspace = version_sde_file
                gdb_table = arcpy.ListTables("*{}*".format(gdb_table_name))[0]
                if arcpy.Exists(gdb_table):
                    # create GDBTableUpdater class object
                    weaver_updater = GDBTableUpdater(weaver_attributes, folioIds, match_fields, gdb_table, add_rows, exist_rows,
                                                     version_sde_file, editor)

                    # should return True when editing is complete
                    table_updated = weaver_updater.perform_update()

                    # create BuildingUpdater class object
                    version_buildings = self.get_versioned_fc(version_sde_file, buildings_name)
                    if arcpy.Exists(version_buildings):
                        try:
                            building_updater = BuildingsUpdater(folioIds, version_buildings, gdb_table, building_attributes,
                                                                weaver_attributes, version_sde_file, editor)

                            # should return True when editing it complete
                            buildings_updated = building_updater.update_buildings()

                            editor.stopEditing(True)
                            del editor

                            try:
                                version_manager.rec_post()
                            except Exception as e:
                                arcpy.AddError("Exception occurred during the rec/post operation, " +
                                "the edits were saved in the version however the version will be removed without the " +
                                "edits having been posted to the default version :: {} :: {}".format(e.message,
                                                                                                     traceback.print_exc()))

                        except Exception as e:
                            editor.stopEditing(False)
                            del editor
                            arcpy.AddError("Exception occured during buildings updates, edits have not been saved :: {}"\
                                           ":: {}".format(e.message, traceback.print_exc()))
                    else:
                        editor.stopEditing(False)
                        del editor
                        arcpy.AddError("Unable to determine the buildings feature class\
                                       using the version connection")
                else:
                    editor.stopEditing(False)
                    del editor
                    arcpy.AddError("Unable to determine the gdb table\
                                    using the version connection")

                version_manager.clean_previous()
                del version_manager

                # Verify that the edits where posted
                # TODO- determine failproof methods for isolating the changed features and viewing the change
                env.workspace = sde_file
                fields = [x for x in building_attributes.itervalues()]
                cursor = da.SearchCursor(bldgs, fields,
                                         "{} in ('{}')".format(building_attributes["Folio Number"], "','".join(folioIds)))
                try:
                    values = cursor.next()
                    arcpy.AddMessage("This is an edited row in the buildings table :: {}".format(values))
                except StopIteration:
                    arcpy.AddMessage("No buildings found with folioIDs in {}".format(folioIds))
                del cursor

            else:
                arcpy.AddMessage("The files are identical, no edits needed")

            return True

        except:
            exc_type, exc_value, exc_traceback = sys.exc_info()
            arcpy.AddError(repr(traceback.format_exception(exc_type, exc_value, exc_traceback)))