def uploadtricoder(tricoderElements, config):
    try:
        realm = config.get('connect', 'realm')
        hostname = config.get('connect', 'hostname')
        username = config.get('connect', 'username')
        password = config.get('connect', 'password')
        INSTITUTION = config.get('info', 'institution')
    except:
        loginfo('uploadtricoder', "could not get at least one of realm, hostname, username, password or institution from config file.", {}, {})
        # loginfo('uploadtricoder', "can't continue, exiting...", {}, {})
        raise

    objectCSID = getCSID('objectnumber', tricoderElements['objectnumber'], config)
    if objectCSID == [] or objectCSID is None:
        loginfo('uploadtricoder', "could not get (i.e. find) objectnumber's csid: %s." % tricoderElements['objectnumber'], {}, {})
        # raise Exception("<span style='color:red'>Object Number not found: %s!</span>" % tricoderElements['objectnumber'])
        #raise
    else:
        objectCSID = objectCSID[0]
        tricoderElements['objectCSID'] = objectCSID

        updateItems = {'objectStatus': 'found',
                       'subjectCsid': '',
                       'objectCsid': tricoderElements['objectCSID'],
                       'objectNumber': tricoderElements['objectnumber'],
                       'imageNumber': tricoderElements['imagenumber'],
                       'blobCsid': tricoderElements['blobCSID'],
                       'name': tricoderElements['name'],
                       'rightsHolderRefname': tricoderElements['rightsholder'],
                       'contributor': tricoderElements['contributor'],
                       'creator': tricoderElements['creator'],
                       'tricoderDate': tricoderElements['date'],
        }

        uri = 'tricoder'

        messages = []
        messages.append("posting to tricoder REST API...")
        # loginfo('uploadtricoder', updateItems, {}, {})
        payload = tricoderPayload(updateItems, INSTITUTION)
        messages.append(payload)
        messages.append(payload)
        (url, data, tricoderCSID, elapsedtime) = postxml('POST', uri, realm, hostname, username, password, payload)
        #elapsedtimetotal += elapsedtime
        messages.append('got tricodercsid %s elapsedtime %s ' % (tricoderCSID, elapsedtime))
        tricoderElements['tricoderCSID'] = tricoderCSID
        messages.append("tricoder REST API post succeeded...")

        # now relate tricoder record to collection object

        uri = 'relations'

        messages.append("posting tricoder2obj to relations REST API...")

        updateItems['objectCsid'] = objectCSID
        updateItems['subjectCsid'] = tricoderCSID
        # "urn:cspace:INSTITUTION.cspace.berkeley.edu:tricoder:id(%s)" % tricoderCSID

        updateItems['objectDocumentType'] = 'CollectionObject'
        updateItems['subjectDocumentType'] = 'Media'

        payload = relationsPayload(updateItems)
        (url, data, csid, elapsedtime) = postxml('POST', uri, realm, hostname, username, password, payload)
        #elapsedtimetotal += elapsedtime
        messages.append('got relation csid %s elapsedtime %s ' % (csid, elapsedtime))
        tricoderElements['tricoder2objCSID'] = csid
        messages.append("relations REST API post succeeded...")

        # reverse the roles
        messages.append("posting obj2tricoder to relations REST API...")
        temp = updateItems['objectCsid']
        updateItems['objectCsid'] = updateItems['subjectCsid']
        updateItems['subjectCsid'] = temp
        updateItems['objectDocumentType'] = 'Media'
        updateItems['subjectDocumentType'] = 'CollectionObject'
        payload = relationsPayload(updateItems)
        (url, data, csid, elapsedtime) = postxml('POST', uri, realm, hostname, username, password, payload)
        #elapsedtimetotal += elapsedtime
        messages.append('got relation csid %s elapsedtime %s ' % (csid, elapsedtime))
        tricoderElements['obj2tricoderCSID'] = csid
        messages.append("relations REST API post succeeded...")

    return tricoderElements
