Changeset 626 for MDRepository


Ignore:
Timestamp:
08/16/10 16:20:54 (14 years ago)
Author:
ljo
Message:

Some improvments for getCollections.

File:
1 edited

Legend:

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

    r619 r626  
    7878  Recurse for collections
    7979:)
    80 declare function cmd-model:recurse-collections($collection as node()+, $parent as xs:string, $depth as xs:integer) as item()* {
     80declare function cmd-model:recurse-collections($collection as node()+, $parent as xs:string, $handle as xs:string, $proxy-id as xs:string, $depth as xs:integer) as item()* {
    8181    let $children := if ($depth eq 0) then () else $collection//ResourceProxy[ResourceType = "Metadata"]
    8282    return
     
    8585            for $child in $children
    8686              let $child-doc := doc(concat(util:collection-name($child/root()), "/", $child/ResourceRef)),
    87                 $child-name := ($child-doc//Corpus/Name, "UNKNOWN")[1]
    88             return if (empty($child-doc)) then <no-target>{util:collection-name($child/root())}</no-target> else
    89               cmd-model:recurse-collections($child-doc, $child-name, $depth - 1)
     87                $child-name := ($child-doc//Corpus/Name, $child-doc//Session/Name, "UNKNOWN")[1]
     88            return if (empty($child-doc)) then <no-target proxy-id="{$child/@id}">{<proxy>{$child}</proxy>, <in-document>{concat(util:collection-name($child/root()), "/", util:document-name($child/root()))}</in-document>}</no-target> else
     89              cmd-model:recurse-collections($child-doc, $child-name, $child-doc//Header/MdSelfLink, $child/@id, $depth - 1)
    9090          return
    91           <c n="{$parent}" cnt="{sum($child-results/@cnt)}">{$child-results}</c>
     91          <c n="{$parent}" handle="{$handle}" proxy-id="{$proxy-id}" cnt="{sum($child-results/*:c/@cnt)}">{$child-results}</c>
    9292      else
    93       <c n="{$parent}" cnt="{count(collection(concat(util:collection-name($collection/CMD[1]/root()), "/../"))//CMD)}"></c>
     93      <c n="{$parent}" handle="{$handle}" proxy-id="{$proxy-id}" cnt="{count(collection(concat(util:collection-name($collection/CMD[1]/root()), "/../"))//CMD[not(//ResourceType[. = "Metadata"])])}"></c>
    9494};
    9595
     
    260260      else
    261261        let $children := for $collection-item in $collections
    262           let $collection-item-doc := collection(concat($collection-item, "/", "Corpusstructure"))
     262          let $collection-item-docs := collection(concat($collection-item, "/", "Corpusstructure"))
    263263        return
    264           cmd-model:recurse-collections($collection-item-doc, "", $max-depth)
     264          for $collection-doc in $collection-item-docs//CMD return
     265          cmd-model:recurse-collections($collection-doc, ($collection-doc//Corpus/Name, $collection-doc//Session/Name, "UNKNOWN")[1], $collection-doc//MdSelfLink, "", $max-depth)
    265266          return
    266             cmd-model:store-collection-data(<Collections count="{count($children)}" root="{$collections}">{$children}</Collections>, $names[1], $names[2])
     267            cmd-model:store-collection-data(<Collections count="{count($children/@cnt)}" root="{$collections}">{$children}</Collections>, $names[1], $names[2])
    267268return
    268269  cmd-model:serialise-as(cmd-model:get-doc($names[1], $names[2]), $format)
Note: See TracChangeset for help on using the changeset viewer.