def test_duplicate_without_copymark(self): """duplicate_into_same_group""" # load source md_duplicator = MetadataDuplicator( api_client=self.isogeo, source_metadata_uuid=environ.get("ISOGEO_METADATA_FIXTURE_UUID"), ) # duplicate it new_md = md_duplicator.duplicate_into_same_group( copymark_title=False, copymark_abstract=False) # compare results self.assertEqual(self.fixture_metadata.title, new_md.title) # delete created metadata self.isogeo.metadata.delete(new_md._id)
def test_duplicate_with_copymark(self): """duplicate_into_other_group""" # load source md_duplicator = MetadataDuplicator( api_client=self.isogeo, source_metadata_uuid=environ.get("ISOGEO_METADATA_FIXTURE_UUID"), ) # duplicate it new_md = md_duplicator.import_into_other_metadata( destination_metadata_uuid=self.fixture_metadata_target._id, copymark_title=True, copymark_abstract=True, ) # compare results self.assertNotEqual(self.fixture_metadata.abstract, new_md.abstract) self.assertEqual(self.fixture_metadata.title + " [COPIE]", new_md.title) self.assertNotEqual(self.fixture_metadata.title, new_md.title) # delete created metadata self.isogeo.metadata.delete(new_md._id)
src_name = md[2] trg_uuid = li_trg_to_migrate[index][0] trg_name = li_trg_to_migrate[index][1] if default_timer() - auth_timer >= 230: logger.info("Manually refreshing token") isogeo.connect( username=environ.get("ISOGEO_USER_NAME"), password=environ.get("ISOGEO_USER_PASSWORD"), ) auth_timer = default_timer() else: pass # loading the metadata to duplicate from his UUID try: src_migrator = MetadataDuplicator(api_client=isogeo, source_metadata_uuid=src_uuid) except Exception as e: logger.info("Faile to load {} source metadata : \n {}".format( src_uuid, e)) li_failed.append( [src_uuid, src_title, src_name, trg_name, trg_uuid]) index += 1 continue # change title to make it specific for rouen src_migrator.metadata_source.title = src_migrator.metadata_source.title.replace( "Département des Pyrénées-Atlantiques", "Haute-Normandie") # remove publication and update events from metadata object that gonna be used to update target metadata for event in src_migrator.metadata_source.events: if event.get("kind") == "update" or event.get(
"Connection to Isogeo established in {:5.2f}s.".format(auth_timer)) # BACKUP backup_mngr = BackupManager(api_client=isogeo, output_folder="./output") search_parameters = {"query": None, "specific_md": li_to_backup} backup_mngr.metadata(search_params=search_parameters) bkp_timer = default_timer() - auth_timer logger.info("Backup of {} finished in {:5.2f}s.".format( len(li_to_backup), bkp_timer)) # MIGRATION prev_timer = bkp_timer for tup_to_migrate in li_to_migrate: # prepare source for migration migrator = MetadataDuplicator(api_client=isogeo, source_metadata_uuid=tup_to_migrate[0]) # import new_md = migrator.import_into_other_metadata( destination_metadata_uuid=tup_to_migrate[1], copymark_catalog="3dda5db6cbea4c48b0357d47d95ebf19", switch_service_layers=1, ) # log it logger.info("Migration from {} to {} finished in {:5.2f}s.".format( tup_to_migrate[0], tup_to_migrate[1], default_timer() - prev_timer)) prev_timer = default_timer() mig_total_timer = default_timer() - bkp_timer
src_name = md[2] trg_uuid = li_trg_to_migrate[index][0] trg_name = li_trg_to_migrate[index][1] if default_timer() - auth_timer >= 6900: logger.info("Manually refreshing token") isogeo.connect( username=environ.get("ISOGEO_USER_NAME"), password=environ.get("ISOGEO_USER_PASSWORD"), ) auth_timer = default_timer() else: pass # loading the metadata to duplicate from his UUID try: src_migrator = MetadataDuplicator(api_client=isogeo, source_metadata_uuid=src_uuid) src_loaded = src_migrator.metadata_source except Exception as e: logger.info("Faile to load {} source metadata : \n {}".format( src_uuid, e)) li_failed.append( [src_uuid, src_title, src_name, trg_name, trg_uuid]) index += 1 continue # check if the metadata exists if isinstance(src_loaded, tuple): logger.info( "{} - There is no accessible source metadata corresponding to this " "uuid".format(src_uuid)) pass
password=environ.get("ISOGEO_USER_PASSWORD"), ) # to build mapping table of 'Isogeo Migrations' workgroup li_migrated = [] li_failed = [] index = 0 for md in li_src_to_duplicate: src_uuid = md[0] src_title = md[1] src_name = md[2] trg_uuid = li_trg_to_duplicate[index][0] trg_name = li_trg_to_duplicate[index][1] # loading the metadata to duplicate from his UUID try: src_migrator = MetadataDuplicator(api_client=isogeo, source_metadata_uuid=src_uuid) trg_migrator = MetadataDuplicator(api_client=isogeo, source_metadata_uuid=trg_uuid) except Exception as e: logger.info("Faile to load source {} and target {} : \n {}".format( src_uuid, trg_uuid, e)) li_failed.append( [src_uuid, src_title, src_name, trg_name, trg_uuid]) index += 1 continue src_loaded = src_migrator.metadata_source trg_loaded = trg_migrator.metadata_source # check if the metadata exists if isinstance(src_loaded, tuple):
logger.info("------- Migrating metadata {}/{} -------".format( index + 1, len(li_uuid_to_migrate))) src_uuid = md if default_timer() - auth_timer >= 6900: logger.info("Manually refreshing token") isogeo.connect( username=environ.get("ISOGEO_USER_NAME"), password=environ.get("ISOGEO_USER_PASSWORD"), ) auth_timer = default_timer() else: pass # loading the metadata to duplicate from his UUID try: duplicator = MetadataDuplicator(api_client=isogeo, source_metadata_uuid=src_uuid) except Exception as e: logger.info("Faile to load {} source metadata : \n {}".format( src_uuid, e)) li_failed.append([ src_uuid, ]) index += 1 continue # change metadata object that gonna be used to update target metadata title to make it specific for AMP if "- France Métropolitaine" in duplicator.metadata_source.title: duplicator.metadata_source.title = duplicator.metadata_source.title.replace( "- France Métropolitaine", "- Métropole Aix-Marseille-Provence") elif "- XXXX" in duplicator.metadata_source.title:
condition_to_delete = Condition(**li_cond_to_delete[0]) # add the new condition isogeo.metadata.conditions.create( metadata=metadata, condition=new_condition ) # delete the old condition isogeo.metadata.conditions.delete( metadata=metadata, condition=condition_to_delete ) else: pass # duplicate md if required if cat_uuid == bdcarto_src_cat_uuid: duplicator = MetadataDuplicator( api_client=isogeo, source_metadata_uuid=md.get("_id") ) duplicator.duplicate_into_same_group( copymark_catalog=bdcarto_trg_cat_uuid, copymark_title=False, copymark_abstract=False, exclude_catalogs=[bdcarto_src_cat_uuid], switch_service_layers=True ) else: pass isogeo.close()
) auth_timer = default_timer() li_parsed = [] for info in li_info: if default_timer() - auth_timer >= 6900: isogeo.connect( username=environ.get("ISOGEO_USER_NAME"), password=environ.get("ISOGEO_USER_PASSWORD"), ) auth_timer = default_timer() else: pass migrator = MetadataDuplicator(api_client=isogeo, source_metadata_uuid=info[1]) migrator.metadata_source.name = info[2] duplicated = migrator.duplicate_into_same_group( copymark_abstract=False, # FALSE EN PROD copymark_title=False, # FALSE EN PROD copymark_catalog="5c743581c7724f69bdab6b542d003b7a", switch_service_layers=True) li_parsed.append([ duplicated.title, duplicated.name, info[1], duplicated._id, "https://app.isogeo.com/groups/" + info[0] + "/resources/" +
li_matching_table = [] for md in origin_search.results: if default_timer() - auth_timer >= 250: logger.info("Manually refreshing token") isogeo.connect( username=environ.get("ISOGEO_USER_NAME"), password=environ.get("ISOGEO_USER_PASSWORD"), ) auth_timer = default_timer() else: pass duplicator = MetadataDuplicator( api_client=isogeo, source_metadata_uuid=md.get("_id") ) duplicated_md = duplicator.duplicate_into_other_group( destination_workgroup_uuid=dgfip_wg_uuid, copymark_abstract=False, copymark_title=False, ) isogeo.catalog.associate_metadata(metadata=duplicated_md, catalog=destination_cat) li_matching_table.append( ( md.get("name"), md.get("_id"), duplicated_md._id
src_title = infos[1] src_name = infos[2] # check if target metadata have already been duplicated if src_name in li_already_duplicated_names: logger.info( "'{}' ({}) has already been duplicated into '{}' workgroup". format(src_name, src_uuid, origin_wg_uuid)) index += 1 continue else: pass # loading the metadata to duplicate from his UUID try: src_migrator = MetadataDuplicator(api_client=isogeo, source_metadata_uuid=src_uuid) except Exception as e: logger.info("Faile to load {} source metadata : \n {}".format( src_uuid, e)) li_failed.append( [src_uuid, src_title, src_name, "missing", "missing"]) index += 1 continue # store source metadata object src_loaded = src_migrator.metadata_source # check if the metadata exists if isinstance(src_loaded, tuple): logger.info( "{} - There is no accessible source metadata corresponding to this uuid : {}"
src_name = md[2] trg_uuid = li_trg_to_migrate[index][0] trg_name = li_trg_to_migrate[index][1] if default_timer() - auth_timer >= 6900: logger.info("Manually refreshing token") isogeo.connect( username=environ.get("ISOGEO_USER_NAME"), password=environ.get("ISOGEO_USER_PASSWORD"), ) auth_timer = default_timer() else: pass # loading the metadata to duplicate from his UUID try: src_migrator = MetadataDuplicator(api_client=isogeo, source_metadata_uuid=src_uuid) src_loaded = src_migrator.metadata_source except Exception as e: logger.info("Faile to load {} source metadata : \n {}".format( src_uuid, e)) li_failed.append( [src_uuid, src_title, src_name, trg_name, trg_uuid]) index += 1 continue # check if the metadata exists if isinstance(src_loaded, tuple): logger.info( "{} - There is no accessible source metadata corresponding to this " "uuid".format(src_uuid)) pass
if src_md_uuid and trg_md_uuid: # Refresh api clien token if needed if default_timer() - auth_timer >= 6900: logger.info("Manually refreshing token") isogeo.connect( username=environ.get("ISOGEO_USER_NAME"), password=environ.get("ISOGEO_USER_PASSWORD"), ) auth_timer = default_timer() else: pass logger.info("from {} to {} :".format(src_title, trg_name)) # instanciate MetadataDuplicator migrator = MetadataDuplicator(api_client=isogeo, source_metadata_uuid=src_md_uuid) # migrate migrated = migrator.import_into_other_metadata( destination_metadata_uuid=trg_md_uuid, copymark_abstract=False, copymark_title=False) else: logger.error( "faile to retrieve target or source md from api content reply") index += 1 continue index += 1 isogeo.close()
li_migrated = [] li_failed = [] index = 0 for md in li_src_to_migrate: logger.info("------- Migrating metadata {}/{} -------".format( index + 1, len(li_src_to_migrate))) src_uuid = md[0] src_title = md[1] src_name = md[2] trg_uuid = li_trg_to_migrate[index][0] trg_name = li_trg_to_migrate[index][1] # loading the metadata to duplicate from his UUID try: src_migrator = MetadataDuplicator(api_client=isogeo, source_metadata_uuid=src_uuid) src_loaded = src_migrator.metadata_source except Exception as e: logger.info("Faile to load {} source metadata : \n {}".format( src_uuid, e)) li_failed.append( [src_uuid, src_title, src_name, trg_name, trg_uuid]) index += 1 continue # check if the metadata exists if isinstance(src_loaded, tuple): logger.info( "{} - There is no accessible source metadata corresponding to this " "uuid".format(src_uuid)) pass