Changeset 258


Ignore:
Timestamp:
03/19/10 14:32:10 (14 years ago)
Author:
ljo
Message:

cmd-model - Rudimentary version of API function getCollections

Location:
MDService/trunk/xquery
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • MDService/trunk/xquery/cmd-model.xql

    r256 r258  
    2020    else
    2121      $cmd-index,
    22     $format := request:get-parameter("format", "xml"),
     22    $format := request:get-parameter("format", $cmd-model:responseFormatXml),
    2323    $collection := fn:concat("/db/cmdi-mirror/", request:get-parameter("collection", "silang_data")),
    2424    $max-depth as xs:integer := xs:integer(request:get-parameter("maxdepth", 1))
    2525    return
    2626      if ($operation eq $cmd-model:getCollections) then
    27         (:cmd-model:get-collections() :) <error>Unimplemented</error>
     27        cmd-model:get-collections($collection, $format, $max-depth)
    2828      else if ($operation eq $cmd-model:queryModel) then
    2929        cmd-model:query-model($cmd-index-path, $collection, $format, $max-depth)
  • MDService/trunk/xquery/cmd-model.xqm

    r256 r258  
    2323declare variable $cmd-model:docTypeTerms as xs:string := "Terms";
    2424declare variable $cmd-model:docTypeSuffix as xs:string := "Values";
     25
     26declare variable $cmd-model:responseFormatXml as xs:string := "xml";
     27declare variable $cmd-model:responseFormatJSon as xs:string := "json";
     28declare variable $cmd-model:responseFormatText as xs:string := "text";
    2529
    2630declare variable $cmd-model:xmlExt as xs:string := ".xml";
     
    7074
    7175(:
     76  Recurse for collections
     77:)
     78declare function cmd-model:recurse-collections($collection as xs:string, $depth as xs:integer) as item()* {
     79    let $children := xdb:get-child-collections($collection)
     80    return
     81      if (fn:exists($children)) then
     82          let $child-results :=
     83            for $child in $children
     84            return
     85              cmd-model:recurse-collections(concat($collection, '/', xs:string($child)), $depth),
     86              $current := <Collection>{$collection}</Collection>
     87          return ($current, $child-results)
     88      else
     89      <Collection>{$collection}</Collection>
     90};
     91
     92(:
    7293
    7394:)
     
    174195};
    175196
     197(:
     198  Seraliseringsformat.
     199:)
     200declare function cmd-model:serialise-as($item as node(), $format as xs:string) as item()? {
     201      if ($format eq $cmd-model:responseFormatJSon) then
     202        let $option := util:declare-option("exist:serialize", "method=text media-type=application/json")
     203          return
     204           (: json:xml-to-json($item) :) $item
     205      else (: $cmd-model:responseFormatXml, $cmd-model:responseFormatText:)
     206        $item
     207};
     208
     209
    176210(:~
    177211  API function queryModel.
    178212:)
    179 declare 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 node() {
    180       if ($format eq "json") then
    181         let $option := util:declare-option("exist:serialize", "method=text media-type=application/json")
    182           return
    183            (: json:xml-to-json( :) cmd-model:get-result-doc($collection, $cmd-index-path, $max-depth) (:) :)
    184       else
    185         cmd-model:get-result-doc($collection, $cmd-index-path, $max-depth)
    186 };
     213declare 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() {
     214        cmd-model:serialise-as(cmd-model:get-result-doc($collection, $cmd-index-path, $max-depth), $format)
     215};
     216
     217(:~
     218  API function getCollections.
     219:)
     220declare function cmd-model:get-collections($collections as xs:string+, $format as xs:string, $max-depth as xs:integer) as item() {
     221  let $children := for $collection-item in $collections
     222                    return
     223                      cmd-model:recurse-collections($collection-item, $max-depth)
     224   return
     225     cmd-model:serialise-as(<Collections count="{count($children)}" root="{$collections}">{$children}</Collections>, $format)
     226
     227};
Note: See TracChangeset for help on using the changeset viewer.