Ignore:
Timestamp:
16/11/06 16:55:18 (13 years ago)
Author:
ko23
Message:

Extensions for MDIP (part one)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TI07-MOLES/trunk/JavaCode/bulkdestubbxmldb/ndg/services/bulkdestubb/Main.java

    r1695 r1707  
    3939    static String DefaultUserPW = "guest"; 
    4040 
    41         static String StubBDEQuery = "declare default element namespace 'http://ndg.nerc.ac.uk/moles/dataentity'; declare namespace moles='http://ndg.nerc.ac.uk/moles'; declare namespace f='http://ndg.nerc.ac.uk/moles/localfunctions'; declare function f:strip-namespace($e as element()) as element() (: Removes namespace info from the element tree being addressed so that it will lie in the default namespace :) { element {QName('', local-name($e))} { let $parent :=$e let $childcount := count($parent/*) return if ($childcount>0) then for $child in ($e/*) return f:strip-namespace($child) else (data($e)) } } ; declare function f:return-stub-activity($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element() (: Returns a 'stubB' style activity record to expand an activity record :) (: Security not implemented here yet :) { for $SRAct in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} { $SRAct/moles:dgMetadataID, $SRAct/moles:dgMetadataDescription, $SRAct/moles:name, $SRAct/moles:abbreviation, element dgActivity { if (exists($SRAct/*/moles:dgActivityDataCollection)) then $SRAct/*/moles:dgActivityDataCollection else if (exists($SRAct/*/moles:dgActivityDataProject)) then $SRAct/*/moles:dgActivityDataProject else if (exists($SRAct/*/dgActivityDataCampaign)) then $SRAct/moles:dgActivity/moles:dgActivityDataCampaign else $SRAct/moles:dgActivity/moles:dgActivityDataInvestigation, $SRAct/moles:dgActivity/moles:dgActivityCoverage, $SRAct/moles:dgActivity/moles:dgActivityDuration } (: </dgActivity> :) } (: </activity> :) } ; declare function f:return-stub-dataentity($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element() (: Returns a 'stubB' style observation station record to expand an data entity record :) (: Security not implemented here; it would be in a wrapper function :) { for $SRDE in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} { $SRDE/moles:dgMetadataID, $SRDE/moles:dgMetadataDescription, $SRDE/moles:name, $SRDE/moles:abbreviation, element dgDataEntity { $SRDE/moles:dgDataEntity/moles:dgDataSetType, $SRDE/moles:dgDataEntity/moles:dgDataGranule, $SRDE/moles:dgDataEntity/moles:dgDataSummary } (: </dgDataEntity> :) } } ; declare function f:return-stub-dpt($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element() (: Returns a 'stubB' style dpt record to expand a dpt record :) (: Security not implemented here; it would be in a wrapper function :) { for $SRDPT in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} { $SRDPT/moles:dgMetadataID, $SRDPT/moles:dgMetadataDescription, $SRDPT/moles:name, $SRDPT/moles:abbreviation, element dgDataProductionTool { $SRDPT/moles:dgDataProductionTool/moles:contactDetails, if (exists($SRDPT/moles:dgDataProductionTool/moles:dgModel)) then $SRDPT/moles:dgDataProductionTool/moles:dgModel else (), if (exists($SRDPT/moles:dgDataProductionTool/moles:dgInstrument)) then $SRDPT/moles:dgDataProductionTool/moles:dgInstrument else () } (: </dgDataProductionTool> :) } (: </dataproductiontool> :) } ; declare function f:return-stub-obsstn($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element() (: Returns a 'stubB' style observation station record to expand an observation station record :) (: Security not implemented here yet; :) { for $SRObsStn in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} { ($SRObsStn/moles:dgMetadataID), ($SRObsStn/moles:dgMetadataDescription), ($SRObsStn/moles:name), ($SRObsStn/moles:abbreviation), element dgObservationStation { ($SRObsStn/moles:dgObservationStation/moles:contactDetails), if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform)) then element dgStationaryPlatform { $SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:position, if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgLandStation)) then element dgLandStation {''} else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgMooring)) then element dgMooring {''} else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgStationGroup)) then element dgStationGroup {''} else () } else if (exists($SRObsStn/moles:dgObservationStation/moles:dgMovingPlatform)) then $SRObsStn/moles:dgObservationStation/moles:dgMovingPlatform else () } (: </dgObservationStation> :) } } ; declare function f:return-stub-person($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element() (: Returns a 'stubB' style observation station record to expand a person record :) (: Security not implemented here; it would be in a wrapper function :) { for $person in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgPerson[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} { $person/moles:name, $person/moles:contactDetails, $person/moles:dgMetadataID } } ; declare function f:return-stub-organisation($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element() (: Returns a 'stubB' style observation station record to expand an organisation record :) (: Security not implemented here; it would be in a wrapper function :) { for $org in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgOrganisation[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} { $org/moles:dgMetadataID, $org/name, $org/abbreviation, $org/contactDetails } } ; for $DE in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[ exists(moles:dgDataEntity) and moles:dgMetadataID[ moles:schemeIdentifier='NDG-B0' and moles:repositoryIdentifier='RepositoryID' and moles:localIdentifier='LocalID']] return f:strip-namespace(element dgMetadataRecord { element dgMetadataID { element schemeIdentifier {'NDG-B1'}, $DE/moles:dgMetadataID/moles:repositoryIdentifier, $DE/moles:dgMetadataID/moles:localIdentifier }, (: </dgMetadataID> :) $DE/moles:dgMetadataDescription, $DE/moles:name, $DE/moles:abbreviation, element dgDataEntity { $DE/moles:dgDataEntity/moles:dgDataSetType, $DE/moles:dgDataEntity/moles:dgDataObjectType, $DE/moles:dgDataEntity/moles:dgDataGranule, $DE/moles:dgDataEntity/moles:dgDataSummary, element dgDataRoles { if (exists($DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgMetadataID)) then element dgDataCreator { $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgMetadataID, $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:roleName, $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:abbreviation, $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:contactDetails, for $DataCreatorRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgRoleHolder order by $DataCreatorRole/moles:startDate empty least, $DataCreatorRole/moles:endDate empty least return element dgRoleHolder { if (exists($DataCreatorRole/moles:dgOrganisationID)) then f:return-stub-organisation('organisation', data($DataCreatorRole/moles:dgOrganisationID/moles:repositoryIdentifier), data($DataCreatorRole/moles:dgOrganisationID/moles:localIdentifier)) else if (exists($DataCreatorRole/moles:dgPersonID)) then f:return-stub-person('person', string($DataCreatorRole/moles:dgPersonID/moles:repositoryIdentifier), string($DataCreatorRole/moles:dgPersonID/moles:localIdentifier)) else (), $DataCreatorRole/moles:startDate, $DataCreatorRole/moles:endDate, $DataCreatorRole/moles:localName } (: </dgRoleHolder> :) } (: </dgDataCreator>) :) else (), if (exists($DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:dgMetadataID)) then element dgDataCurator { $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:dgMetadataID, $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:roleName, $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:abbreviation, $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:contactDetails, for $DataCuratorRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:dgRoleHolder order by $DataCuratorRole/moles:startDate empty least, $DataCuratorRole/moles:endDate empty least return element dgRoleHolder { if (exists($DataCuratorRole/moles:dgOrganisationID)) then f:return-stub-organisation('organisation', data($DataCuratorRole/moles:dgOrganisationID/moles:repositoryIdentifier), data($DataCuratorRole/moles:dgOrganisationID/moles:localIdentifier)) else if (exists($DataCuratorRole/moles:dgPersonID)) then f:return-stub-person('person', string($DataCuratorRole/moles:dgPersonID/moles:repositoryIdentifier), string($DataCuratorRole/moles:dgPersonID/moles:localIdentifier)) else (), $DataCuratorRole/moles:startDate, $DataCuratorRole/moles:endDate, $DataCuratorRole/moles:localName } (: </dgRoleHolder> :) } (: </dgDataCurator> :) else (), if (exists($DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:dgMetadataID)) then element dgDataOtherRoles { $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:dgMetadataID, $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:roleName, $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:abbreviation, $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:contactDetails, for $DataOtherRolesRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:dgRoleHolder order by $DataOtherRolesRole/moles:startDate empty least, $DataOtherRolesRole/moles:endDate empty least return element dgRoleHolder { if (exists($DataOtherRolesRole/moles:dgOrganisationID)) then f:return-stub-organisation('organisation', data($DataOtherRolesRole/moles:dgOrganisationID/moles:repositoryIdentifier), data($DataOtherRolesRole/moles:dgOrganisationID/moles:localIdentifier)) else if (exists($DataOtherRolesRole/moles:dgPersonID)) then f:return-stub-person('person', string($DataOtherRolesRole/moles:dgPersonID/moles:repositoryIdentifier), string($DataOtherRolesRole/moles:dgPersonID/moles:localIdentifier)) else (), $DataOtherRolesRole/moles:startDate, $DataOtherRolesRole/moles:endDate, $DataOtherRolesRole/moles:localName } (: </dgRoleHolder> :) } (: </dgDataOtherRoles> :) else () } , (: </dgDataRoles> :) for $RelDep in $DE/moles:dgDataEntity/moles:RelatedDeployment return element RelatedDeployment { $RelDep/moles:DateStart, $RelDep/moles:DateEnd, $RelDep/moles:dgMetadataID, f:return-stub-activity('activity', data($RelDep/moles:ActivityID/moles:repositoryIdentifier), data($RelDep/moles:ActivityID/moles:localIdentifier)), f:return-stub-dpt('dataproductiontool', data($RelDep/moles:DataProductionToolID/moles:repositoryIdentifier), data($RelDep/moles:DataProductionToolID/moles:localIdentifier)), f:return-stub-obsstn('observationstation', data($RelDep/moles:ObservationStationID/moles:repositoryIdentifier), data($RelDep/moles:ObservationStationID/moles:localIdentifier)), $RelDep/moles:Coverage } (: </RelatedDeployment> :) , for $RelatedDataEntity in $DE/moles:dgDataEntity/moles:dgRelatedDataEntity return element relateddataentity { element relation { $RelatedDataEntity/moles:RelationID/moles:dgValidTerm, $RelatedDataEntity/moles:RelationID/moles:dgValidTermID }, (: </relation> :) f:return-stub-dataentity('dataentity', data($RelatedDataEntity/(moles:RelatedDataEntityID | moles:RelatedDataGranuleID)/moles:repositoryIdentifier), data($RelatedDataEntity/(moles:RelatedDataEntityID | moles:RelatedDataGranuleID)/moles:localIdentifier)) } (: </relateddataentity> :) } (: </dgDataEntity> :), for $strkwrd in $DE/moles:dgStructuredKeyword return $strkwrd, if (exists($DE/moles:DataProvenance)) then $DE/moles:DataProvenance else (), if (exists($DE/moles:MetadataSecurity)) then $DE/moles:MetadataSecurity else () } (: </dgMetadataRecord> :) ) (: end of namespace strip :)"; 
    42         static String StubBActQuery = "declare default element namespace 'http://ndg.nerc.ac.uk/moles/activity'; declare namespace moles='http://ndg.nerc.ac.uk/moles'; declare namespace f='http://ndg.nerc.ac.uk/moles/localfunctions'; declare function f:strip-namespace($e as element()) as element() (: Removes namespace info from the element tree being addressed so that it will lie in the default namespace :) { element {QName('', local-name($e))} { let $parent :=$e let $childcount := count($parent/*) return if ($childcount>0) then for $child in ($e/*) return f:strip-namespace($child) else (data($e)) } } ; declare function f:return-stub-activity($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element() (: Returns a 'stubB' style activity record to expand an activity record :) (: Security not implemented here yet :) { for $SRAct in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} { ($SRAct/moles:dgMetadataID), ($SRAct/moles:dgMetadataDescription), ($SRAct/moles:name), ($SRAct/moles:abbreviation), element dgActivity { if (exists($SRAct/*/moles:dgActivityDataCollection)) then ($SRAct/*/moles:dgActivityDataCollection) else if (exists($SRAct/*/moles:dgActivityDataProject)) then ($SRAct/*/moles:dgActivityDataProject) else if (exists($SRAct/*/dgActivityDataCampaign)) then ($SRAct/moles:dgActivity/moles:dgActivityDataCampaign) else ($SRAct/moles:dgActivity/moles:dgActivityDataInvestigation), ($SRAct/moles:dgActivity/moles:dgActivityCoverage), ($SRAct/moles:dgActivity/moles:dgActivityDuration) } (: </dgActivity> :) } (: </activity> :) } ; declare function f:return-stub-dataentity($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element() (: Returns a 'stubB' style observation station record to expand an data entity record :) (: Security not implemented here; it would be in a wrapper function :) { for $SRDE in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} { ($SRDE/moles:dgMetadataID), ($SRDE/moles:dgMetadataDescription), ($SRDE/moles:name), ($SRDE/moles:abbreviation), element dgDataEntity { ($SRDE/moles:dgDataEntity/moles:dgDataSetType), ($SRDE/moles:dgDataEntity/moles:dgDataGranule), ($SRDE/moles:dgDataEntity/moles:dgDataSummary) } (: </dgDataEntity> :) } } ; declare function f:return-stub-dpt($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element() (: Returns a 'stubB' style dpt record to expand a dpt record :) (: Security not implemented here; it would be in a wrapper function :) { for $SRDPT in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} { ($SRDPT/moles:dgMetadataID), ($SRDPT/moles:dgMetadataDescription), ($SRDPT/moles:name), ($SRDPT/moles:abbreviation), element dgDataProductionTool { ($SRDPT/moles:dgDataProductionTool/moles:contactDetails), if (exists($SRDPT/moles:dgDataProductionTool/moles:dgModel)) then ($SRDPT/moles:dgDataProductionTool/moles:dgModel) else (), if (exists($SRDPT/moles:dgDataProductionTool/moles:dgInstrument)) then ($SRDPT/moles:dgDataProductionTool/moles:dgInstrument) else () } (: </dgDataProductionTool> :) } (: </dataproductiontool> :) } ; declare function f:return-stub-obsstn($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element() (: Returns a 'stubB' style observation station record to expand an observation station record :) (: Security not implemented here yet; :) { for $SRObsStn in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} { ($SRObsStn/moles:dgMetadataID), ($SRObsStn/moles:dgMetadataDescription), ($SRObsStn/moles:name), ($SRObsStn/moles:abbreviation), element dgObservationStation { ($SRObsStn/moles:dgObservationStation/moles:contactDetails), if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform)) then element dgStationaryPlatform { $SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:position, if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgLandStation)) then element dgLandStation {''} else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgMooring)) then element dgMooring {''} else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgStationGroup)) then element dgStationGroup {''} else () } else if (exists($SRObsStn/moles:dgObservationStation/moles:dgMovingPlatform)) then $SRObsStn/moles:dgObservationStation/moles:dgMovingPlatform else () } (: </dgObservationStation> :) } } ; declare function f:return-stub-person($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element() (: Returns a 'stubB' style observation station record to expand a person record :) (: Security not implemented here; it would be in a wrapper function :) { for $person in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgPerson[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} { ($person/moles:name), ($person/moles:contactDetails), ($person/moles:dgMetadataID) } } ; declare function f:return-stub-organisation($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element() (: Returns a 'stubB' style observation station record to expand an organisation record :) (: Security not implemented here; it would be in a wrapper function :) { for $org in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgOrganisation[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} { ($org/moles:dgMetadataID), ($org/name), ($org/abbreviation), ($org/contactDetails) } } ; for $Act in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID/moles:schemeIdentifier='NDG-B0' and moles:dgMetadataID/moles:repositoryIdentifier='RepositoryID' and moles:dgMetadataID/moles:localIdentifier='LocalID'] return f:strip-namespace(element dgMetadataRecord { element dgMetadataID { element schemeIdentifier {'NDG-B1'}, (element repositoryIdentifier {data($Act/moles:dgMetadataID/moles:repositoryIdentifier)}), element localIdentifier {data($Act/moles:dgMetadataID/moles:localIdentifier)} }, $Act/moles:dgMetadataDescription, $Act/moles:name, $Act/moles:abbreviation, element dgActivity { for $RelatedActivities in $Act/dgActivity/moles:relatedActivity return element relatedActivity { $RelatedActivities/moles:activityRelation, f:return-stub-activity('activity', data($RelatedActivities/moles:relatedActivityID/moles:repositoryIdentifier), data($RelatedActivities/moles:relatedActivityID/moles:localIdentifier)) }, (: </relatedActivity> :) if (exists($Act/moles:dgActivity/moles:dgActivityDataCollection)) then ($Act/moles:dgActivity/moles:dgActivityDataCollection) else if (exists($Act/moles:dgActivity/moles:dgActivityDataProject)) then ($Act/moles:dgActivity/moles:dgActivityDataProject) else if (exists($Act/moles:dgActivity/moles:dgActivityDataInvestigation)) then ($Act/moles:dgActivity/moles:dgActivityDataInvestigation) else if (exists($Act/moles:dgActivity/moles:dgActivityDataCampaign)) then ($Act/moles:dgActivity/moles:dgActivityDataCampaign) else (), element dgActivityRole { element dgInvestigator { element dgPrincipalInvestigator { ($Act/moles:dgActivity/moles:dgActivityRole/moles:dgInvestigator/moles:dgPrincipalInvestigator/moles:dgMetadataID), ($Act/moles:dgActivity/moles:dgActivityRole/moles:dgInvestigator/moles:dgPrincipalInvestigator/moles:roleName), ($Act/moles:dgActivity/moles:dgActivityRole/moles:dgInvestigator/moles:dgPrincipalInvestigator/moles:abbreviation), ($Act/moles:dgActivity/moles:dgActivityRole/moles:dgInvestigator/moles:dgPrincipalInvestigator/moles:contactDetails), for $PIRole in $Act/moles:dgActivity/moles:dgActivityRole/moles:dgInvestigator/moles:dgPrincipalInvestigator/moles:dgRoleHolder order by $PIRole/moles:startDate empty least, $PIRole/moles:endDate empty least return element dgRoleHolder { if (exists($PIRole/moles:dgOrganisationID)) then f:return-stub-organisation('organisation', data($PIRole/moles:dgOrganisationID/moles:repositoryIdentifier), data($PIRole/moles:dgOrganisationID/moles:localIdentifier)) else if (exists($PIRole/moles:dgPersonID)) then f:return-stub-person('person', string($PIRole/moles:dgPersonID/moles:repositoryIdentifier), string($PIRole/moles:dgPersonID/moles:localIdentifier)) else (), ($PIRole/moles:startDate), if (exists($PIRole/moles:endDate)) then ($PIRole/moles:endDate) else (), if (exists($PIRole/moles:localName)) then ($PIRole/moles:localName) else () } (: </dgRoleHolder> :) }, (: </dgPrincipalInvestigator> :) for $CI in $Act/moles:dgActivity/moles:dgActivityRole/moles:dgInvestigator/moles:dgCoInvestigator return element dgCoInvestigator { ($CI/moles:dgMetadataID), ($CI/moles:roleName), ($CI/moles:abbreviation), ($CI/moles:contactDetails), for $CIRole in $CI/moles:dgRoleHolder order by $CIRole/moles:startDate empty least, $CIRole/moles:endDate empty least return element dgRoleHolder { if (exists(CIRole/moles:dgOrganisationID)) then f:return-stub-organisation('organisation', data($CIRole/moles:dgOrganisationID/moles:repositoryIdentifier), data($CIRole/moles:dgOrganisationID/moles:localIdentifier)) else if (exists($CIRole/moles:dgPersonID)) then f:return-stub-person('person', string($CIRole/moles:dgPersonID/moles:repositoryIdentifier), string($CIRole/moles:dgPersonID/moles:localIdentifier)) else (), ($CIRole/moles:startDate), if (exists($CIRole/moles:endDate)) then ($CIRole/moles:endDate) else (), if (exists($CIRole/moles:localName)) then ($CIRole/moles:localName) else () } (: </dgRoleHolder> :) } (: </dgCoInvestigator> :) }, (: </dgInvestigator> :) if (exists($Act/moles:dgActivity/moles:dgActivityRole/moles:dgTechnicalContact)) then ( element dgTechnicalContact { ($Act/moles:dgActivity/moles:dgActivityRole/moles:dgTechnicalContact/moles:dgMetadataID), ($Act/moles:dgActivity/moles:dgActivityRole/moles:dgTechnicalContact/moles:roleName), ($Act/moles:dgActivity/moles:dgActivityRole/moles:dgTechnicalContact/moles:abbreviation), ($Act/moles:dgActivity/moles:dgActivityRole/moles:dgTechnicalContact/moles:contactDetails), for $TechConRole in $Act/moles:dgActivity/moles:dgActivityRole/moles:dgTechnicalContact/moles:dgRoleHolder order by $TechConRole/moles:startDate empty least, $TechConRole/moles:endDate empty least return element dgRoleHolder { if (exists($TechConRole/moles:dgOrganisationID)) then f:return-stub-organisation('organisation', data($TechConRole/moles:dgOrganisationID/moles:repositoryIdentifier), data($TechConRole/moles:dgOrganisationID/moles:localIdentifier)) else if (exists($TechConRole/moles:dgPersonID)) then f:return-stub-person('person', string($TechConRole/moles:dgPersonID/moles:repositoryIdentifier), string($TechConRole/moles:dgPersonID/moles:localIdentifier)) else (), ($TechConRole/moles:startDate), if (exists($TechConRole/moles:endDate)) then ($TechConRole/moles:endDate) else (), if (exists($TechConRole/moles:localName)) then ($TechConRole/moles:localName) else () } (: </dgRoleHolder> :) } (: </dgTechnicalContact> :) ) else (), if (exists($Act/dgActivity/dgActivityRole/dgProjectManager)) then ( element dgProjectManager { ($Act/dgActivity/dgActivityRole/dgProjectManager/dgMetadataID), ($Act/dgActivity/dgActivityRole/dgProjectManager/roleName), ($Act/dgActivity/dgActivityRole/dgProjectManager/abbreviation), ($Act/dgActivity/dgActivityRole/dgProjectManager/contactDetails), for $PMRole in $Act/dgActivity/dgActivityRole/dgProjectManager/dgRoleHolder order by $PMRole/startDate empty least, $PMRole/endDate empty least return element dgRoleHolder { if (exists($PMRole/moles:dgOrganisationID)) then f:return-stub-organisation('organisation', data($PMRole/moles:dgOrganisationID/moles:repositoryIdentifier), data($PMRole/moles:dgOrganisationID/moles:localIdentifier)) else if (exists($PMRole/moles:dgPersonID)) then f:return-stub-person('person', string($PMRole/moles:dgPersonID/moles:repositoryIdentifier), string($PMRole/moles:dgPersonID/moles:localIdentifier)) else (), ($PMRole/startDate), if (exists($PMRole/moles:endDate)) then ($PMRole/moles:endDate) else (), if (exists($PMRole/moles:localName)) then ($PMRole/moles:localName) else () } (: </dgRoleHolder> :) } (: </dgProjectManager> :) ) else () }, (: </dgActivityRole> :) for $RelDep in $Act/moles:dgActivity/moles:ActivityDeployment return element ActivityDeployment { ($RelDep/moles:DateStart), if (exists($RelDep/moles:DateEnd)) then ($RelDep/moles:DateEnd) else (), ($RelDep/moles:dgMetadataID), f:return-stub-dpt('dataproductiontool', data($RelDep/moles:DataProductionToolID/moles:repositoryIdentifier), data($RelDep/moles:DataProductionToolID/moles:localIdentifier)), f:return-stub-obsstn('observationstation', data($RelDep/moles:ObservationStationID/moles:repositoryIdentifier), data($RelDep/moles:ObservationStationID/moles:localIdentifier)), for $DE in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord where $DE/moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:repositoryIdentifier=$RelDep/moles:dgMetadataID/moles:repositoryIdentifier and $DE/moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:localIdentifier=$RelDep/moles:dgMetadataID/moles:localIdentifier return f:return-stub-dataentity('dataentity', data($DE/moles:dgMetadataID/moles:repositoryIdentifier), data($DE/moles:dgMetadataID/moles:localIdentifier)) }, (: </ActivityDeployment> :) if (exists($Act/dgActivityCoverage)) then ($Act/dgActivityCoverage) else (), if (exists($Act/dgActivityDuration)) then ($Act/dgActivityDuration) else () } , (: </dgActivity> :) for $strkwrd in $Act/moles:dgStructuredKeyword return $strkwrd, if (exists($Act/moles:DataProvenance)) then $Act/moles:DataProvenance else (), if (exists($Act/moles:MetadataSecurity)) then $Act/moles:MetadataSecurity else () } (:</dgMRecord>:) ) (: End namespace strip :)"; 
    43         static String StubBDPTQuery = "declare default element namespace 'http://ndg.nerc.ac.uk/moles/dataentity'; declare namespace moles='http://ndg.nerc.ac.uk/moles'; declare namespace f='http://ndg.nerc.ac.uk/moles/localfunctions'; declare function f:strip-namespace($e as element()) as element() (: Removes namespace info from the element tree being addressed so that it will lie in the default namespace :) { element {QName('', local-name($e))} { let $parent :=$e let $childcount := count($parent/*) return if ($childcount>0) then for $child in ($e/*) return f:strip-namespace($child) else (data($e)) } } ; declare function f:return-stub-activity($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element() (: Returns a 'stubB' style activity record to expand an activity record :) (: Security not implemented here yet :) { for $SRAct in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} { $SRAct/moles:dgMetadataID, $SRAct/moles:dgMetadataDescription, $SRAct/moles:name, $SRAct/moles:abbreviation, element dgActivity { if (exists($SRAct/*/moles:dgActivityDataCollection)) then $SRAct/*/moles:dgActivityDataCollection else if (exists($SRAct/*/moles:dgActivityDataProject)) then $SRAct/*/moles:dgActivityDataProject else if (exists($SRAct/*/dgActivityDataCampaign)) then $SRAct/moles:dgActivity/moles:dgActivityDataCampaign else $SRAct/moles:dgActivity/moles:dgActivityDataInvestigation, $SRAct/moles:dgActivity/moles:dgActivityCoverage, $SRAct/moles:dgActivity/moles:dgActivityDuration } (: </dgActivity> :) } (: </activity> :) } ; declare function f:return-stub-dataentity($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element() (: Returns a 'stubB' style observation station record to expand an data entity record :) (: Security not implemented here; it would be in a wrapper function :) { for $SRDE in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} { $SRDE/moles:dgMetadataID, $SRDE/moles:dgMetadataDescription, $SRDE/moles:name, $SRDE/moles:abbreviation, element dgDataEntity { $SRDE/moles:dgDataEntity/moles:dgDataSetType, $SRDE/moles:dgDataEntity/moles:dgDataGranule, $SRDE/moles:dgDataEntity/moles:dgDataSummary } (: </dgDataEntity> :) } } ; declare function f:return-stub-dpt($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element() (: Returns a 'stubB' style dpt record to expand a dpt record :) (: Security not implemented here; it would be in a wrapper function :) { for $SRDPT in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} { $SRDPT/moles:dgMetadataID, $SRDPT/moles:dgMetadataDescription, $SRDPT/moles:name, $SRDPT/moles:abbreviation, element dgDataProductionTool { $SRDPT/moles:dgDataProductionTool/moles:contactDetails, if (exists($SRDPT/moles:dgDataProductionTool/moles:dgModel)) then $SRDPT/moles:dgDataProductionTool/moles:dgModel else (), if (exists($SRDPT/moles:dgDataProductionTool/moles:dgInstrument)) then $SRDPT/moles:dgDataProductionTool/moles:dgInstrument else () } (: </dgDataProductionTool> :) } (: </dataproductiontool> :) } ; declare function f:return-stub-obsstn($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element() (: Returns a 'stubB' style observation station record to expand an observation station record :) (: Security not implemented here yet; :) { for $SRObsStn in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} { ($SRObsStn/moles:dgMetadataID), ($SRObsStn/moles:dgMetadataDescription), ($SRObsStn/moles:name), ($SRObsStn/moles:abbreviation), element dgObservationStation { ($SRObsStn/moles:dgObservationStation/moles:contactDetails), if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform)) then element dgStationaryPlatform { $SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:position, if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgLandStation)) then element dgLandStation {''} else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgMooring)) then element dgMooring {''} else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgStationGroup)) then element dgStationGroup {''} else () } else if (exists($SRObsStn/moles:dgObservationStation/moles:dgMovingPlatform)) then $SRObsStn/moles:dgObservationStation/moles:dgMovingPlatform else () } (: </dgObservationStation> :) } } ; declare function f:return-stub-person($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element() (: Returns a 'stubB' style observation station record to expand a person record :) (: Security not implemented here; it would be in a wrapper function :) { for $person in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgPerson[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} { $person/moles:name, $person/moles:contactDetails, $person/moles:dgMetadataID } } ; declare function f:return-stub-organisation($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element() (: Returns a 'stubB' style observation station record to expand an organisation record :) (: Security not implemented here; it would be in a wrapper function :) { for $org in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgOrganisation[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} { $org/moles:dgMetadataID, $org/name, $org/abbreviation, $org/contactDetails } } ; for $DE in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[ exists(moles:dgDataEntity) and moles:dgMetadataID[ moles:schemeIdentifier='NDG-B0' and moles:repositoryIdentifier='RepositoryID' and moles:localIdentifier='LocalID']] return f:strip-namespace(element dgMetadataRecord { element dgMetadataID { element schemeIdentifier {'NDG-B1'}, $DE/moles:dgMetadataID/moles:repositoryIdentifier, $DE/moles:dgMetadataID/moles:localIdentifier }, (: </dgMetadataID> :) $DE/moles:dgMetadataDescription, $DE/moles:name, $DE/moles:abbreviation, element dgDataEntity { $DE/moles:dgDataEntity/moles:dgDataSetType, $DE/moles:dgDataEntity/moles:dgDataObjectType, $DE/moles:dgDataEntity/moles:dgDataGranule, $DE/moles:dgDataEntity/moles:dgDataSummary, element dgDataRoles { if (exists($DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgMetadataID)) then element dgDataCreator { $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgMetadataID, $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:roleName, $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:abbreviation, $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:contactDetails, for $DataCreatorRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgRoleHolder order by $DataCreatorRole/moles:startDate empty least, $DataCreatorRole/moles:endDate empty least return element dgRoleHolder { if (exists($DataCreatorRole/moles:dgOrganisationID)) then f:return-stub-organisation('organisation', data($DataCreatorRole/moles:dgOrganisationID/moles:repositoryIdentifier), data($DataCreatorRole/moles:dgOrganisationID/moles:localIdentifier)) else if (exists($DataCreatorRole/moles:dgPersonID)) then f:return-stub-person('person', string($DataCreatorRole/moles:dgPersonID/moles:repositoryIdentifier), string($DataCreatorRole/moles:dgPersonID/moles:localIdentifier)) else (), $DataCreatorRole/moles:startDate, $DataCreatorRole/moles:endDate, $DataCreatorRole/moles:localName } (: </dgRoleHolder> :) } (: </dgDataCreator>) :) else (), if (exists($DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:dgMetadataID)) then element dgDataCurator { $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:dgMetadataID, $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:roleName, $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:abbreviation, $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:contactDetails, for $DataCuratorRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:dgRoleHolder order by $DataCuratorRole/moles:startDate empty least, $DataCuratorRole/moles:endDate empty least return element dgRoleHolder { if (exists($DataCuratorRole/moles:dgOrganisationID)) then f:return-stub-organisation('organisation', data($DataCuratorRole/moles:dgOrganisationID/moles:repositoryIdentifier), data($DataCuratorRole/moles:dgOrganisationID/moles:localIdentifier)) else if (exists($DataCuratorRole/moles:dgPersonID)) then f:return-stub-person('person', string($DataCuratorRole/moles:dgPersonID/moles:repositoryIdentifier), string($DataCuratorRole/moles:dgPersonID/moles:localIdentifier)) else (), $DataCuratorRole/moles:startDate, $DataCuratorRole/moles:endDate, $DataCuratorRole/moles:localName } (: </dgRoleHolder> :) } (: </dgDataCurator> :) else (), if (exists($DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:dgMetadataID)) then element dgDataOtherRoles { $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:dgMetadataID, $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:roleName, $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:abbreviation, $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:contactDetails, for $DataOtherRolesRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:dgRoleHolder order by $DataOtherRolesRole/moles:startDate empty least, $DataOtherRolesRole/moles:endDate empty least return element dgRoleHolder { if (exists($DataOtherRolesRole/moles:dgOrganisationID)) then f:return-stub-organisation('organisation', data($DataOtherRolesRole/moles:dgOrganisationID/moles:repositoryIdentifier), data($DataOtherRolesRole/moles:dgOrganisationID/moles:localIdentifier)) else if (exists($DataOtherRolesRole/moles:dgPersonID)) then f:return-stub-person('person', string($DataOtherRolesRole/moles:dgPersonID/moles:repositoryIdentifier), string($DataOtherRolesRole/moles:dgPersonID/moles:localIdentifier)) else (), $DataOtherRolesRole/moles:startDate, $DataOtherRolesRole/moles:endDate, $DataOtherRolesRole/moles:localName } (: </dgRoleHolder> :) } (: </dgDataOtherRoles> :) else () } , (: </dgDataRoles> :) for $RelDep in $DE/moles:dgDataEntity/moles:RelatedDeployment return element RelatedDeployment { $RelDep/moles:DateStart, $RelDep/moles:DateEnd, $RelDep/moles:dgMetadataID, f:return-stub-activity('activity', data($RelDep/moles:ActivityID/moles:repositoryIdentifier), data($RelDep/moles:ActivityID/moles:localIdentifier)), f:return-stub-dpt('dataproductiontool', data($RelDep/moles:DataProductionToolID/moles:repositoryIdentifier), data($RelDep/moles:DataProductionToolID/moles:localIdentifier)), f:return-stub-obsstn('observationstation', data($RelDep/moles:ObservationStationID/moles:repositoryIdentifier), data($RelDep/moles:ObservationStationID/moles:localIdentifier)), $RelDep/moles:Coverage } (: </RelatedDeployment> :) , for $RelatedDataEntity in $DE/moles:dgDataEntity/moles:dgRelatedDataEntity return element relateddataentity { element relation { $RelatedDataEntity/moles:RelationID/moles:dgValidTerm, $RelatedDataEntity/moles:RelationID/moles:dgValidTermID }, (: </relation> :) f:return-stub-dataentity('dataentity', data($RelatedDataEntity/(moles:RelatedDataEntityID | moles:RelatedDataGranuleID)/moles:repositoryIdentifier), data($RelatedDataEntity/(moles:RelatedDataEntityID | moles:RelatedDataGranuleID)/moles:localIdentifier)) } (: </relateddataentity> :) } (: </dgDataEntity> :), for $strkwrd in $DE/moles:dgStructuredKeyword return $strkwrd, if (exists($DE/moles:DataProvenance)) then $DE/moles:DataProvenance else (), if (exists($DE/moles:MetadataSecurity)) then $DE/moles:MetadataSecurity else () } (: </dgMetadataRecord> :) ) (: end of namespace strip :)"; 
    44         static String StubBObsStnQuery = "declare default element namespace 'http://ndg.nerc.ac.uk/moles/observationstation'; declare namespace moles='http://ndg.nerc.ac.uk/moles'; declare namespace f='http://ndg.nerc.ac.uk/moles/localfunctions'; declare function f:strip-namespace($e as element()) as element() (: Removes namespace info from the element tree being addressed so that it will lie in the default namespace :) { element {QName('', local-name($e))} { let $parent :=$e let $childcount := count($parent/*) return if ($childcount>0) then for $child in ($e/*) return f:strip-namespace($child) else (data($e)) } } ; declare function f:return-stub-activity($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element() (: Returns a 'stubB' style activity record to expand an activity record :) (: Security not implemented here yet :) { for $SRAct in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} { ($SRAct/moles:dgMetadataID), ($SRAct/moles:dgMetadataDescription), ($SRAct/moles:name), ($SRAct/moles:abbreviation), element dgActivity { if (exists($SRAct/*/moles:dgActivityDataCollection)) then ($SRAct/*/moles:dgActivityDataCollection) else if (exists($SRAct/*/moles:dgActivityDataProject)) then ($SRAct/*/moles:dgActivityDataProject) else if (exists($SRAct/*/dgActivityDataCampaign)) then ($SRAct/moles:dgActivity/moles:dgActivityDataCampaign) else ($SRAct/moles:dgActivity/moles:dgActivityDataInvestigation), ($SRAct/moles:dgActivity/moles:dgActivityCoverage), ($SRAct/moles:dgActivity/moles:dgActivityDuration) } (: </dgActivity> :) } (: </activity> :) } ; declare function f:return-stub-dataentity($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element() (: Returns a 'stubB' style observation station record to expand an data entity record :) (: Security not implemented here; it would be in a wrapper function :) { for $SRDE in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} { ($SRDE/moles:dgMetadataID), ($SRDE/moles:dgMetadataDescription), ($SRDE/moles:name), ($SRDE/moles:abbreviation), element dgDataEntity { ($SRDE/moles:dgDataEntity/moles:dgDataSetType), ($SRDE/moles:dgDataEntity/moles:dgDataGranule), ($SRDE/moles:dgDataEntity/moles:dgDataSummary) } (: </dgDataEntity> :) } } ; declare function f:return-stub-dpt($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element() (: Returns a 'stubB' style dpt record to expand a dpt record :) (: Security not implemented here; it would be in a wrapper function :) { for $SRDPT in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} { ($SRDPT/moles:dgMetadataID), ($SRDPT/moles:dgMetadataDescription), ($SRDPT/moles:name), ($SRDPT/moles:abbreviation), element dgDataProductionTool { ($SRDPT/moles:dgDataProductionTool/moles:contactDetails), if (exists($SRDPT/moles:dgDataProductionTool/moles:dgModel)) then ($SRDPT/moles:dgDataProductionTool/moles:dgModel) else (), if (exists($SRDPT/moles:dgDataProductionTool/moles:dgInstrument)) then ($SRDPT/moles:dgDataProductionTool/moles:dgInstrument) else () } (: </dgDataProductionTool> :) } (: </dataproductiontool> :) } ; declare function f:return-stub-obsstn($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element() (: Returns a 'stubB' style observation station record to expand an observation station record :) (: Security not implemented here yet; :) { for $SRObsStn in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} { ($SRObsStn/moles:dgMetadataID), ($SRObsStn/moles:dgMetadataDescription), ($SRObsStn/moles:name), ($SRObsStn/moles:abbreviation), element dgObservationStation { ($SRObsStn/moles:dgObservationStation/moles:contactDetails), if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform)) then element dgStationaryPlatform { $SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:position, if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgLandStation)) then element dgLandStation {''} else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgMooring)) then element dgMooring {''} else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgStationGroup)) then element dgStationGroup {''} else () } else if (exists($SRObsStn/moles:dgObservationStation/moles:dgMovingPlatform)) then $SRObsStn/moles:dgObservationStation/moles:dgMovingPlatform else () } (: </dgObservationStation> :) } } ; declare function f:return-stub-person($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element() (: Returns a 'stubB' style observation station record to expand a person record :) (: Security not implemented here; it would be in a wrapper function :) { for $person in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgPerson[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} { ($person/moles:name), ($person/moles:contactDetails), ($person/moles:dgMetadataID) } } ; declare function f:return-stub-organisation($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element() (: Returns a 'stubB' style observation station record to expand an organisation record :) (: Security not implemented here; it would be in a wrapper function :) { for $org in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgOrganisation[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} { ($org/moles:dgMetadataID), ($org/name), ($org/abbreviation), ($org/contactDetails) } } ; for $ObsStn in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[ moles:dgMetadataID/moles:schemeIdentifier='NDG-B0' and moles:dgMetadataID/moles:repositoryIdentifier='RepositoryID' and moles:dgMetadataID/moles:localIdentifier='LocalID'] return f:strip-namespace( element dgMetadataRecord { element dgMetadataID { element schemeIdentifier {'NDG-B1', $ObsStn/moles:dgMetadataID/moles:repositoryIdentifier, $ObsStn/moles:dgMetadataID/moles:localIdentifier } (: End </dgMetadataID> :), $ObsStn/moles:dgMetadataDescription, $ObsStn/moles:name, $ObsStn/moles:abbreviation, element dgObservationStation { $ObsStn/moles:dgObservationStation/moles:contactDetails, if (exists($ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform)) then element dgStationaryPlatform { $ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:position, if (exists($ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring)) then element dgMooring { $ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/moles:dateStart, $ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/moles:dateEnd, for $DepositingCruise in $ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/moles:DepositingCruise return f:return-stub-activity('depositingcruise', data($DepositingCruise/moles:dgMetadataID/moles:repositoryIdentifier), data($DepositingCruise/moles:dgMetadataID/moles:localIdentifier)), if (exists($ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/moles:dgStationGrouping)) then for $StationGrouping in $ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/dgStationGrouping return f:return-stub-obsstn('stationgrouping', data($StationGrouping/moles:dgMetadataID/moles:repositoryIdentifier), data($StationGrouping/moles:dgMetadataID/moles:localIdentifier)) else () } (: End </dgMooring> :) else if (exists($ObsStn/dgObservationStation/dgStationaryPlatform/dgStationGroup)) then element dgStationGroup { element dgGroupedStations { if (exists($ObsStn/dgObservationStation/dgStationaryPlatform/dgStationGroup/dgGroupedStations)) then for $GroupedStation in $ObsStn/dgObservationStation/dgStationaryPlatform/dgStationGroup/dgGroupedStation/dgGroupedStations return f:return-stub-obsstn('dgGroupedStation', data($GroupedStation/moles:dgMetadataID/moles:repositoryIdentifier), data($GroupedStation/moles:dgMetadataID/moles:localIdentifier)) else () } (: End </dgGroupedStations> :) } (: End </dgStationGroup> :) else $ObsStn/moles:dgObservationStation/moles:dgLandStation } (: End </dgStationaryPlatform> :) else $ObsStn/moles:dgObservationStation/moles:dgMovingPlatform } , for $RelDep in $ObsStn/moles:dgObservationStation/moles:ObsStationDeployment return element ObsStationDeployment { $RelDep/moles:DateStart, $RelDep/moles:DateEnd, $RelDep/moles:dgMetadataID, f:return-stub-activity('activity', data($RelDep/moles:ActivityID/moles:repositoryIdentifier), data($RelDep/moles:ActivityID/moles:localIdentifier)), f:return-stub-dpt('dataproductiontool', data($RelDep/moles:DataProductionToolID/moles:repositoryIdentifier), data($RelDep/moles:DataProductionToolID/moles:localIdentifier)), for $DE in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord where $DE/moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:repositoryIdentifier=$RelDep/moles:dgMetadataID/moles:repositoryIdentifier and $DE/moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:localIdentifier=$RelDep/moles:dgMetadataID/moles:localIdentifier return f:return-stub-dataentity('dataentity', data($DE/moles:dgMetadataID/moles:repositoryIdentifier), data($DE/moles:dgMetadataID/moles:localIdentifier)), $RelDep/moles:Coverage } (: </RelatedDeployment> :) } (: </dgObservationStation> :), for $strkwrd in $ObsStn/moles:dgStructuredKeyword return $strkwrd, if (exists($ObsStn/moles:DataProvenance)) then $ObsStn/moles:DataProvenance else (), if (exists($ObsStn/moles:MetadataSecurity)) then $ObsStn/moles:MetadataSecurity else () } (: End </dgMetadataRecord> :) ) (: End namespace strip :)"; 
     41        static String StubBDEQuery = "declare default element namespace 'http://ndg.nerc.ac.uk/moles/dataentity';declare namespace moles='http://ndg.nerc.ac.uk/moles';declare namespace f='http://ndg.nerc.ac.uk/moles/localfunctions';declare function f:strip-namespace($e as element()) as element(){element {QName('', local-name($e))}{let $parent :=$e let $childcount := count($parent/*) return if ($childcount>0) then for $child in ($e/*) return f:strip-namespace($child) else (data($e))}};declare function f:return-stub-activity($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element(){let $found := count(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid]) return if ($found = 0) then element {$out-element-name} {element error {'not found'},element repositoryIdentifier {$repid},element localIdentifier {$locid}} else (for $SRAct in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} {($SRAct/moles:dgMetadataID),($SRAct/moles:dgMetadataDescription),($SRAct/moles:name),($SRAct/moles:abbreviation),element dgActivity {if (exists($SRAct/*/moles:dgActivityDataCollection)) then ($SRAct/*/moles:dgActivityDataCollection) else if (exists($SRAct/*/moles:dgActivityDataProject)) then ($SRAct/*/moles:dgActivityDataProject) else if (exists($SRAct/*/dgActivityDataCampaign)) then ($SRAct/moles:dgActivity/moles:dgActivityDataCampaign) else ($SRAct/moles:dgActivity/moles:dgActivityDataInvestigation),($SRAct/moles:dgActivity/moles:dgActivityCoverage),($SRAct/moles:dgActivity/moles:dgActivityDuration)}})};declare function f:return-stub-dataentity($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element(){let $found := count(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid]) return if ($found = 0) then element {$out-element-name} {element error {'not found'},element repositoryIdentifier {$repid},element localIdentifier {$locid}} else (for $SRDE in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} {($SRDE/moles:dgMetadataID),($SRDE/moles:dgMetadataDescription),($SRDE/moles:name),($SRDE/moles:abbreviation),element dgDataEntity {($SRDE/moles:dgDataEntity/moles:dgDataSetType),($SRDE/moles:dgDataEntity/moles:dgDataGranule),($SRDE/moles:dgDataEntity/moles:dgDataSummary)}})};declare function f:return-stub-dpt($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element(){let $found := count(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid]) return if ($found = 0) then element {$out-element-name} {element error {'not found'},element repositoryIdentifier {$repid},element localIdentifier {$locid}} else (for $SRDPT in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} {$SRDPT/moles:dgMetadataID,$SRDPT/moles:dgMetadataDescription,$SRDPT/moles:name,$SRDPT/moles:abbreviation,$SRDPT/moles:logos,element dgDataProductionTool {$SRDPT/moles:dgDataProductionTool/moles:contactDetails,if (exists($SRDPT/moles:dgDataProductionTool/moles:dgModel)) then $SRDPT/moles:dgDataProductionTool/moles:dgModel else (),if (exists($SRDPT/moles:dgDataProductionTool/moles:dgInstrument)) then $SRDPT/moles:dgDataProductionTool/moles:dgInstrument else ()}})};declare function f:return-stub-obsstn($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element(){let $found := count(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid]) return if ($found = 0) then element {$out-element-name} {element error {'not found'},element repositoryIdentifier {$repid},element localIdentifier {$locid}} else (for $SRObsStn in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} {($SRObsStn/moles:dgMetadataID),($SRObsStn/moles:dgMetadataDescription),($SRObsStn/moles:name),($SRObsStn/moles:abbreviation),element dgObservationStation {($SRObsStn/moles:dgObservationStation/moles:contactDetails),if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform)) then element dgStationaryPlatform {$SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:position,if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgLandStation)) then element dgLandStation {''} else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgMooring)) then element dgMooring {''} else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgStationGroup)) then element dgStationGroup {''} else ()} else if (exists($SRObsStn/moles:dgObservationStation/moles:dgMovingPlatform)) then $SRObsStn/moles:dgObservationStation/moles:dgMovingPlatform else ()}})};declare function f:return-stub-person($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element(){let $found := count(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgPerson[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid]) return if ($found = 0) then element {$out-element-name} {element error {'not found'},element repositoryIdentifier {$repid},element localIdentifier {$locid}} else (for $person in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgPerson[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} {($person/moles:name),($person/moles:contactDetails),($person/moles:dgMetadataID)})};declare function f:return-stub-organisation($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element(){let $found := count(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgOrganisation[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid])return if ($found = 0) then element {$out-element-name} {element error {'not found'},element repositoryIdentifier {$repid},element localIdentifier {$locid}} else (for $org in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgOrganisation[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} {$org/moles:dgMetadataID,$org/moles:name,$org/moles:abbreviation,$org/moles:contactDetails,$org/moles:logos})};for $DE in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[exists(moles:dgDataEntity)and moles:dgMetadataID[moles:schemeIdentifier='NDG-B0' and moles:repositoryIdentifier='repositoryID' and moles:localIdentifier='localID']] return f:strip-namespace(element dgMetadataRecord {element dgMetadataID {element schemeIdentifier {'NDG-B1'},$DE/moles:dgMetadataID/moles:repositoryIdentifier,$DE/moles:dgMetadataID/moles:localIdentifier},$DE/moles:dgMetadataDescription,$DE/moles:name,$DE/moles:abbreviation,element dgDataEntity {$DE/moles:dgDataEntity/moles:dgDataSetType,$DE/moles:dgDataEntity/moles:dgDataObjectType,$DE/moles:dgDataEntity/moles:dgDataGranule,$DE/moles:dgDataEntity/moles:dgDataSummary,element dgDataRoles {if (exists($DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgMetadataID)) then element dgDataCreator {$DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgMetadataID,$DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:roleName,$DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:abbreviation,$DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:contactDetails,for $DataCreatorRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgRoleHolder order by $DataCreatorRole/moles:startDate empty least, $DataCreatorRole/moles:endDate empty least return element dgRoleHolder {if (exists($DataCreatorRole/moles:dgOrganisationID)) then f:return-stub-organisation('organisation', data($DataCreatorRole/moles:dgOrganisationID/moles:repositoryIdentifier), data($DataCreatorRole/moles:dgOrganisationID/moles:localIdentifier)) else if (exists($DataCreatorRole/moles:dgPersonID)) then f:return-stub-person('person', string($DataCreatorRole/moles:dgPersonID/moles:repositoryIdentifier), string($DataCreatorRole/moles:dgPersonID/moles:localIdentifier)) else (),$DataCreatorRole/moles:startDate,$DataCreatorRole/moles:endDate,$DataCreatorRole/moles:localName}} else (),if (exists($DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:dgMetadataID)) then element dgDataCurator {$DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:dgMetadataID,$DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:roleName,$DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:abbreviation,$DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:contactDetails,for $DataCuratorRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:dgRoleHolder order by $DataCuratorRole/moles:startDate empty least, $DataCuratorRole/moles:endDate empty least return element dgRoleHolder {if (exists($DataCuratorRole/moles:dgOrganisationID)) then f:return-stub-organisation('organisation', data($DataCuratorRole/moles:dgOrganisationID/moles:repositoryIdentifier), data($DataCuratorRole/moles:dgOrganisationID/moles:localIdentifier)) else if (exists($DataCuratorRole/moles:dgPersonID)) then f:return-stub-person('person', string($DataCuratorRole/moles:dgPersonID/moles:repositoryIdentifier), string($DataCuratorRole/moles:dgPersonID/moles:localIdentifier)) else (),$DataCuratorRole/moles:startDate,$DataCuratorRole/moles:endDate,$DataCuratorRole/moles:localName}} else (),if (exists($DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:dgMetadataID)) then element dgDataOtherRoles {$DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:dgMetadataID,$DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:roleName,$DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:abbreviation,$DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:contactDetails,for $DataOtherRolesRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:dgRoleHolder order by $DataOtherRolesRole/moles:startDate empty least, $DataOtherRolesRole/moles:endDate empty least return element dgRoleHolder {if (exists($DataOtherRolesRole/moles:dgOrganisationID)) then f:return-stub-organisation('organisation', data($DataOtherRolesRole/moles:dgOrganisationID/moles:repositoryIdentifier), data($DataOtherRolesRole/moles:dgOrganisationID/moles:localIdentifier)) else if (exists($DataOtherRolesRole/moles:dgPersonID)) then f:return-stub-person('person', string($DataOtherRolesRole/moles:dgPersonID/moles:repositoryIdentifier), string($DataOtherRolesRole/moles:dgPersonID/moles:localIdentifier)) else (),$DataOtherRolesRole/moles:startDate,$DataOtherRolesRole/moles:endDate,$DataOtherRolesRole/moles:localName}} else ()},for $RelDep in $DE/moles:dgDataEntity/moles:RelatedDeployment return element RelatedDeployment {$RelDep/moles:DateStart,$RelDep/moles:DateEnd,$RelDep/moles:dgMetadataID,f:return-stub-activity('activity', data($RelDep/moles:ActivityID/moles:repositoryIdentifier), data($RelDep/moles:ActivityID/moles:localIdentifier)),f:return-stub-dpt('dataproductiontool', data($RelDep/moles:DataProductionToolID/moles:repositoryIdentifier), data($RelDep/moles:DataProductionToolID/moles:localIdentifier)),f:return-stub-obsstn('observationstation', data($RelDep/moles:ObservationStationID/moles:repositoryIdentifier), data($RelDep/moles:ObservationStationID/moles:localIdentifier)),$RelDep/moles:Coverage},for $RelatedDataEntity in $DE/moles:dgDataEntity/moles:dgRelatedDataEntity return element relateddataentity {element relation {$RelatedDataEntity/moles:RelationID/moles:dgValidTerm,$RelatedDataEntity/moles:RelationID/moles:dgValidTermID},f:return-stub-dataentity('dataentity', data($RelatedDataEntity/(moles:RelatedDataEntityID | moles:RelatedDataGranuleID)/moles:repositoryIdentifier), data($RelatedDataEntity/(moles:RelatedDataEntityID | moles:RelatedDataGranuleID)/moles:localIdentifier))}},for $strkwrd in $DE/moles:dgStructuredKeyword return $strkwrd,if (exists($DE/moles:dgMetadataProvenance)) then $DE/moles:dgMetadataProvenance else (),if (exists($DE/moles:dgMetadataSecurity)) then $DE/moles:dgMetadataSecurity else ()})"; 
     42        static String StubBActQuery = "declare default element namespace 'http://ndg.nerc.ac.uk/moles/activity'; declare namespace moles='http://ndg.nerc.ac.uk/moles'; declare namespace f='http://ndg.nerc.ac.uk/moles/localfunctions';  declare function f:strip-namespace($e as element()) as element() {element {QName('', local-name($e))} {let $parent :=$e let $childcount := count($parent/*) return if ($childcount>0) then for $child in ($e/*) return f:strip-namespace($child) else (data($e))}} ;  declare function f:return-stub-activity($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element() {let $found := count(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid]) return if ($found = 0) then element {$out-element-name} {element error {'not found'}, element repositoryIdentifier {$repid}, element localIdentifier {$locid}} else (for $SRAct in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} {($SRAct/moles:dgMetadataID), ($SRAct/moles:dgMetadataDescription), ($SRAct/moles:name), ($SRAct/moles:abbreviation), element dgActivity {if (exists($SRAct/*/moles:dgActivityDataCollection)) then ($SRAct/*/moles:dgActivityDataCollection) else if (exists($SRAct/*/moles:dgActivityDataProject)) then ($SRAct/*/moles:dgActivityDataProject) else if (exists($SRAct/*/dgActivityDataCampaign)) then ($SRAct/moles:dgActivity/moles:dgActivityDataCampaign) else ($SRAct/moles:dgActivity/moles:dgActivityDataInvestigation), ($SRAct/moles:dgActivity/moles:dgActivityCoverage), ($SRAct/moles:dgActivity/moles:dgActivityDuration)}})};declare function f:return-stub-dataentity($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element() {let $found := count(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid]) return if ($found = 0) then element {$out-element-name} {element error {'not found'}, element repositoryIdentifier {$repid}, element localIdentifier {$locid}} else (for $SRDE in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} {($SRDE/moles:dgMetadataID), ($SRDE/moles:dgMetadataDescription), ($SRDE/moles:name), ($SRDE/moles:abbreviation), element dgDataEntity {($SRDE/moles:dgDataEntity/moles:dgDataSetType), ($SRDE/moles:dgDataEntity/moles:dgDataGranule), ($SRDE/moles:dgDataEntity/moles:dgDataSummary)}})};declare function f:return-stub-dpt($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element() {let $found := count(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid]) return if ($found = 0) then element {$out-element-name} {element error {'not found'}, element repositoryIdentifier {$repid}, element localIdentifier {$locid}} else (for $SRDPT in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} {$SRDPT/moles:dgMetadataID, $SRDPT/moles:dgMetadataDescription, $SRDPT/moles:name, $SRDPT/moles:abbreviation, $SRDPT/moles:logos, element dgDataProductionTool {$SRDPT/moles:dgDataProductionTool/moles:contactDetails, if (exists($SRDPT/moles:dgDataProductionTool/moles:dgModel)) then $SRDPT/moles:dgDataProductionTool/moles:dgModel else (), if (exists($SRDPT/moles:dgDataProductionTool/moles:dgInstrument)) then $SRDPT/moles:dgDataProductionTool/moles:dgInstrument else ()}})}; declare function f:return-stub-obsstn($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element() {let $found := count(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid]) return if ($found = 0) then element {$out-element-name} {element error {'not found'}, element repositoryIdentifier {$repid}, element localIdentifier {$locid}} else (for $SRObsStn in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} {($SRObsStn/moles:dgMetadataID), ($SRObsStn/moles:dgMetadataDescription), ($SRObsStn/moles:name), ($SRObsStn/moles:abbreviation), element dgObservationStation {($SRObsStn/moles:dgObservationStation/moles:contactDetails), if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform)) then element dgStationaryPlatform {$SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:position, if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgLandStation)) then element dgLandStation {''} else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgMooring)) then element dgMooring {''} else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgStationGroup)) then element dgStationGroup {''} else ()} else if (exists($SRObsStn/moles:dgObservationStation/moles:dgMovingPlatform)) then $SRObsStn/moles:dgObservationStation/moles:dgMovingPlatform else ()}})};declare function f:return-stub-person($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element() {let $found := count(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgPerson[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid]) return if ($found = 0) then element {$out-element-name} {element error {'not found'}, element repositoryIdentifier {$repid}, element localIdentifier {$locid}} else (for $person in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgPerson[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} {($person/moles:name), ($person/moles:contactDetails), ($person/moles:dgMetadataID)})}; declare function f:return-stub-organisation($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element() {let $found := count(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgOrganisation[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid]) return if ($found = 0) then element {$out-element-name} {element error {'not found'}, element repositoryIdentifier {$repid}, element localIdentifier {$locid}} else (for $org in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgOrganisation[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} {$org/moles:dgMetadataID, $org/moles:name, $org/moles:abbreviation, $org/moles:contactDetails, $org/moles:logos})};for $Act in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[ moles:dgActivity!='' and moles:dgMetadataID/moles:schemeIdentifier='NDG-B0' and moles:dgMetadataID/moles:repositoryIdentifier='repositoryID' and moles:dgMetadataID/moles:localIdentifier='localID'] return f:strip-namespace(element dgMetadataRecord {element dgMetadataID {element schemeIdentifier {'NDG-B1'}, (element repositoryIdentifier {data($Act/moles:dgMetadataID/moles:repositoryIdentifier)}), element localIdentifier {data($Act/moles:dgMetadataID/moles:localIdentifier)}}, $Act/moles:dgMetadataDescription, $Act/moles:name, $Act/moles:abbreviation, element dgActivity {for $RelatedActivities in $Act/dgActivity/moles:relatedActivity return element relatedActivity {$RelatedActivities/moles:activityRelation, f:return-stub-activity('activity', data($RelatedActivities/moles:relatedActivityID/moles:repositoryIdentifier), data($RelatedActivities/moles:relatedActivityID/moles:localIdentifier))},if (exists($Act/moles:dgActivity/moles:dgActivityDataCollection)) then ($Act/moles:dgActivity/moles:dgActivityDataCollection) else if (exists($Act/moles:dgActivity/moles:dgActivityDataProject)) then ($Act/moles:dgActivity/moles:dgActivityDataProject) else if (exists($Act/moles:dgActivity/moles:dgActivityDataInvestigation)) then ($Act/moles:dgActivity/moles:dgActivityDataInvestigation) else if (exists($Act/moles:dgActivity/moles:dgActivityDataCampaign)) then ($Act/moles:dgActivity/moles:dgActivityDataCampaign) else (), element dgActivityRole {element dgInvestigator {element dgPrincipalInvestigator {($Act/moles:dgActivity/moles:dgActivityRole/moles:dgInvestigator/moles:dgPrincipalInvestigator/moles:dgMetadataID), ($Act/moles:dgActivity/moles:dgActivityRole/moles:dgInvestigator/moles:dgPrincipalInvestigator/moles:roleName), ($Act/moles:dgActivity/moles:dgActivityRole/moles:dgInvestigator/moles:dgPrincipalInvestigator/moles:abbreviation), ($Act/moles:dgActivity/moles:dgActivityRole/moles:dgInvestigator/moles:dgPrincipalInvestigator/moles:contactDetails), for $PIRole in $Act/moles:dgActivity/moles:dgActivityRole/moles:dgInvestigator/moles:dgPrincipalInvestigator/moles:dgRoleHolder order by $PIRole/moles:startDate empty least, $PIRole/moles:endDate empty least return element dgRoleHolder {if (exists($PIRole/moles:dgOrganisationID)) then f:return-stub-organisation('organisation', data($PIRole/moles:dgOrganisationID/moles:repositoryIdentifier), data($PIRole/moles:dgOrganisationID/moles:localIdentifier)) else if (exists($PIRole/moles:dgPersonID)) then f:return-stub-person('person', string($PIRole/moles:dgPersonID/moles:repositoryIdentifier), string($PIRole/moles:dgPersonID/moles:localIdentifier)) else (), ($PIRole/moles:startDate), if (exists($PIRole/moles:endDate)) then ($PIRole/moles:endDate) else (), if (exists($PIRole/moles:localName)) then ($PIRole/moles:localName) else ()}},for $CI in $Act/moles:dgActivity/moles:dgActivityRole/moles:dgInvestigator/moles:dgCoInvestigator return element dgCoInvestigator {($CI/moles:dgMetadataID), ($CI/moles:roleName), ($CI/moles:abbreviation), ($CI/moles:contactDetails), for $CIRole in $CI/moles:dgRoleHolder order by $CIRole/moles:startDate empty least, $CIRole/moles:endDate empty least return element dgRoleHolder {if (exists(CIRole/moles:dgOrganisationID)) then f:return-stub-organisation('organisation', data($CIRole/moles:dgOrganisationID/moles:repositoryIdentifier), data($CIRole/moles:dgOrganisationID/moles:localIdentifier)) else if (exists($CIRole/moles:dgPersonID)) then f:return-stub-person('person', string($CIRole/moles:dgPersonID/moles:repositoryIdentifier), string($CIRole/moles:dgPersonID/moles:localIdentifier)) else (), ($CIRole/moles:startDate), if (exists($CIRole/moles:endDate)) then ($CIRole/moles:endDate) else (), if (exists($CIRole/moles:localName)) then ($CIRole/moles:localName) else ()}}},if (exists($Act/moles:dgActivity/moles:dgActivityRole/moles:dgTechnicalContact)) then (element dgTechnicalContact {($Act/moles:dgActivity/moles:dgActivityRole/moles:dgTechnicalContact/moles:dgMetadataID), ($Act/moles:dgActivity/moles:dgActivityRole/moles:dgTechnicalContact/moles:roleName), ($Act/moles:dgActivity/moles:dgActivityRole/moles:dgTechnicalContact/moles:abbreviation), ($Act/moles:dgActivity/moles:dgActivityRole/moles:dgTechnicalContact/moles:contactDetails), for $TechConRole in $Act/moles:dgActivity/moles:dgActivityRole/moles:dgTechnicalContact/moles:dgRoleHolder order by $TechConRole/moles:startDate empty least, $TechConRole/moles:endDate empty least return element dgRoleHolder {if (exists($TechConRole/moles:dgOrganisationID)) then f:return-stub-organisation('organisation', data($TechConRole/moles:dgOrganisationID/moles:repositoryIdentifier), data($TechConRole/moles:dgOrganisationID/moles:localIdentifier)) else if (exists($TechConRole/moles:dgPersonID)) then f:return-stub-person('person', string($TechConRole/moles:dgPersonID/moles:repositoryIdentifier), string($TechConRole/moles:dgPersonID/moles:localIdentifier)) else (), ($TechConRole/moles:startDate), if (exists($TechConRole/moles:endDate)) then ($TechConRole/moles:endDate) else (), if (exists($TechConRole/moles:localName)) then ($TechConRole/moles:localName) else ()}}) else (),if (exists($Act/dgActivity/dgActivityRole/dgProjectManager)) then (element dgProjectManager {($Act/dgActivity/dgActivityRole/dgProjectManager/dgMetadataID), ($Act/dgActivity/dgActivityRole/dgProjectManager/roleName), ($Act/dgActivity/dgActivityRole/dgProjectManager/abbreviation), ($Act/dgActivity/dgActivityRole/dgProjectManager/contactDetails), for $PMRole in $Act/dgActivity/dgActivityRole/dgProjectManager/dgRoleHolder order by $PMRole/startDate empty least, $PMRole/endDate empty least return element dgRoleHolder {if (exists($PMRole/moles:dgOrganisationID)) then f:return-stub-organisation('organisation', data($PMRole/moles:dgOrganisationID/moles:repositoryIdentifier), data($PMRole/moles:dgOrganisationID/moles:localIdentifier)) else if (exists($PMRole/moles:dgPersonID)) then f:return-stub-person('person', string($PMRole/moles:dgPersonID/moles:repositoryIdentifier), string($PMRole/moles:dgPersonID/moles:localIdentifier)) else (), ($PMRole/startDate), if (exists($PMRole/moles:endDate)) then ($PMRole/moles:endDate) else (), if (exists($PMRole/moles:localName)) then ($PMRole/moles:localName) else ()}}) else ()},for $RelDep in $Act/moles:dgActivity/moles:ActivityDeployment return element ActivityDeployment {($RelDep/moles:DateStart), if (exists($RelDep/moles:DateEnd)) then ($RelDep/moles:DateEnd) else (), ($RelDep/moles:dgMetadataID), f:return-stub-dpt('dataproductiontool', data($RelDep/moles:DataProductionToolID/moles:repositoryIdentifier), data($RelDep/moles:DataProductionToolID/moles:localIdentifier)), f:return-stub-obsstn('observationstation', data($RelDep/moles:ObservationStationID/moles:repositoryIdentifier), data($RelDep/moles:ObservationStationID/moles:localIdentifier)), for $DE in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord where $DE/moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:repositoryIdentifier=$RelDep/moles:dgMetadataID/moles:repositoryIdentifier and $DE/moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:localIdentifier=$RelDep/moles:dgMetadataID/moles:localIdentifier return f:return-stub-dataentity('dataentity', data($DE/moles:dgMetadataID/moles:repositoryIdentifier), data($DE/moles:dgMetadataID/moles:localIdentifier))}, (: </ActivityDeployment> :) if (exists($Act/dgActivityCoverage)) then ($Act/dgActivityCoverage) else (), if (exists($Act/dgActivityDuration)) then ($Act/dgActivityDuration) else ()} ,for $strkwrd in $Act/moles:dgStructuredKeyword return $strkwrd, if (exists($Act/moles:dgMetadataProvenance)) then $Act/moles:dgMetadataProvenance else (), if (exists($Act/moles:dgMetadataSecurity)) then $Act/moles:dgMetadataSecurity else ()})"; 
     43        static String StubBDPTQuery = "declare default element namespace 'http://ndg.nerc.ac.uk/moles/dataproductiontool';declare namespace moles='http://ndg.nerc.ac.uk/moles';declare namespace f='http://ndg.nerc.ac.uk/moles/localfunctions';declare function f:strip-namespace($e as element()) as element(){element {QName('', local-name($e))}{let $parent :=$e let $childcount := count($parent/*) return if ($childcount>0) then for $child in ($e/*) return f:strip-namespace($child) else (data($e))}};declare function f:return-stub-activity($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element(){let $found := count(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid]) return if ($found = 0) then element {$out-element-name} {element error {'not found'},element repositoryIdentifier {$repid},element localIdentifier {$locid}} else (for $SRAct in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} {($SRAct/moles:dgMetadataID),($SRAct/moles:dgMetadataDescription),($SRAct/moles:name),($SRAct/moles:abbreviation),element dgActivity {if (exists($SRAct/*/moles:dgActivityDataCollection)) then ($SRAct/*/moles:dgActivityDataCollection) else if (exists($SRAct/*/moles:dgActivityDataProject)) then ($SRAct/*/moles:dgActivityDataProject) else if (exists($SRAct/*/dgActivityDataCampaign)) then ($SRAct/moles:dgActivity/moles:dgActivityDataCampaign) else ($SRAct/moles:dgActivity/moles:dgActivityDataInvestigation),($SRAct/moles:dgActivity/moles:dgActivityCoverage),($SRAct/moles:dgActivity/moles:dgActivityDuration)}})};declare function f:return-stub-dataentity($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element(){let $found := count(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid]) return if ($found = 0) then element {$out-element-name} {element error {'not found'},element repositoryIdentifier {$repid},element localIdentifier {$locid}} else (for $SRDE in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} {($SRDE/moles:dgMetadataID),($SRDE/moles:dgMetadataDescription),($SRDE/moles:name),($SRDE/moles:abbreviation),element dgDataEntity {($SRDE/moles:dgDataEntity/moles:dgDataSetType),($SRDE/moles:dgDataEntity/moles:dgDataGranule),($SRDE/moles:dgDataEntity/moles:dgDataSummary)}})};declare function f:return-stub-dpt($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element(){let $found := count(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid]) return if ($found = 0) then element {$out-element-name} {element error {'not found'},element repositoryIdentifier {$repid},element localIdentifier {$locid}}else (for $SRDPT in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} {$SRDPT/moles:dgMetadataID,$SRDPT/moles:dgMetadataDescription,$SRDPT/moles:name,$SRDPT/moles:abbreviation,$SRDPT/moles:logos,element dgDataProductionTool {$SRDPT/moles:dgDataProductionTool/moles:contactDetails,if (exists($SRDPT/moles:dgDataProductionTool/moles:dgModel)) then $SRDPT/moles:dgDataProductionTool/moles:dgModel else (),if (exists($SRDPT/moles:dgDataProductionTool/moles:dgInstrument)) then $SRDPT/moles:dgDataProductionTool/moles:dgInstrument else ()}})};declare function f:return-stub-obsstn($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element(){let $found := count(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid]) return if ($found = 0) then element {$out-element-name} {element error {'not found'},element repositoryIdentifier {$repid},element localIdentifier {$locid}} else (for $SRObsStn in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} {($SRObsStn/moles:dgMetadataID),($SRObsStn/moles:dgMetadataDescription),($SRObsStn/moles:name),($SRObsStn/moles:abbreviation),element dgObservationStation {($SRObsStn/moles:dgObservationStation/moles:contactDetails),if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform)) then element dgStationaryPlatform {$SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:position,if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgLandStation)) then element dgLandStation {''} else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgMooring)) then element dgMooring {''} else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgStationGroup)) then element dgStationGroup {''} else ()} else if (exists($SRObsStn/moles:dgObservationStation/moles:dgMovingPlatform)) then $SRObsStn/moles:dgObservationStation/moles:dgMovingPlatform else ()}})};declare function f:return-stub-person($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element(){let $found := count(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgPerson[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid]) return if ($found = 0) then element {$out-element-name} {element error {'not found'},element repositoryIdentifier {$repid},element localIdentifier {$locid}} else (for $person in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgPerson[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name}{($person/moles:name),($person/moles:contactDetails),($person/moles:dgMetadataID)})};declare function f:return-stub-organisation($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element(){let $found := count(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgOrganisation[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid]) return if ($found = 0) then element {$out-element-name} {element error {'not found'},element repositoryIdentifier {$repid},element localIdentifier {$locid}} else (for $org in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgOrganisation[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} {$org/moles:dgMetadataID,$org/moles:name,$org/moles:abbreviation,$org/moles:contactDetails,$org/moles:logos})};for $DPT in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgDataProductionTool!='' and moles:dgMetadataID/moles:schemeIdentifier='NDG-B0' and moles:dgMetadataID/moles:repositoryIdentifier='repositoryID' and moles:dgMetadataID/moles:localIdentifier='localID'] return f:strip-namespace(element dgMetadataRecord {$DPT/dgMetadataID,element dgMetadataID {element schemeIdentifier {'NDG-B1'},$DPT/moles:dgMetadataID/moles:repositoryIdentifier,$DPT/moles:dgMetadataID/moles:localIdentifier},$DPT/moles:dgMetadataDescription,$DPT/moles:name,$DPT/moles:abbreviation,element dgDataProductionTool {$DPT/moles:contactDetails,if (exists($DPT/moles:dgModel)) then $DPT/moles:dgModel else $DPT/moles:dgInstrument,if (exists($DPT/moles:dgDPTRoles)) then element dgDPTRoles {'Roles are available, and will be added soon'} else(),for $RelDep in $DPT/moles:dgDataProductionTool/moles:DPTDeployment return element DPTDeployment {$RelDep/moles:DateStart,$RelDep/moles:DateEnd,$RelDep/moles:dgMetadataID,f:return-stub-activity('activity', data($RelDep/moles:ActivityID/moles:repositoryIdentifier), data($RelDep/moles:ActivityID/moles:localIdentifier)),f:return-stub-obsstn('observationstation', data($RelDep/moles:ObservationStationID/moles:repositoryIdentifier), data($RelDep/moles:ObservationStationID/moles:localIdentifier)),for $DE in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord where $DE/moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:repositoryIdentifier=$RelDep/moles:dgMetadataID/moles:repositoryIdentifier and $DE/moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:localIdentifier=$RelDep/moles:dgMetadataID/moles:localIdentifier return f:return-stub-dataentity('dataentity', data($DE/moles:dgMetadataID/moles:repositoryIdentifier), data($DE/moles:dgMetadataID/moles:localIdentifier)),$RelDep/moles:Coverage}},for $strkwrd in $DPT/moles:dgStructuredKeyword return $strkwrd,if (exists($DPT/moles:dgMetadataProvenance)) then $DPT/moles:dgMetadataProvenance else (),if (exists($DPT/moles:dgMetadataSecurity)) then $DPT/moles:dgMetadataSecurity else ()})"; 
     44        static String StubBObsStnQuery = "declare default element namespace 'http://ndg.nerc.ac.uk/moles/observationstation';declare namespace moles='http://ndg.nerc.ac.uk/moles';declare namespace f='http://ndg.nerc.ac.uk/moles/localfunctions';declare function f:strip-namespace($e as element()) as element(){element {QName('', local-name($e))}{let $parent :=$e let $childcount := count($parent/*) return if ($childcount>0) then for $child in ($e/*) return f:strip-namespace($child) else (data($e))}};declare function f:return-stub-activity($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element(){let $found := count(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid]) return if ($found = 0) then element {$out-element-name} {element error {'not found'},element repositoryIdentifier {$repid},element localIdentifier {$locid}}else (for $SRAct in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} {($SRAct/moles:dgMetadataID),($SRAct/moles:dgMetadataDescription),($SRAct/moles:name),($SRAct/moles:abbreviation),element dgActivity {if (exists($SRAct/*/moles:dgActivityDataCollection)) then ($SRAct/*/moles:dgActivityDataCollection) else if (exists($SRAct/*/moles:dgActivityDataProject)) then ($SRAct/*/moles:dgActivityDataProject) else if (exists($SRAct/*/dgActivityDataCampaign)) then ($SRAct/moles:dgActivity/moles:dgActivityDataCampaign) else ($SRAct/moles:dgActivity/moles:dgActivityDataInvestigation),($SRAct/moles:dgActivity/moles:dgActivityCoverage),($SRAct/moles:dgActivity/moles:dgActivityDuration)}})};declare function f:return-stub-dataentity($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element(){let $found := count(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid]) return if ($found = 0) then element {$out-element-name} {element error {'not found'},element repositoryIdentifier {$repid},element localIdentifier {$locid}} else (for $SRDE in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} {($SRDE/moles:dgMetadataID),($SRDE/moles:dgMetadataDescription),($SRDE/moles:name),($SRDE/moles:abbreviation),element dgDataEntity {($SRDE/moles:dgDataEntity/moles:dgDataSetType),($SRDE/moles:dgDataEntity/moles:dgDataGranule),($SRDE/moles:dgDataEntity/moles:dgDataSummary)}})};declare function f:return-stub-dpt($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element(){let $found := count(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid]) return if ($found = 0) then element {$out-element-name} {element error {'not found'},element repositoryIdentifier {$repid},element localIdentifier {$locid}} else (for $SRDPT in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} {$SRDPT/moles:dgMetadataID,$SRDPT/moles:dgMetadataDescription,$SRDPT/moles:name,$SRDPT/moles:abbreviation,$SRDPT/moles:logos,element dgDataProductionTool {$SRDPT/moles:dgDataProductionTool/moles:contactDetails,if (exists($SRDPT/moles:dgDataProductionTool/moles:dgModel)) then $SRDPT/moles:dgDataProductionTool/moles:dgModel else (),if (exists($SRDPT/moles:dgDataProductionTool/moles:dgInstrument)) then $SRDPT/moles:dgDataProductionTool/moles:dgInstrument else ()}})};declare function f:return-stub-obsstn($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element(){let $found := count(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid]) return if ($found = 0) then element {$out-element-name} {element error {'not found'},element repositoryIdentifier {$repid},element localIdentifier {$locid}} else (for $SRObsStn in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} {($SRObsStn/moles:dgMetadataID),($SRObsStn/moles:dgMetadataDescription),($SRObsStn/moles:name),($SRObsStn/moles:abbreviation),element dgObservationStation {($SRObsStn/moles:dgObservationStation/moles:contactDetails),if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform)) then element dgStationaryPlatform {$SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:position,if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgLandStation)) then element dgLandStation {''} else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgMooring)) then element dgMooring {''} else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgStationGroup)) then element dgStationGroup {''} else ()} else if (exists($SRObsStn/moles:dgObservationStation/moles:dgMovingPlatform)) then $SRObsStn/moles:dgObservationStation/moles:dgMovingPlatform else ()}})};declare function f:return-stub-person($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element(){let $found := count(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgPerson[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid]) return if ($found = 0) then element {$out-element-name} {element error {'not found'},element repositoryIdentifier {$repid},element localIdentifier {$locid}} else (for $person in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgPerson[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name}{($person/moles:name),($person/moles:contactDetails),($person/moles:dgMetadataID)})};declare function f:return-stub-organisation($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element(){let $found := count(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgOrganisation[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid]) return if ($found = 0) then element {$out-element-name} {element error {'not found'},element repositoryIdentifier {$repid},element localIdentifier {$locid}} else (for $org in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgOrganisation[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} {$org/moles:dgMetadataID,$org/moles:name,$org/moles:abbreviation,$org/moles:contactDetails,$org/moles:logos})};for $ObsStn in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgObservationStation!='' and moles:dgMetadataID/moles:schemeIdentifier='NDG-B0' and moles:dgMetadataID/moles:repositoryIdentifier='repositoryID' and moles:dgMetadataID/moles:localIdentifier='localID'] return f:strip-namespace(element dgMetadataRecord {element dgMetadataID {element schemeIdentifier {'NDG-B1',$ObsStn/moles:dgMetadataID/moles:repositoryIdentifier,$ObsStn/moles:dgMetadataID/moles:localIdentifier},$ObsStn/moles:dgMetadataDescription,$ObsStn/moles:name,$ObsStn/moles:abbreviation,element dgObservationStation {$ObsStn/moles:dgObservationStation/moles:contactDetails,if (exists($ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform)) then element dgStationaryPlatform {$ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:position,if (exists($ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring)) then element dgMooring {$ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/moles:dateStart,$ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/moles:dateEnd,for $DepositingCruise in $ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/moles:DepositingCruise return f:return-stub-activity('depositingcruise', data($DepositingCruise/moles:dgMetadataID/moles:repositoryIdentifier), data($DepositingCruise/moles:dgMetadataID/moles:localIdentifier)),if (exists($ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/moles:dgStationGrouping)) then for $StationGrouping in $ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/dgStationGrouping return f:return-stub-obsstn('stationgrouping', data($StationGrouping/moles:dgMetadataID/moles:repositoryIdentifier), data($StationGrouping/moles:dgMetadataID/moles:localIdentifier)) else ()} else if (exists($ObsStn/dgObservationStation/dgStationaryPlatform/dgStationGroup)) then element dgStationGroup {element dgGroupedStations {if (exists($ObsStn/dgObservationStation/dgStationaryPlatform/dgStationGroup/dgGroupedStations)) then for $GroupedStation in $ObsStn/dgObservationStation/dgStationaryPlatform/dgStationGroup/dgGroupedStation/dgGroupedStations return f:return-stub-obsstn('dgGroupedStation', data($GroupedStation/moles:dgMetadataID/moles:repositoryIdentifier), data($GroupedStation/moles:dgMetadataID/moles:localIdentifier)) else ()}} else $ObsStn/moles:dgObservationStation/moles:dgLandStation} else $ObsStn/moles:dgObservationStation/moles:dgMovingPlatform},for $RelDep in $ObsStn/moles:dgObservationStation/moles:ObsStationDeployment return element ObsStationDeployment {$RelDep/moles:DateStart,$RelDep/moles:DateEnd,$RelDep/moles:dgMetadataID,f:return-stub-activity('activity', data($RelDep/moles:ActivityID/moles:repositoryIdentifier), data($RelDep/moles:ActivityID/moles:localIdentifier)),f:return-stub-dpt('dataproductiontool', data($RelDep/moles:DataProductionToolID/moles:repositoryIdentifier), data($RelDep/moles:DataProductionToolID/moles:localIdentifier)),for $DE in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord where $DE/moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:repositoryIdentifier=$RelDep/moles:dgMetadataID/moles:repositoryIdentifier and $DE/moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:localIdentifier=$RelDep/moles:dgMetadataID/moles:localIdentifier return f:return-stub-dataentity('dataentity', data($DE/moles:dgMetadataID/moles:repositoryIdentifier), data($DE/moles:dgMetadataID/moles:localIdentifier)),$RelDep/moles:Coverage}},for $strkwrd in $ObsStn/moles:dgStructuredKeyword return $strkwrd,if (exists($ObsStn/moles:dgMetadataProvenance)) then $ObsStn/moles:dgMetadataProvenance else (),if (exists($ObsStn/moles:dgMetadataSecurity)) then $ObsStn/moles:dgMetadataSecurity else ()})"; 
    4545        static String MOLESQuery = "declare default element namespace 'http://ndg.nerc.ac.uk/moles';for $Moles in collection('/db/ndg_B_metadata')/dgMetadata/dgMetadataRecord[dgMetadataID/schemeIdentifier='NDG-B0' and dgMetadataID/repositoryIdentifier='RepositoryID' and dgMetadataID/localIdentifier='LocalID'] return $Moles"; 
    4646        static String DublinCoreDEQuery = "declare default element namespace 'http://ndg.nerc.ac.uk/moles'; declare namespace dc='http://purl.org/dc/elements/1.1/'; declare namespace oai_dc='http://www.openarchives.org/OAI/2.0/oai_dc'; declare variable $gcmd_science_valids as xs:string {'http://gcmd.gsfc.nasa.gov/Resources/valids/gcmd_parameters.html'}; declare variable $gcmd_project_valids as xs:string {'http://gcmd.gsfc.nasa.gov/Resources/valids/projects.html'}; declare variable $cf_standard_names as xs:string {'http://www.cgd.ucar.edu/cms/eaton/cf-metadata/standard_name.html'}; declare variable $iso_topic_list as xs:string {'http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_TopicCategoryCode'}; for $DE in collection('/db/ndg_B_metadata')/dgMetadata/dgMetadataRecord[dgDataEntity!='' and dgMetadataID/schemeIdentifier='NDG-B0' and dgMetadataID/repositoryIdentifier='badc.nerc.ac.uk' and dgMetadataID/localIdentifier='dataent1'] return <oai_dc:dc xmlns:oai_dc='http://www.openarchives.org/OAI/2.0/oai_dc/' xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd'> { element dc:title {string($DE/name)}, element dc:type {'Dataset'}, element dc:identifier {concat($DE/dgMetadataID/repositoryIdentifier, ':DC:', $DE/dgMetadataID/localIdentifier)}, element dc:description {string($DE/dgMetadataDescription/abstract/abstractText)}, element dc:date { if (exists($DE/(dgMetadataProvenance | DataProvenance)/RecordUpdate/UpdateDate)) then for $updatedate in $DE/(dgMetadataProvenance | DataProvenance)/RecordUpdate/UpdateDate order by xs:date($updatedate) descending return xs:date($updatedate[1]) else string($DE/(dgMetadataProvenance | DataProvenance)/RecordCreation/CreatedDate) }, for $StructuredKeyword in distinct-values($DE/dgStructuredKeyword [dgValidTermID/ParentListID=$cf_standard_names or dgValidTermID/ParentListID=$gcmd_science_valids or dgValidTermID/ParentListID=$gcmd_project_valids or dgValidTermID/ParentListID=$iso_topic_list ]//dgValidTerm) order by $StructuredKeyword return element dc:subject {string($StructuredKeyword)}, for $StructuredKeyword1 in distinct-values($DE/dgDataEntity/dgDataSummary/dgParameterSummary/dgStdParameterMeasured[dgValidTermID/ParentListID=$cf_standard_names or dgValidTermID/ParentListID=$gcmd_science_valids or dgValidTermID/ParentListID=$gcmd_project_valids]//dgValidTerm) order by $StructuredKeyword1 return element dc:subject {string($StructuredKeyword1)}, for $DataCreatorRole in $DE/dgDataEntity/dgDataRoles/dgDataCreator/dgRoleHolder order by $DataCreatorRole/startDate empty least return for $DataCreatorRoleHolder in collection('/db/ndg_B_metadata')/dgMetadata/(dgOrganisation | dgPerson) [(dgMetadataID/schemeIdentifier='NDG-B0' and dgMetadataID/repositoryIdentifier=$DataCreatorRole/(dgOrganisationID | dgPersonID)/repositoryIdentifier and dgMetadataID/localIdentifier=$DataCreatorRole/(dgOrganisationID | dgPersonID)/localIdentifier)] return element dc:creator { if (string(local-name($DataCreatorRoleHolder))='dgOrganisation') then (string($DataCreatorRoleHolder/name)) else if (string(local-name($DataCreatorRoleHolder))='dgPerson') then (string(concat(string($DataCreatorRoleHolder/name/initials), ' ', string($DataCreatorRoleHolder/name/familyName)))) else ('empty content') }, for $DataCuratorRole in $DE/dgDataEntity/dgDataRoles/dgDataCurator/dgRoleHolder[not(exists(endDate)) or endDate=''] order by $DataCuratorRole/startDate empty least return for $DataCuratorRoleHolder in collection('/db/ndg_B_metadata')/dgMetadata/(dgOrganisation | dgPerson) [(dgMetadataID/schemeIdentifier='NDG-B0' and dgMetadataID/repositoryIdentifier=$DataCuratorRole/(dgOrganisationID | dgPersonID)/repositoryIdentifier and dgMetadataID/localIdentifier=$DataCuratorRole/(dgOrganisationID | dgPersonID)/localIdentifier)] return element dc:publisher { if (string(local-name($DataCuratorRoleHolder))='dgOrganisation') then (string($DataCuratorRoleHolder/name)) else if (string(local-name($DataCuratorRoleHolder))='dgPerson') then (string(concat(string($DataCuratorRoleHolder/name/initials), ' ', string($DataCuratorRoleHolder/name/familyName)))) else ('empty content') } } </oai_dc:dc>"; 
Note: See TracChangeset for help on using the changeset viewer.