Closed tpcolson closed 8 years ago
When you add an item, the functionality already exists to place items into folders and to set sharing.
Sharing cannot be set until an item is added. When you successfully add an item, addItem() returns an object of that item. When you obtain that object, call the share() on Item.
As for setting folders, this is done by switching the currentFolder property to the folder you wish place the item. Example:
myuser = content.users.user("tpcolson")
myuser.currentFolder = "randomFolder"
item = myuser.addItem(parameters....,)
item.share(<share arguments>)
The item is added to the folder "randomFolder" and shared as needed.
To speed up your tasks, try mutliprocessing or multi-threading the calls to AGOL if speed is an issue. With these functions, you have situation where you do something... wait... do something else... then wait... etc etc etc... Lots of waiting...
You can take advantages of Pythons multiprocessing at 2.7/3.4 or concurrent.futures at 3.4 or even threading (doesn't work in arcmap though because arcpy isn't thread safe). This will split up the uploads and should make things run faster.
Hi thanks for the quick reply! I got the folder designation working pretty easily, but I'm drawing a blank on the share arguments. I've tried
item.share = "group guid"
and
item.share = "group name"
both before and after
print (user.addItem(itemParameters=itemParams,
overwrite=True,
text=json.dumps(map_json)))
which outputs
..."sharing": {"access": "private", "groups": []}}
as well as the item.id further up.
Here is some code that might help you
groupNames = ['group1','group2'] admin = arcrest.manageorg.Administration(securityHandler=securityhandler) content = admin.content userInfo = content.users.user() userCommunity = admin.community group_ids = userCommunity.getGroupIDs(groupNames=groupNames) shareResults = userInfo.shareItems(items=item.id, groups=','.join(group_ids), everyone=everyone, org=org)
Thanks for the hint Mike! Based on your example, here's what I came up with:
groupNames = ['Some Group','Another Group']
securityHandler = arcrest.AGOLTokenSecurityHandler(username,
password)
# Create the administration connection
#
admin = arcrest.manageorg.Administration(url, securityHandler)
# Access the content properties to add the item
#
content = admin.content
# Get the user
#
user = content.users.user()
userCommunity = admin.community
group_ids = userCommunity.getGroupIDs(groupNames=groupNames)
shareResults = user.shareItems(items=item.id,
groups=','.join(group_ids),
everyone=everyone,
org=org)
# Provide the item parameters
#
itemParams = arcrest.manageorg.ItemParameter()
itemParams.title = "ABCD"
itemParams.thumbnailurl = ""
itemParams.type = "Web Map"
itemParams.snippet = "A Great map"
itemParams.licenseInfo = "Blah Blah Blah"
itemParams.accessInformation = "A great organization"
itemParams.tags = "Some tags"
itemParams.description = "Woo Hoo"
itemParams.extent = "-84.1076,35.2814,-82.9795, 35.8366"
user.currentFolder = "Species"
# Add the Web Map
#
print (user.addItem(itemParameters=itemParams,
overwrite=True,
text=json.dumps(map_json)))
Which give me the error
shareResults = user.shareItems(items=item.id,
NameError: name 'item' is not defined
So how do I pass the item.id to the addItem call?
you need to add the item before sharing it. Get the item id from the result of addItem
Thanks again Mike. I'm wracking my head trying to figure out how to call the item id from addItem.
In
print (user.addItem(itemParameters=itemParams,
overwrite=True,
text=json.dumps(map_json)))
shareResults = user.shareItems(items=json.dumps(map_json).item.id,
groups=','.join(group_ids),
everyone=everyone,
org=org)
I've replaced json.dumps(map_json).
with just about every variable I can think of...missing something obvious here....
change print (user.addItem(itemParameters=itemParams... to item = user.addItem(itemParameters=itemParams...
This should return the item or information about the item. From here you can get the item id
Thank a bunch Mike for your patient help!
Here's what finally ended up working:
item = user.addItem(itemParameters=itemParams,
overwrite=True,
text=json.dumps(map_json))
userInfo = content.users.user()
userCommunity = admin.community
group_ids = userCommunity.getGroupIDs(groupNames=groupNames)
shareResults = userInfo.shareItems(items=item.id,
groups=','.join(group_ids),
everyone = True,
org = True)
This is an enhancement request to modify arcrest.manageorg.parameters module to allow specification of owner folder and sharing (group) id's when, for example, using https://github.com/Esri/ArcREST/blob/master/samples/additem_webmap_sample.py to batch create web map items. Would be handy to have a CSV file that allows in-line variable substitution that contains a folder that the item goes into, and what group(s) it's shared with. I've got the batch-from-csv part figured out, but moving 1000+ maps and sharing them with various groups sure is tedious.....