Esempio 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
Esempio n. 2
0
    def testUpdateReferenceDate(self):
        try:
            updateValue = '1940'
            tmpDirectory = tempfile.mkdtemp('', 'tmp_',
                                            TEMPLATE_FILES['tmp_dir'])
            mdFile = createTemporaryCopy(TEMPLATE_FILES['child'], tmpDirectory)
            mdEditor = ChildMetadataBinding(mdFile, self.logger)
            response = mdEditor.updateReferenceDate(updateValue)
            self.assertTrue(
                response,
                'Function: testUpdateReferenceDate - Response is not like expected.'
            )

            # check if value is correctly set
            for element in mdEditor.root.iter(mdEditor.ns['gmd'] + 'CI_Date'):
                self.logger.debug(
                    'Element for identifier <gmd:CI_Date> founded.')
                dateElement = element.find(mdEditor.ns['gmd'] + 'date')
                valueElement = dateElement.find(mdEditor.ns['gco'] + 'Date')
                self.assertEqual(
                    updateValue, valueElement.text,
                    'Function: testUpdateReferenceDate - Response is not equal to the expected response.'
                )
        except:
            raise
        finally:
            shutil.rmtree(tmpDirectory)
Esempio n. 3
0
 def testUpdateReferenceDate(self):
     try:
         updateValue = '1940'
         tmpDirectory = tempfile.mkdtemp('', 'tmp_', TEMPLATE_FILES['tmp_dir'])
         mdFile = createTemporaryCopy(TEMPLATE_FILES['child'], tmpDirectory)
         mdEditor = ChildMetadataBinding(mdFile, self.logger)
         response = mdEditor.updateReferenceDate(updateValue)
         self.assertTrue(response, 'Function: testUpdateReferenceDate - Response is not like expected.')
         
         # check if value is correctly set
         for element in mdEditor.root.iter(mdEditor.ns['gmd']+'CI_Date' ):
             self.logger.debug('Element for identifier <gmd:CI_Date> founded.')
             dateElement = element.find(mdEditor.ns['gmd']+'date')
             valueElement = dateElement.find(mdEditor.ns['gco']+'Date')
             self.assertEqual(updateValue,valueElement.text, 'Function: testUpdateReferenceDate - Response is not equal to the expected response.')
     except:
         raise
     finally:
         shutil.rmtree(tmpDirectory)
    def testUpdateReferenceDate(self):
        try:
            updateValue = "1940"
            tmpDirectory = tempfile.mkdtemp("", "tmp_", TEMPLATE_FILES["tmp_dir"])
            mdFile = createTemporaryCopy(TEMPLATE_FILES["child"], tmpDirectory)
            mdEditor = ChildMetadataBinding(mdFile, self.logger)
            response = mdEditor.updateReferenceDate(updateValue)
            self.assertTrue(response, "Function: testUpdateReferenceDate - Response is not like expected.")

            # check if value is correctly set
            for element in mdEditor.root.iter(mdEditor.ns["gmd"] + "CI_Date"):
                self.logger.debug("Element for identifier <gmd:CI_Date> founded.")
                dateElement = element.find(mdEditor.ns["gmd"] + "date")
                valueElement = dateElement.find(mdEditor.ns["gco"] + "Date")
                self.assertEqual(
                    updateValue,
                    valueElement.text,
                    "Function: testUpdateReferenceDate - Response is not equal to the expected response.",
                )
        except:
            raise
        finally:
            shutil.rmtree(tmpDirectory)