Esempio n. 2
0
def uploadmedia(mediaElements, config):
    try:
        realm = config.get('connect', 'realm')
        hostname = config.get('connect', 'hostname')
        username = config.get('connect', 'username')
        password = config.get('connect', 'password')
        INSTITUTION = config.get('info', 'institution')
    except:
        print "could not get at least one of realm, hostname, username, password or institution from config file."
        # print "can't continue, exiting..."
        raise

    objectCSID = getCSID('objectnumber', mediaElements['objectnumber'], config)
    if objectCSID == [] or objectCSID is None:
        print "could not get (i.e. find) objectnumber's csid: %s." % mediaElements['objectnumber']
        # raise Exception("<span style='color:red'>Object Number not found: %s!</span>" % mediaElements['objectnumber'])
        #raise
    else:
        objectCSID = objectCSID[0]
        mediaElements['objectCSID'] = objectCSID

        updateItems = {'objectStatus': 'found',
                       'subjectCsid': '',
                       'objectCsid': mediaElements['objectCSID'],
                       'objectNumber': mediaElements['objectnumber'],
                       'imageNumber': mediaElements['imagenumber'],
                       'blobCsid': mediaElements['blobCSID'],
                       'name': mediaElements['name'],
                       'rightsHolderRefname': mediaElements['rightsholder'],
                       'contributor': mediaElements['contributor'],
                       'creator': mediaElements['creator'],
                       'mediaDate': mediaElements['date'],
        }

        uri = 'media'

        messages = []
        messages.append("posting to media REST API...")
        # print updateItems
        payload = mediaPayload(updateItems, INSTITUTION)
        messages.append(payload)
        messages.append(payload)
        (url, data, mediaCSID, elapsedtime) = postxml('POST', uri, realm, hostname, username, password, payload)
        #elapsedtimetotal += elapsedtime
        messages.append('got mediacsid %s elapsedtime %s ' % (mediaCSID, elapsedtime))
        mediaElements['mediaCSID'] = mediaCSID
        messages.append("media REST API post succeeded...")

        # now relate media record to collection object

        uri = 'relations'

        messages.append("posting media2obj to relations REST API...")

        updateItems['objectCsid'] = objectCSID
        updateItems['subjectCsid'] = mediaCSID
        # "urn:cspace:INSTITUTION.cspace.berkeley.edu:media:id(%s)" % mediaCSID

        updateItems['objectDocumentType'] = 'CollectionObject'
        updateItems['subjectDocumentType'] = 'Media'

        payload = relationsPayload(updateItems)
        (url, data, csid, elapsedtime) = postxml('POST', uri, realm, hostname, username, password, payload)
        #elapsedtimetotal += elapsedtime
        messages.append('got relation csid %s elapsedtime %s ' % (csid, elapsedtime))
        mediaElements['media2objCSID'] = csid
        messages.append("relations REST API post succeeded...")

        # reverse the roles
        messages.append("posting obj2media to relations REST API...")
        temp = updateItems['objectCsid']
        updateItems['objectCsid'] = updateItems['subjectCsid']
        updateItems['subjectCsid'] = temp
        updateItems['objectDocumentType'] = 'Media'
        updateItems['subjectDocumentType'] = 'CollectionObject'
        payload = relationsPayload(updateItems)
        (url, data, csid, elapsedtime) = postxml('POST', uri, realm, hostname, username, password, payload)
        #elapsedtimetotal += elapsedtime
        messages.append('got relation csid %s elapsedtime %s ' % (csid, elapsedtime))
        mediaElements['obj2mediaCSID'] = csid
        messages.append("relations REST API post succeeded...")

    return mediaElements
Esempio n. 3
0
def uploadmedia(mediaElements, config):
    try:
        realm = config.get('connect', 'realm')
        hostname = config.get('connect', 'hostname')
        username = config.get('connect', 'username')
        password = config.get('connect', 'password')
    except:
        print "could not get config."
        raise

    objectCSID = getCSID('objectnumber', mediaElements['objectnumber'], config)
    if objectCSID == [] or objectCSID is None:
        print "could not get objectnumber's csid: %s." % mediaElements['objectnumber']
        raise
        #raise Exception("<span style='color:red'>Object Number not found: %s!</span>" % mediaElements['objectnumber'])
    else:
        objectCSID = objectCSID[0]
        mediaElements['objectCSID'] = objectCSID

        updateItems = {'objectStatus': 'found',
                       'subjectCsid': '',
                       'objectCsid': mediaElements['objectCSID'],
                       'objectNumber': mediaElements['objectnumber'],
                       'blobCsid': mediaElements['blobCSID'],
                       'rightsHolderRefname': mediaElements['rightsholder'],
                       'contributor': mediaElements['contributor'],
                       'creator': mediaElements['creator'],
                       'mediaDate': mediaElements['date'],
        }

        uri = 'media'

        #print "<br>posting to media REST API..."
        payload = mediaPayload(updateItems)
        (url, data, mediaCSID, elapsedtime) = postxml('POST', uri, realm, hostname, username, password, payload)
        #elapsedtimetotal += elapsedtime
        #print 'got mediacsid', mediaCSID, '. elapsedtime', elapsedtime
        mediaElements['mediaCSID'] = mediaCSID
        #print "media REST API post succeeded..."

        # now relate media record to collection object

        uri = 'relations'

        #print "<br>posting media2obj to relations REST API..."

        updateItems['objectCsid'] = objectCSID
        updateItems['subjectCsid'] = mediaCSID
        # "urn:cspace:pahma.cspace.berkeley.edu:media:id(%s)" % mediaCSID

        updateItems['objectDocumentType'] = 'CollectionObject'
        updateItems['subjectDocumentType'] = 'Media'

        payload = relationsPayload(updateItems)
        (url, data, csid, elapsedtime) = postxml('POST', uri, realm, hostname, username, password, payload)
        #elapsedtimetotal += elapsedtime
        #print 'got relation csid', csid, '. elapsedtime', elapsedtime
        mediaElements['media2objCSID'] = csid
        #print "relations REST API post succeeded..."

        # reverse the roles
        #print "<br>posting obj2media to relations REST API..."
        temp = updateItems['objectCsid']
        updateItems['objectCsid'] = updateItems['subjectCsid']
        updateItems['subjectCsid'] = temp
        updateItems['objectDocumentType'] = 'Media'
        updateItems['subjectDocumentType'] = 'CollectionObject'
        payload = relationsPayload(updateItems)
        (url, data, csid, elapsedtime) = postxml('POST', uri, realm, hostname, username, password, payload)
        #elapsedtimetotal += elapsedtime
        #print 'got relation csid', csid, '. elapsedtime', elapsedtime
        mediaElements['obj2mediaCSID'] = csid
        #print "relations REST API post succeeded..."

    return mediaElements