def __init__(self, PID, DS, key=None, token=None, download=False): # object and datastream self.PID = PID self.DS = DS self.unique_id = hashlib.md5(PID+DS).hexdigest() # auth, key, token access self.key = key self.token = token self.return_token = None # response params self.msg = None self.status_code = None self.download = download # stream params self.chunk_step = 1024 # instantiate object self.obj_handle = fedora_handle.get_object(self.PID) self.obj_ds_handle = self.obj_handle.getDatastreamObject(self.DS) # determine auth try: self.auth = self._determine_auth() except Exception, e: print e self.msg = "authorization failed" self.status_code = 500 self.auth = False
def retrieveManifest(identifier, getParams, request): """ genIIIFManifest() is a function built-in to each content-type. In an effort to reduce how many times these manifests are generated, this function now tries to retreive from stored datastream first. If not there, runs object method to generate, then tries again. """ # check for IIIF manifest datastream ohandle = fedora_handle.get_object(identifier) if "IIIF_MANIFEST" in ohandle.ds_list: print "manifest located and retrieved from Redis" return ohandle.getDatastreamObject("IIIF_MANIFEST").content else: print "generating manifest, storing as datastream, returning" obj = WSUDOR_ContentTypes.WSUDOR_Object(identifier) # fire content-type defined manifest generation return obj.genIIIFManifest()
def genAllTokens(cls, PID, key): ''' This function generates bitStream tokens for ALL datastreams for an object ''' # if key and key match if key == localConfig.BITSTREAM_KEY: print "generating all bitStream tokens..." # return dict response_dict = {} # init object handle obj_handle = fedora_handle.get_object(PID) # generate tokens for each datastream using BitStream instance for DS in obj_handle.ds_list: try: bs = cls(PID, DS, key=key, token='request') response_dict[DS] = { "token":bs.msg['token'], "url":bs.msg['url'] } except: print "could not generate bitstream for %s" % DS response_dict[DS] = { 'msg': "could not generate bitstream for %s" % DS } return response_dict else: print "bitstream key not recognized" return False
def downsizeImage(pid, ds, ic): ''' If collection is flagged for downsizing, downsize downloadable image to target size pixels on long or short side see: http://iiif.io/api/image/2.0/#size Improvements: We should pull target resolution size from colletion object Or policy? ''' ######################################################################################################################## # RDF based ######################################################################################################################## target_resolution = 700 restricted_collections = [ 'wayne:collectionvmc', 'wayne:collectionUniversityBuildings' ] restricted_status = False collections = [ o for s,p,o in fedora_handle.get_object(pid).rels_ext.content if p == rdflib.term.URIRef(u'info:fedora/fedora-system:def/relations-external#isMemberOfCollection') ] for c in collections: if c.split("info:fedora/")[1] in restricted_collections: restricted_status = True break ######################################################################################################################## if restricted_status: downsize = False # derive size request size_d = ic.size.as_dict() print size_d # full requested if size_d['full']: downsize = True # percent requested # retrieve info.json and see if percent would exceed size restrictions if size_d['percent']: r = requests.get(ic.info()).json() if ((r['width'] * float(size_d['percent']) / 100) >= target_resolution) or ((r['height'] * float(size_d['percent']) / 100) >= target_resolution): downsize = True # specific size requested if size_d['width'] >= target_resolution or size_d['height'] >= target_resolution: downsize = True # downsize if triggered if downsize: print "downsizing from %s to !%s,%s for Reuther" % (ic.size.as_dict(), target_resolution, target_resolution) ic.size.set_options( width=target_resolution, height=target_resolution, exact=True ) return ic