Example #1
0
def copy_items_query():
    source = Portal('http://www.arcgis.com')
    target = Portal('http://wittm.esri.com', 'wmathot', 'wmathot')
    items = source.search(q='h1n1')
    copied_items = copy_items(items, source, target, 'wmathot', 'Copied Items (h1n1)')
    for sourceid in copied_items.keys():
        print 'Copied ' + sourceid + ' to ' + copied_items[sourceid]
Example #2
0
def copy_items_with_related():
    source = Portal('http://dev.arcgis.com')
    target = Portal('http://wittm.esri.com', 'wmathot', 'wmathot')
    items = source.search(q='type:"Web Mapping Application"', num=5)
    copied_items = copy_items(items, source, target, 'wmathot', 'Web Apps 5',  \
                              relationships=['WMA2Code', 'MobileApp2Code'])
    for sourceid in copied_items.keys():
        print 'Copied ' + sourceid + ' to ' + copied_items[sourceid]
Example #3
0
def copy_items_query():
    source = Portal('http://www.arcgis.com')
    target = Portal('http://wittm.esri.com', 'wmathot', 'wmathot')
    items = source.search(q='h1n1')
    copied_items = copy_items(items, source, target, 'wmathot',
                              'Copied Items (h1n1)')
    for sourceid in copied_items.keys():
        print 'Copied ' + sourceid + ' to ' + copied_items[sourceid]
Example #4
0
def copy_items_with_related():
    source = Portal('http://dev.arcgis.com')
    target = Portal('http://wittm.esri.com', 'wmathot', 'wmathot')
    items = source.search(q='type:"Web Mapping Application"', num=5)
    copied_items = copy_items(items, source, target, 'wmathot', 'Web Apps 5',  \
                              relationships=['WMA2Code', 'MobileApp2Code'])
    for sourceid in copied_items.keys():
        print 'Copied ' + sourceid + ' to ' + copied_items[sourceid]
Example #5
0
def create_demographics_group():
    arcgisonline = Portal('http://www.arcgis.com')
    portal = Portal('http://wittm.esri.com', 'admin', 'esri.agp')
    owner = portal.logged_in_user()['username']
    items = arcgisonline.search(q='demographics owner:esri ' + WEBMAP_ITEM_FILTER)
    copied_items = copy_items(items, arcgisonline, portal, owner)
    group_id = portal.create_group({'title': 'Demographics', 'access': 'public',
                                    'tags': 'demographics'},
                                   thumbnail='http://bit.ly/WEaIh5')
    for item_id in copied_items.values():
        portal.share_items(owner, [item_id], [group_id], True, True)
Example #6
0
def create_demographics_group():
    arcgisonline = Portal('http://www.arcgis.com')
    portal = Portal('http://wittm.esri.com', 'admin', 'esri.agp')
    owner = portal.logged_in_user()['username']
    items = arcgisonline.search(q='demographics owner:esri ' +
                                WEBMAP_ITEM_FILTER)
    copied_items = copy_items(items, arcgisonline, portal, owner)
    group_id = portal.create_group(
        {
            'title': 'Demographics',
            'access': 'public',
            'tags': 'demographics'
        },
        thumbnail='http://bit.ly/WEaIh5')
    for item_id in copied_items.values():
        portal.share_items(owner, [item_id], [group_id], True, True)
