Пример #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
Пример #2
0
 def testUpdateReferenceTime(self):
     try:
         startUpdateValue = '1940-01-01'
         endUpdateValue = '1940-12-31'
         tmpDirectory = tempfile.mkdtemp('', 'tmp_', TEMPLATE_FILES['tmp_dir'])
         mdFile = createTemporaryCopy(TEMPLATE_FILES['child'], tmpDirectory)
         mdEditor = ChildMetadataBinding(mdFile, self.logger)
         response = mdEditor.updateReferenceTime(startUpdateValue, endUpdateValue)
         self.assertTrue(response, 'Function: testUpdateReferenceTime - Response is not like expected.')
         
         # check if value is correctly set
         temporalExtentElement = mdEditor.__getChildElement__(parentElementId=mdEditor.ns['gmd']+'identificationInfo', childElementId=mdEditor.ns['gmd']+'EX_TemporalExtent')
         # test startUpdateValue
         for element in temporalExtentElement.iter(mdEditor.ns['gml']+'begin'):
             timeInstant = element.find(mdEditor.ns['gml']+'TimeInstant')
             timePosition = timeInstant.find(mdEditor.ns['gml']+'timePosition')                
             self.assertEqual(startUpdateValue,timePosition.text, 'Function: testUpdateReferenceTime - Response is not equal to the expected response.')
 
         # test endUpdateValue
         for element in temporalExtentElement.iter(mdEditor.ns['gml']+'end'):
             timeInstant = element.find(mdEditor.ns['gml']+'TimeInstant')
             timePosition = timeInstant.find(mdEditor.ns['gml']+'timePosition')
             self.assertEqual(endUpdateValue,timePosition.text, 'Function: testUpdateReferenceTime - Response is not equal to the expected response.')
     except:
         raise
     finally:
         shutil.rmtree(tmpDirectory)
Пример #3
0
    def testUpdateReferenceTime(self):
        try:
            startUpdateValue = "1940-01-01"
            endUpdateValue = "1940-12-31"
            tmpDirectory = tempfile.mkdtemp("", "tmp_", TEMPLATE_FILES["tmp_dir"])
            mdFile = createTemporaryCopy(TEMPLATE_FILES["child"], tmpDirectory)
            mdEditor = ChildMetadataBinding(mdFile, self.logger)
            response = mdEditor.updateReferenceTime(startUpdateValue, endUpdateValue)
            self.assertTrue(response, "Function: testUpdateReferenceTime - Response is not like expected.")

            # check if value is correctly set
            temporalExtentElement = mdEditor.__getChildElement__(
                parentElementId=mdEditor.ns["gmd"] + "identificationInfo",
                childElementId=mdEditor.ns["gmd"] + "EX_TemporalExtent",
            )
            # test startUpdateValue
            for element in temporalExtentElement.iter(mdEditor.ns["gml"] + "begin"):
                timeInstant = element.find(mdEditor.ns["gml"] + "TimeInstant")
                timePosition = timeInstant.find(mdEditor.ns["gml"] + "timePosition")
                self.assertEqual(
                    startUpdateValue,
                    timePosition.text,
                    "Function: testUpdateReferenceTime - Response is not equal to the expected response.",
                )

            # test endUpdateValue
            for element in temporalExtentElement.iter(mdEditor.ns["gml"] + "end"):
                timeInstant = element.find(mdEditor.ns["gml"] + "TimeInstant")
                timePosition = timeInstant.find(mdEditor.ns["gml"] + "timePosition")
                self.assertEqual(
                    endUpdateValue,
                    timePosition.text,
                    "Function: testUpdateReferenceTime - Response is not equal to the expected response.",
                )
        except:
            raise
        finally:
            shutil.rmtree(tmpDirectory)