source: TI01-discovery-Ingest/trunk/v4n_MEDIN/ingestAutomation-upgrade/OAIBatch/testISO.py @ 6618

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI01-discovery-Ingest/trunk/v4n_MEDIN/ingestAutomation-upgrade/OAIBatch/testISO.py@6618
Revision 6618, 3.7 KB checked in by sdonegan, 11 years ago (diff)

Commit of code that updates successfully MEDIN ISO as well as GCMD DIF into NDG3 style postgres DB..

Line 
1from ExtractISO import ExtractISO
2import logging,os,pdb,datetime
3
4def accessIsoDataModel(struct,name):
5        cnt=0
6
7        #are we dealing with a list or dictionary?
8        if type(struct) is dict:
9                for j in struct.keys():
10                        print name + "(" + str(cnt) + "): " + j + " = " + str(struct[j])
11                        cnt = cnt + 1
12                       
13        if type(struct) is list:       
14                for i in struct:
15                        if type(i) is dict:
16                                for j in i.keys():             
17                                        print name + "(" + str(cnt) + "): " + j + " = " + str(i[j])
18                        if type(i) is list:
19                                for j in i:
20                                        print name + "(" + str(cnt) + "): " + j
21               
22                        if len(struct) > 1:
23                                print "-------------------------------"
24                       
25                        cnt = cnt + 1
26
27logging.basicConfig(level=logging.DEBUG,format='%(asctime)s %(filename)s:%(lineno)d %(levelname)s %(message)s')
28
29#test dif2stubIso xml file - converted from dif via xquery
30#dif2stubIso_file = 'data/NEODC/stub_iso/neodc.nerc.ac.uk__stubISO__dataent_11658383444211836_DIF_multiDate.xml'
31#dif2stubIso_file = 'data/NEODC/stub_iso/neodc.nerc.ac.uk__stubISO__dataent_11658383444211836_DIF_multiCoord.xml'
32#dif2stubIso_file = 'data/NEODC/stub_iso/neodc.nerc.ac.uk__stubISO__dataent_11658383444211836_DIF.xml'
33
34inputISO = 'data/MEDIN/ISO_19139_Dataset_DASSH_v1.0.xml'
35
36#test dif 2 iso
37#isoData = ExtractISO(dif2stubIso_file,'difConvertedto_ISO19139')
38
39#test medin iso extractor
40isoData = ExtractISO(inputISO,'medin_2_3_ISO19139')
41
42
43
44if isoData.createISOdataStructure() is True:
45        logging.info("ISO extractor worked fine! (here are the variables...)")
46elif isoData.createISOdataStructure() is True:
47        logging.info ("Something wrong with ISO extractor... (ExtractISO returned False: xml access problem?)")
48        sys.exit()
49else:
50        logging.info( "Something SERIOUSELY wrong with extractor (couldnt get at ExtractISO class)")
51        sys.exit()
52       
53#sys.exit()
54
55print "\nTesting for bounding dates (list of dictionaries) ..."
56name = "boundingDates"
57accessIsoDataModel(isoData.boundingDates, name)
58
59print "\nTesting for extracting start and end dates (dictionary)"
60name = "boundingDatesRange"
61
62accessIsoDataModel(isoData.boundingDatesRange,name)
63
64print "\nTesting for datasetID (List)..."
65name = "datasetID"
66accessIsoDataModel(isoData.datasetID, name)
67
68print "\nTesting for keywords (List)..."
69name = "keywords"
70accessIsoDataModel(isoData.keywords, name)
71
72print "\nTesting for revision date (List)..."
73name = "revisionDate"
74accessIsoDataModel(isoData.revisionDate, name)
75
76print "\nTesting for creation date (List) ..."
77name = "createDate"
78accessIsoDataModel(isoData.createDate, name)
79
80print "\nTesting for publication date (List) ..."
81name = "publicationDate"
82accessIsoDataModel(isoData.publicationDate, name)
83       
84print "\nTesting for dataset name (List) ..."
85name = "datasetName"
86accessIsoDataModel(isoData.datasetName, name)
87
88print "\nTesting for dataset abstract (List) ..."
89name = "datasetAbstract"
90accessIsoDataModel(isoData.datasetAbstract, name)
91               
92print "\nTesting for original format (List) ..."
93name = "originalFormat"
94accessIsoDataModel(isoData.originalFormat, name)
95       
96print "\nTesting for authors (List) ..."
97name = "authors"
98
99accessIsoDataModel(isoData.authors, name)
100               
101print "\nTesting for data centre name (List) ..."
102name = "datacentreName"
103accessIsoDataModel(isoData.datacentreName, name)
104       
105print "\nTesting for parameters (List) ..."
106name = "parameters"
107accessIsoDataModel(isoData.parameters, name)
108       
109print "\nTesting for data centre name (list of dictionaries) ..."
110name = "boundingBoxCoordinates"
111accessIsoDataModel(isoData.boundingBoxCoordinates, name)
112
113print "\nConverting relevant URLS to NDG redirect URL!"
114if isoData.generateNDGredirectURL("http://scooby.dooby.doo/redirect=","./theRedirectedOutput.xml"):
115        print "Successfully generated redirect url xml!!"
116else:
117        print "Unsuccessfully tried to rewrite urls with ndg redirect url!"
Note: See TracBrowser for help on using the repository browser.