Instrução
Em alguns casos, é necessário determinar as dependências entre os itens do Portal for ArcGIS. Por exemplo, na limpeza de dados, um aplicativo da web e seu mapa da web associado podem precisar ser excluídos. Verificar manualmente essas dependências pode ser entediante. Como alternativa, este processo pode ser executado programaticamente com o privilégio de Administrador usando a seguinte API ArcGIS para funções Python: dependente_upon() e dependente_to().
As etapas a seguir descrevem como encontrar dependências no Portal for ArcGIS usando a API ArcGIS para Python.
from arcgis.gis import GIS from IPython.display import display
source = GIS("<portalurl>", "<admin_user>", "<admin_password>") source_users = source.users.search(query=None, sort_field='username', sort_order='asc', max_users=100, outside_org=False, exclude_system=True) source_items_by_id = {} print('User list: Role')
for user in source_users: print(user.username + "\t:\t" + str(user.role))
for user in source_users: num_items = 0 num_folders = 0 print("Collecting item ids for {}".format(user.username), end="\n\n") user_content = user.items()
for item in user_content: num_items += 1 source_items_by_id[item.itemid] = item print("\n\n Item: \t {2} \t\t\t id {0} is dependent on these items: \t {1}".format(item.itemid,item.dependent_upon(), item.title)) if (item.dependent_to()['total'] > 0): print("\t This item is also a dependency of these items: {}".format(item.dependent_to()))
folders = user.folders for folder in folders: num_folders += 1 folder_items = user.items(folder=folder['title']) for item in folder_items: num_items += 1 source_items_by_id[item.itemid] = item print("\n\n Item: \t {2} \t\t\t id {0} is dependent on these items: \t {1}".format(item.itemid,item.dependent_upon(), item.title)) if (item.dependent_to()['total'] > 0): print("\t This item is also a dependency of these items: {}".format(item.dependent_to())) print("Number of folders {} # Number of items {} # Number of users {}".format(str(num_folders), str(num_items), len(source_users)))
O seguinte mostra o script completo:
from arcgis.gis import GIS from IPython.display import display source = GIS("https://test.domain.com/portal", "portaladmin", "portaladmin") source_users = source.users.search(query=None, sort_field='username', sort_order='asc', max_users=100, outside_org=False, exclude_system=True) source_items_by_id = {} print('User list: Role') for user in source_users: print(user.username + "\t:\t" + str(user.role)) for user in source_users: num_items = 0 num_folders = 0 print("Collecting item ids for {}".format(user.username), end="\n\n") user_content = user.items() for item in user_content: num_items += 1 source_items_by_id[item.itemid] = item print("\n\n Item: \t {2} \t\t\t id {0} is dependent on these items: \t {1}".format(item.itemid,item.dependent_upon(), item.title)) if (item.dependent_to()['total'] > 0): print("\t This item is also a dependency of these items: {}".format(item.dependent_to())) folders = user.folders for folder in folders: num_folders += 1 folder_items = user.items(folder=folder['title']) for item in folder_items: num_items += 1 source_items_by_id[item.itemid] = item print("\n\n Item: \t {2} \t\t\t id {0} is dependent on these items: \t {1}".format(item.itemid,item.dependent_upon(), item.title)) if (item.dependent_to()['total'] > 0): print("\t This item is also a dependency of these items: {}".format(item.dependent_to())) print("Number of folders {} # Number of items {} # Number of users {}".format(str(num_folders), str(num_items), len(source_users)))
Obtenha ajuda de especialistas do ArcGIS
Baixe o Aplicativo de Suporte da Esri