def _getLinkToGranule()

in libraries/edge/opensearch/granuleatomresponse.py [0:0]


    def _getLinkToGranule(self, doc):
        attr = {}
        link = None

        if 'GranuleReference-Type' in doc and len(self.linkToGranule) > 0:
            granuleRefDict = dict(zip(doc['GranuleReference-Type'], zip(doc['GranuleReference-Path'], doc['GranuleReference-Status'])))

            for type in self.linkToGranule:
                # check if reference type exists
                if type in granuleRefDict:
                    # check if reference is online
                    if granuleRefDict[type][1] == 'ONLINE':
                        link = granuleRefDict[type][0]
                        break
            if link is not None:
                attr['rel'] = 'http://esipfed.org/ns/discovery/1.1/data#'
                attr['title'] = 'Granule File'
                
                if 'GranuleArchive-Name' in doc and 'GranuleArchive-Type' in doc and 'GranuleArchive-FileSize':
                    granuleArchiveDict  = dict(zip(doc['GranuleArchive-Type'], zip(doc['GranuleArchive-Name'], doc['GranuleArchive-FileSize']))) 
                    if link.endswith(granuleArchiveDict['DATA'][0]):
                        attr['size'] = granuleArchiveDict['DATA'][1]
                
                if 'Granule-DataFormat' in doc:
                    attr['type'] = 'application/x-' + doc['Granule-DataFormat'][0].lower()
        else:
            #No link to granule download provided so create link back to opensearch to retrieve granule metadata
            link = "http://" + self.host + "/granule/opensearch.atom?granule=" + doc['Granule-Name'][0]
        attr['href'] = link
        return attr