Changeset 826 for MDRepository


Ignore:
Timestamp:
11/01/10 13:24:46 (14 years ago)
Author:
ljo
Message:

cmd-model.xqm - first merge.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • MDRepository/trunk/xquery/cmd-model.xqm

    r825 r826  
    4242declare function cmd-model:query-model($cmd-index-path as xs:string, $collection as xs:string+, $format as xs:string, $max-depth as xs:integer) as item()? {
    4343       
    44         let $name := cmd-model:gen-cache-id("model", ($collection, $cmd-index-path), xs:string($max-depth)),
    45         $doc :=
     44  let $name := cmd-model:gen-cache-id("model", ($collection, $cmd-index-path), xs:string($max-depth)),
     45    $doc :=
    4646    if (cmd-model:is-in-cache($name)) then
    4747      cmd-model:get-from-cache($name)
    4848    else
    49         let $data := cmd-model:elem($collection, $cmd-index-path, $max-depth)
    50                 return cmd-model:store-in-cache($name, $data)
    51 
    52         return
    53         cmd-model:serialise-as($doc, $format)   
     49      let $data := cmd-model:elem($collection, $cmd-index-path, $max-depth)
     50        return cmd-model:store-in-cache($name, $data)
     51  return
     52    cmd-model:serialise-as($doc, $format)       
    5453};
    5554
     
    5958declare function cmd-model:get-collections($collections as xs:string+, $format as xs:string, $max-depth as xs:integer) as item() {
    6059  let $name := cmd-model:gen-cache-id("collection", $collections, xs:string($max-depth)),
    61         $doc :=
     60    $doc :=
    6261    if (cmd-model:is-in-cache($name)) then
    6362       cmd-model:get-from-cache($name)
    6463    else
    65                 let $data := cmd-model:colls($collections, $max-depth)
    66                 return cmd-model:store-in-cache($name, $data)
    67         return
    68         cmd-model:serialise-as($doc, $format)
     64      let $data := cmd-model:colls($collections, $max-depth)
     65        return cmd-model:store-in-cache($name, $data)
     66  return
     67    cmd-model:serialise-as($doc, $format)
    6968};
    7069
     
    7473declare function cmd-model:search-retrieve($cql-query as xs:string, $collections as xs:string+, $format as xs:string, $start-item as xs:integer, $end-item as xs:integer) as item()* {
    7574  let $collection := collection($cmd-model:cmdiMirrorPath),
     75    $decoded-query := xdb:decode($cql-query),
     76    $sanitized-query := cmd-model:sanitize-query($decoded-query),
    7677    $results :=
    7778    if ($collections[1] eq $cmd-model:collectionRoot) then
    78       util:eval(fn:concat("$collection", xdb:decode($cql-query), "/ancestor::CMD"))
     79      util:eval(fn:concat("$collection", $sanitized-query, "/ancestor-or-self::CMD"))
    7980    else
    80       for $coll in $collections return util:eval(fn:concat("$collection", xdb:decode($cql-query), "/ancestor::CMD[descendant::IsPartOf = '", xdb:decode($coll) ,"']"))
     81      for $coll in $collections return util:eval(fn:concat("$collection", $sanitized-query, "/ancestor-or-self::CMD[descendant::IsPartOf = '", xdb:decode($coll) ,"']"))
    8182
    8283    let $result-count := fn:count($results),
     
    8687    <searchRetrieveResponse>
    8788      <numberOfRecords>{$result-count}</numberOfRecords>
    88       <echoedSearchRetrieveRequest>{$cql-query, $collections, $start-item, $end-item}</echoedSearchRetrieveRequest>
     89      <echoedSearchRetrieveRequest>{if ($decoded-query ne $sanitized-query) then "Rewritten to descendant-or-self::CMD" else $cql-query, $collections, $start-item, $end-item}</echoedSearchRetrieveRequest>
    8990      <diagnostics>{$seq-count}</diagnostics>
    9091      <records>
     
    9899};
    99100
    100 (: **********************
    101         queryModel - subfunctions
    102 C:)
     101(:
     102  **********************
     103  queryModel - subfunctions
     104:)
     105
     106declare function cmd-model:sanitize-query($query as xs:string) as xs:string {
     107if ($query = ("//*", "descendant::element()")) then "/descendant-or-self::CMD" else $query
     108};
    103109
    104110declare function cmd-model:elem($collections as xs:string+, $path as xs:string, $depth as xs:integer) as element() {
     
    156162
    157163
    158 (: **********************
    159         getCollections - subfunctions   :)
     164(:
     165  **********************
     166  getCollections - subfunctions
     167:)
    160168
    161169declare function cmd-model:colls($collections as xs:string+, $max-depth as xs:integer) as element() {
     
    208216};
    209217
    210 (:  Get the next level collection-records (ResourceType='Metadata')
     218(:
     219  Get the next level collection-records (ResourceType='Metadata')
    211220  rely on the ResourceProxy of the parent (param)
    212221:)
     
    218227};
    219228
    220 (: count ALL (independent of maxDepth) resource-records (ie actually ResourceType=Resource, but
    221                         there are records without ResourceProxy[ResourceType=Resource] - so care for that (not(exists((ResourceType))))
     229(:
     230  count ALL (independent of maxDepth) resource-records (ie actually ResourceType=Resource, but
     231  there are records without ResourceProxy[ResourceType=Resource] -
     232  so care for that (not(exists((ResourceType))))
    222233:)
    223234declare function cmd-model:get-resource-count($handle as xs:string) as xs:string {
     
    225236};
    226237
    227 (: this is complement to cmd-model:get-resource-count()
    228                  count ALL (independent of maxDepth) collection-records (ie ResourceType=Metadata                       
     238(:
     239  This is complement to cmd-model:get-resource-count()
     240  count ALL (independent of maxDepth) collection-records
     241  (ie ResourceType=Metadata)                   
    229242:)
    230243declare function cmd-model:get-collection-count($handle as xs:string) as xs:string {
     
    232245};
    233246
    234 (: Try to derive a name from the collection-record (more-or-less agnostic about the actual schema.
     247(:
     248  Try to derive a name from the collection-record (more-or-less agnostic about
     249  the actual schema.
    235250:)
    236251declare function cmd-model:get-md-collection-name($collection-doc as node()) as xs:string {
     
    238253};
    239254
    240 (: ***********************
    241 HELPER function - dealing with caching the results
    242 :)
    243 
    244 
    245 (: Function for telling wether the document is available or not.
    246 generic, currently not used
     255(:
     256  ***********************
     257  HELPER function - dealing with caching the results
     258:)
     259
     260
     261(:
     262  Function for telling wether the document is available or not.
     263  generic, currently not used
    247264:)
    248265declare function cmd-model:is-doc-available($collection as xs:string, $doc-name as xs:string) as xs:boolean {
     
    295312        $item
    296313};
    297 
Note: See TracChangeset for help on using the changeset viewer.