Created
February 19, 2013 18:20
-
-
Save wabson/4988436 to your computer and use it in GitHub Desktop.
Test code to examine CMIS relationship targetId values before and after uploading a file via Share. Requires [cmislib](https://chemistry.apache.org/python/cmislib.html) 0.5.1 or greater and the files `alfresco.sh`, `ping.py` and `MultipartPostHandler.py` from the latest version of [share-import-export](http://code.google.com/p/share-import-export/)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cmislib | |
import alfresco | |
import base64 | |
filename = '/Users/wabson/Desktop/Screen Shot 2012-11-27 at 11.50.42.png' | |
cmisurl = 'https://api.alfresco.com/cmis/versions/1.0/atom' | |
access_token = 'xxxxxxxx' # Currently active access token | |
salesforce_site = 'will-salesforce' | |
record_id = '006b0000002YoDJ' | |
shareurl = 'https://my.alfresco.com/share' | |
tenant = 'alfresco.com' | |
username = 'firstname.lastname@alfresco.com' | |
password = '123456=' #base64 encoded | |
headers = {'Authorization': 'Bearer ' + access_token} | |
client = cmislib.CmisClient(cmisurl, '', '', headers=headers) | |
repo = client.defaultRepository | |
print 'Connected to repository %s' % (repo.getRepositoryInfo()['repositoryId']) | |
source_path = '/Sites/%s/Salesforce Records/%s' % (salesforce_site, record_id) | |
source = repo.getObjectByPath(source_path, includeRelationships='source') | |
print 'Found source object with ID %s' % (source.id) | |
rels = source.getRelationships() | |
print 'Found %s relationships' % (len(rels)) | |
for r in rels.getResults(): | |
print r.targetId | |
if len(rels) > 0: | |
#print 'Fetch target item %s' % (rels.getResults()[0].targetId) | |
#doc = rels.getResults()[0].getTarget() | |
#print 'Update target item %s' % (rels.getResults()[0].targetId) | |
#doc.setContentStream(open(filename)) | |
updateNodeRef = 'workspace://SpacesStore/%s' % (rels.getResults()[0].targetId.partition(';')[0]) | |
print 'Updating nodeRef %s' % (updateNodeRef) | |
sc = alfresco.ShareClient(shareurl, debug=0, tenant=tenant) | |
print "Log in (%s)" % (username) | |
loginres = sc.doLogin(username, base64.b64decode(password)) | |
if not loginres['success']: | |
print "Could not log in using specified credentials" | |
sys.exit(1) | |
fr = sc.updateContentItem(updateNodeRef, file(filename, 'rb')) | |
print fr.read() | |
print "Log out (%s)" % (username) | |
sc.doLogout() | |
print 'Reload relationships' | |
rels.reload() | |
print 'Found %s relationships' % (len(rels)) | |
for r in rels.getResults(): | |
print r.targetId |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment