source: exist/branches/proglue_production_rev4605_xquery4884/xquery/atom2DIF.xq @ 4886

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/exist/branches/proglue_production_rev4605_xquery4884/xquery/atom2DIF.xq@4886
Revision 4886, 8.4 KB checked in by sdonegan, 10 years ago (diff)

Creating operational branch for ndgUtils as used on proglue

Line 
1declare default element namespace 'http://gcmd.gsfc.nasa.gov/Aboutus/xml/dif/';
2declare namespace atom = 'http://www.w3.org/2005/Atom';
3declare namespace dif = 'http://gcmd.gsfc.nasa.gov/Aboutus/xml/dif/';
4declare namespace xsi='http://www.w3.org/2001/XMLSchema-instance';
5declare namespace moles="http://ndg.nerc.ac.uk/schema/moles2alpha";
6declare namespace f='http://ndg.nerc.ac.uk/moles/localfunctions';
7declare namespace georss = "http://www.georss.org/georss";
8declare namespace gml = "http://www.opengis.net/gml";
9declare namespace fn = "http://www.w3.org/2005/02/xpath-functions";
10
11(: Keep this in official lib version
12declare variable $targetCollection as xs:string := '/db/atoms/Published';
13declare variable $deploymentsDir as xs:string := '/deployments';
14declare variable $dataEntitiesDir as xs:string := '/data_entities';
15declare variable $repositoryIdentifier as xs:string := 'badc.nerc.ac.uk';
16declare variable $localIdentifier as xs:string := 'dataent_active';
17declare variable $dptTerm as xs:string := 'DPTTerm';
18declare variable $obsTerm as xs:string :=  'OBSTerm';
19declare variable $activityTerm as xs:string :=  'ACTIVITYTerm';
20declare variable $uriTerm as xs:string :=  'URITerm';
21declare variable $granuleTerm as xs:string :=  'GranuleTerm';
22:)
23
24declare variable $targetCollection as xs:string := 'TargetCollection';
25declare variable $repositoryIdentifier as xs:string := 'RepositoryID';
26declare variable $localIdentifier as xs:string := 'LocalID';
27declare variable $dptTerm as xs:string := 'DPT - NOT YET SET UP/None/DPT';
28declare variable $obsTerm as xs:string :=  'OBS - NOT YET SET UP/None/OBS';
29declare variable $activityTerm as xs:string :=  'Activity - NOT YET SET UP/None/ACTIVITY';
30declare variable $granuleTerm as xs:string :=  'GRAN - NOT YET SET UP/None/GRANULE';
31declare variable $deploymentTerm as xs:string := 'NOT YET SET UP/None/Deployment';
32declare variable $uriTerm as xs:string :=  'URI';
33
34(: These two are unlikely to change :)
35declare variable $dataEntitiesDir as xs:string := 'data_entities';
36declare variable $deploymentsDir as xs:string := 'deployments';
37declare variable $deploymentDataDir as xs:string := 'deployment_data';
38
39for $DE in collection(string-join(($targetCollection, $dataEntitiesDir, $repositoryIdentifier), '/'))/atom:entry[matches(atom:id, concat('__ATOM__',$localIdentifier,'$'))]
40return
41element DIF {
42        attribute xsi:schemaLocation {'http://gcmd.gsfc.nasa.gov/Aboutus/xml/dif/ http://gcmd.gsfc.nasa.gov/Aboutus/xml/dif/dif_v9.4.xsd'},
43        element Entry_ID {concat(string($DE/moles:entity/moles:molesISO/moles:providerID),':DIF:', tokenize(string($DE/atom:id), '__ATOM__')[2])},
44        element Entry_Title {string($DE/atom:title)},
45        element Data_Set_Citation {
46            element Dataset_Creator {string($DE/atom:author/atom:name)},
47            element Dataset_Title {string($DE/atom:title)},
48            element Dataset_Publisher {string($DE/moles:entity/moles:molesISO/moles:providerID)}
49        },
50        element Personnel {
51            element Role {''},
52            element Last_Name {''}
53        },
54        element Discipline { element Discipline_Name {''} },
55        for $category in ($DE/atom:category)
56        return
57                element Parameters {
58                        element Category {'Earth Science'},
59                element Topic {string-join((data($category/@scheme), data($category/@term)), '---')},
60                        element Term {data($category/@label)}
61                        },
62
63   (:Top level loop over all link data in the atom that refers to deployment atoms:)
64   (: NB, slightly convoluted way of doing things to avoid item duplication :)
65        for $val in distinct-values(
66                for $deploymentID in data($DE/atom:link[@rel = $deploymentTerm]/@href)
67        return
68        (:Now look up these deployment atoms and retrieve their links - removing duplicates:)
69        for $href in (data(collection(string-join(($targetCollection, $deploymentsDir), '/'))/atom:entry[atom:link[@href = $deploymentID] and atom:category[@label = 'Deployment']]/atom:link[@rel = $dptTerm]/@href))
70                return
71                                $href
72                        )
73        return
74                for $atom in (collection(string-join(($targetCollection, $deploymentDataDir), '/'))/atom:entry[atom:link[@href = $val]])
75                return
76                    element Sensor_Name {
77                        element Short_Name {data($atom/moles:entity/moles:molesISO/moles:abbreviation)},
78                        element Long_Name {data($atom/atom:title)}
79                    },
80
81        for $val in distinct-values(
82                for $deploymentID in data($DE/atom:link[@rel = $deploymentTerm]/@href)
83        return
84                for $href in (data(collection(string-join(($targetCollection, $deploymentsDir), '/'))/atom:entry[atom:link[@href = $deploymentID] and atom:category[@label = 'Deployment']]/atom:link[@rel = $obsTerm]/@href))
85                return
86                                $href
87                        )
88        return
89                for $atom in (collection(string-join(($targetCollection, $deploymentDataDir), '/'))/atom:entry[atom:link[@href = $val]])
90                return
91                    element Source_Name {
92                        element Short_Name {data($atom/moles:entity/moles:molesISO/moles:abbreviation)},
93                        element Long_Name {data($atom/atom:title)}
94                    },
95
96   for $TemporalRange in $DE/moles:temporalRange
97        return
98        element Temporal_Coverage
99        {
100        element Start_Date {tokenize(string($DE/moles:temporalRange), '/')[1]},
101        element Stop_Date {tokenize(string($DE/moles:temporalRange), '/')[2]}
102        },
103
104        for $BoundingBox in $DE//../gml:Envelope
105        return
106            element Spatial_Coverage {
107                    element Southernmost_Latitude {tokenize(string($BoundingBox/gml:lowerCorner), ' ')[2]},
108                    element Northernmost_Latitude {tokenize(string($BoundingBox/gml:upperCorner), ' ')[2]},
109                    element Westernmost_Longitude {tokenize(string($BoundingBox/gml:lowerCorner), ' ')[1]},
110                    element Easternmost_Longitude {tokenize(string($BoundingBox/gml:upperCorner), ' ')[1]}
111                },
112
113        element Data_Resolution {''},
114
115        for $val in distinct-values(
116                for $deploymentID in data($DE/atom:link[@rel = $deploymentTerm]/@href)
117        return
118                for $href in (data(collection(string-join(($targetCollection, $deploymentsDir), '/'))/atom:entry[atom:link[@href = $deploymentID] and atom:category[@label = 'Deployment']]/atom:link[@rel = $activityTerm]/@href))
119                return
120                                $href
121                        )
122        return
123                for $atom in (collection(string-join(($targetCollection, $deploymentDataDir), '/'))/atom:entry[atom:link[@href = $val]])
124                return
125                    element Project {
126                        element Short_Name {data($atom/moles:entity/moles:molesISO/moles:abbreviation)},
127                        element Long_Name {data($atom/atom:title)}
128                    },
129
130        element Quality {''},
131        element Use_Constraints {''},
132        element Data_Set_Language {''},
133        element Distribution {''},
134        element Multimedia_Sample {''},
135        element Reference {''},
136        element Summary {string($DE/atom:summary)},
137        (: NB, deployment data is already included in the Project, Source_Name and Sensor_Name elements :)
138   for $link in ($DE/atom:link[@rel != $deploymentTerm])
139       return
140            element Related_URL {
141                    element URL {data($link/@href)},
142                    element Description {data($link/@title)},
143                    element URL_Content_Type{
144                                element Type{data($link/@rel)}
145                    }
146            },
147        element Parent_DIF {''},
148        element IDN_Node { element Short_Name {''} },
149        element Originating_Metadata_Node {''},
150        element Metadata_Name {'[CEOS IDN DIF]'},
151        element Metadata_Version {'9.4'},
152        if  (exists($DE/moles:entity/moles:molesISO/moles:created)) then
153                element DIF_Creation_Date {data($DE/moles:entity/moles:molesISO/moles:created)}
154        else (),
155        if  (exists($DE/atom:updated)) then
156                element DIF_Revision_History {data($DE/atom:updated)}
157        else ()
158        }
Note: See TracBrowser for help on using the repository browser.