Example #7
0
def copy_group_with_shared_content():
    source = Portal('http://www.arcgis.com')
    target = Portal('http://wittm.esri.com', 'admin', 'esri.agp')
    target_owner = target.logged_in_user()['username']
    group_id = '2394b887a80347fb8544610cfa30489c'

    # Copy the groups
    groups = source.groups(q='id:' + group_id)
    copied_groups = copy_groups(groups, source, target)
    print 'Copied ' + str(len(copied_groups)) + ' groups'

    # Copy the items
    items = source.search(q='group:' + group_id)
    copied_items = copy_items(items, source, target, target_owner,
                              'Copied Items (' + group_id + ')')
    print 'Copied ' + str(len(copied_items)) + ' items'

    # Share the items in the target portal
    for item_id in copied_items.keys():
        sharing = source.user_item(item_id)[1]

        # If we have access to the full sharing properties of the source
        # item, then copy all of them, otherwise just share with the group
        if sharing and sharing['access'] != 'private':
            target_item_id = copied_items[item_id]
            target_group_ids = [copied_groups[id] for id in sharing['groups'] \
                                if id in copied_groups]
            share_org = (sharing['access'] == 'org')
            share_public = (sharing['access'] == 'public')
            if not target.is_multitenant():
                share_public = (share_public or share_org)
            target.share_items(target_owner, [target_item_id],
                               target_group_ids, \
                               share_org or share_public, \
                               share_public)
        else:
            target_item_id = copied_items[item_id]
            target_group_id = copied_groups[group_id]
            target.share_items(target_owner, [target_item_id], \
                               [target_group_id])
Example #8
0
def copy_group_with_shared_content():
    source = Portal('http://www.arcgis.com')
    target = Portal('http://wittm.esri.com', 'admin', 'esri.agp')
    target_owner = target.logged_in_user()['username']
    group_id = '2394b887a80347fb8544610cfa30489c'

    # Copy the groups
    groups = source.groups(q='id:' + group_id)
    copied_groups = copy_groups(groups, source, target)
    print 'Copied ' + str(len(copied_groups)) + ' groups'

    # Copy the items
    items = source.search(q='group:' + group_id)
    copied_items = copy_items(items, source, target, target_owner,
                              'Copied Items (' + group_id + ')')
    print 'Copied ' + str(len(copied_items)) + ' items'

    # Share the items in the target portal
    for item_id in copied_items.keys():
        sharing = source.user_item(item_id)[1]

        # If we have access to the full sharing properties of the source
        # item, then copy all of them, otherwise just share with the group
        if sharing and sharing['access'] != 'private':
            target_item_id = copied_items[item_id]
            target_group_ids = [copied_groups[id] for id in sharing['groups'] \
                                if id in copied_groups]
            share_org = (sharing['access'] == 'org')
            share_public = (sharing['access'] == 'public')
            if not target.is_multitenant():
                share_public = (share_public or share_org)
            target.share_items(target_owner, [target_item_id],
                               target_group_ids, \
                               share_org or share_public, \
                               share_public)
        else:
            target_item_id = copied_items[item_id]
            target_group_id = copied_groups[group_id]
            target.share_items(target_owner, [target_item_id], \
                               [target_group_id])
                            feature_items, feature_groups
from portalpy.provision import load_groups, copy_items

logging.basicConfig(level=logging.WARN)

# Setup portal connections and file paths
portal = Portal('http://wittm.esri.com', 'admin', 'esri.agp')
arcgisonline = Portal('http://www.arcgis.com')
groups_csv = '.\\provision_groups.csv'

# Configure the portal
configure_portal(portal, 'Demo Portal', 'A portal used for demonstrations.')
create_basemap_gallery_group(portal, 'Demo Basemaps', copy_filter='-bing -osm')

# Create groups from CSV, then copy/share like-tagged items from arcgis online
items_to_feature = []
owner = portal.logged_in_user()['username']
groups = load_groups(portal, groups_csv, 'csv')[0]
for group in groups:
    tags = group['tags'].split(',')
    tags_expr = ' OR '.join('tags:"%s"' % tag.strip() for tag in tags)
    item_query = WEB_ITEM_FILTER + ' AND (' + tags_expr + ')'
    items = arcgisonline.search(q=item_query, num=5)
    item_id_map = copy_items(items, arcgisonline, portal, owner)
    portal.share_items(owner, item_id_map.values(), [group['id']], True, True)
    items_to_feature.append(item_id_map[items[0]['id']])

# Feature items and groups (clear_existing=True)
feature_items(portal, items_to_feature, True)
feature_groups(portal, random.sample(groups, 5), True)