Exemplo n.º 1
0
def updateMetadata(file, metadata, logger):
    try:
        logger.debug('Start updating the metadata in the xml file %s'%file)
        mdEditor = ChildMetadataBinding(file, logger)
        mdEditor.updateId(metadata['identifier'])
        mdEditor.updateTitle(metadata['title'])
        mdEditor.updateAbstract(metadata['abstract'])
        mdEditor.updateHierarchyLevelName(metadata['hierarchylevel'])
        mdEditor.updateBoundingBox(metadata['westBoundLongitude'], metadata['eastBoundLongitude'], 
                                   metadata['southBoundLatitude'], metadata['northBoundLatitude'])
        mdEditor.updateDateStamp(metadata['dateStamp'])
        mdEditor.updateReferenceTime(metadata['temporalExtent_begin'], metadata['temporalExtent_end'])
        mdEditor.updateReferenceDate(metadata['cite_date'])
        mdEditor.updateGraphicOverview(metadata['overviews'])
        mdEditor.updateIdCode(metadata['identifier'])
        mdEditor.updateOnlineResource(metadata['onlineresource'])
        
        print '============================'
        print mdEditor.tostring()
        print '============================'
        
        mdEditor.saveFile(file)
        return True
    except:
        logger.error('Problems while updating the metadata for the xml file %s'%file)
        raise
Exemplo n.º 2
0
    def testUpdateOnlineResource(self):
        try:
            updateValue = [
                {
                    "url": "http://kartenforum.slub-dresden.de/vkviewer/permalink?objectid=",
                    "protocol": "HTTP",
                    "name": "Permalink",
                },
                {"url": "testWMS", "protocol": "OGC:WMS-1.1.1-http-get-map", "name": "WEB MAP SERVICE (WMS)"},
                {"url": "testperma", "protocol": "HTTP", "name": "Permalink"},
            ]

            tmpDirectory = tempfile.mkdtemp("", "tmp_", TEMPLATE_FILES["tmp_dir"])
            mdFile = createTemporaryCopy(TEMPLATE_FILES["child"], tmpDirectory)
            mdEditor = ChildMetadataBinding(mdFile, self.logger)
            response = mdEditor.updateOnlineResource(updateValue)
            self.assertTrue(response, "Function: testUpdatePermalink - Response is not like expected.")

            # check if value is correctly set
            """digitalTransferOptionsElement = mdEditor.__getChildElement__(parentElementId=mdEditor.ns['gmd']+'distributionInfo', 
                        childElementId=mdEditor.ns['gmd']+'MD_DigitalTransferOptions')
            for element in digitalTransferOptionsElement.iter(mdEditor.ns['gmd']+'linkage'):
                valueElement = element.find(mdEditor.ns['gmd']+'URL')
                self.assertEqual(updateValue,valueElement.text, 'Function: testUpdatePermalink - Response is not equal to the expected response.')"""
        except:
            raise
        finally:
            shutil.rmtree(tmpDirectory)
Exemplo n.º 3
0
    def testUpdateOnlineResource(self):
        try:
            updateValue = [{
                'url':
                'http://kartenforum.slub-dresden.de/vkviewer/permalink?objectid=',
                'protocol': 'HTTP',
                'name': 'Permalink'
            }, {
                'url': 'testWMS',
                'protocol': 'OGC:WMS-1.1.1-http-get-map',
                'name': 'WEB MAP SERVICE (WMS)'
            }, {
                'url': 'testperma',
                'protocol': 'HTTP',
                'name': 'Permalink'
            }]

            tmpDirectory = tempfile.mkdtemp('', 'tmp_',
                                            TEMPLATE_FILES['tmp_dir'])
            mdFile = createTemporaryCopy(TEMPLATE_FILES['child'], tmpDirectory)
            mdEditor = ChildMetadataBinding(mdFile, self.logger)
            response = mdEditor.updateOnlineResource(updateValue)
            self.assertTrue(
                response,
                'Function: testUpdatePermalink - Response is not like expected.'
            )

            # check if value is correctly set
            '''digitalTransferOptionsElement = mdEditor.__getChildElement__(parentElementId=mdEditor.ns['gmd']+'distributionInfo', 
                        childElementId=mdEditor.ns['gmd']+'MD_DigitalTransferOptions')
            for element in digitalTransferOptionsElement.iter(mdEditor.ns['gmd']+'linkage'):
                valueElement = element.find(mdEditor.ns['gmd']+'URL')
                self.assertEqual(updateValue,valueElement.text, 'Function: testUpdatePermalink - Response is not equal to the expected response.')'''
        except:
            raise
        finally:
            shutil.rmtree(tmpDirectory)
Exemplo n.º 4
0
 def testUpdateOnlineResource(self):
     try:
         updateValue = [
             {
                 'url':'http://kartenforum.slub-dresden.de/vkviewer/permalink?objectid=',
                 'protocol':'HTTP',
                 'name':'Permalink'
             },
             {
                 'url':'testWMS',
                 'protocol':'OGC:WMS-1.1.1-http-get-map',
                 'name':'WEB MAP SERVICE (WMS)'
             },
             {
                 'url':'testperma',
                 'protocol':'HTTP',
                 'name':'Permalink'
             }                        
         ]           
         
         tmpDirectory = tempfile.mkdtemp('', 'tmp_', TEMPLATE_FILES['tmp_dir'])
         mdFile = createTemporaryCopy(TEMPLATE_FILES['child'], tmpDirectory)
         mdEditor = ChildMetadataBinding(mdFile, self.logger)
         response = mdEditor.updateOnlineResource(updateValue)
         self.assertTrue(response, 'Function: testUpdatePermalink - Response is not like expected.')
         
         # check if value is correctly set
         '''digitalTransferOptionsElement = mdEditor.__getChildElement__(parentElementId=mdEditor.ns['gmd']+'distributionInfo', 
                     childElementId=mdEditor.ns['gmd']+'MD_DigitalTransferOptions')
         for element in digitalTransferOptionsElement.iter(mdEditor.ns['gmd']+'linkage'):
             valueElement = element.find(mdEditor.ns['gmd']+'URL')
             self.assertEqual(updateValue,valueElement.text, 'Function: testUpdatePermalink - Response is not equal to the expected response.')'''
     except:
         raise
     finally:
         shutil.rmtree(tmpDirectory)