@@ -536,7 +536,7 @@ declare function setup:rewrite-config($import-configs as node()+, $silent as xs:
536536 <groups xmlns = "http://marklogic.com/xdmp/group" >{
537537 let $default-group := ($import-configs/self::*:configuration/@default-group , "Default" )[1 ]
538538 for $group in fn:distinct-values ((
539- $import-configs/descendant-or-self::gr:group /gr:group-name,
539+ $import-configs/descendant-or-self::gr:group /gr:group-name/ fn:string () ,
540540 $import-configs/descendant-or-self::*/(
541541 self::gr:http-server, self::gr:xdbc-server,
542542 self::gr:odbc-server, self::gr:task-server, self::db:database
@@ -559,7 +559,7 @@ declare function setup:rewrite-config($import-configs as node()+, $silent as xs:
559559 let $databases := $import-configs/descendant-or-self::db:database[
560560 @group = $group or ( $group = $default-group and fn:empty (@group ) )
561561 ]
562- let $group-config := $import-configs/descendant-or-self::gr:group [gr:group-name = $group]
562+ let $group-config := $import-configs/descendant-or-self::gr:group [gr:group-name/ fn:string () = $group]
563563 where fn:exists ($servers | $databases | $group-config)
564564 return
565565 <group>
@@ -608,7 +608,7 @@ declare function setup:rewrite-config($import-configs as node()+, $silent as xs:
608608 let $_ :=
609609 if ($silent) then ()
610610 else
611- for $group in $config/gr:groups/gr:group /gr:group-name
611+ for $group in $config/gr:groups/gr:group /gr:group-name/ fn:string ()
612612 let $hosts := ($config/ho:hosts/ho:host[ho:group /@name = $group], try { xdmp:group-hosts (xdmp:group ($group)) } catch ($ignore) {})
613613 where fn:empty ($hosts)
614614 return
@@ -621,6 +621,43 @@ declare function setup:rewrite-config($import-configs as node()+, $silent as xs:
621621 return if ($keep-comments) then $config else setup:suppress-comments ($config)
622622};
623623
624+ declare function setup:split-config ($config as element (configuration), $app-name as xs:string) as node ()* {
625+ for $part in (
626+ $config/*/*,
627+ $config/gr:groups/gr:group /(
628+ (gr:http-servers, gr:xdbc-servers, gr:odbc-servers)/*,
629+ gr:task-server
630+ )
631+ )
632+ let $type := fn:local-name ($part)
633+
634+ let $name :=
635+ if ($part instance of element (gr:task-server)) then
636+ "TaskServer"
637+ else
638+ $part/*[local-name () = ("name" , "forest-name" , "local-name" , concat ($type, "-name" ))][1 ]
639+ /fn:replace (fn:replace (fn:string (), "^(.*/)?([^/]+)" , "$2" ), "^\$\{group\}$" , "default-group" )
640+
641+ let $path := fn:replace (fn:replace ($type, "(http|xdbc|odbc|task)-" , "" ) || "s" , "ys$" , "ies" )
642+ let $path :=
643+ if (fn:contains (fn:namespace-uri ($part), "security" )) then
644+ "security/" || $path
645+ else
646+ fn:replace ($path, "assignments/" , "forests/" )
647+
648+ let $file := fn:replace ($name, "(@ml.|[${}])" , "" ) || ".xml"
649+
650+ return (
651+ comment { "SAVE-PART-AS:" || $path || "/" || $file },
652+ typeswitch ($part)
653+ case element (gr:group )
654+ return element gr:group {
655+ $part/@*,
656+ $part/(node () except (gr:http-servers, gr:xdbc-servers, gr:odbc-servers, gr:task-server))
657+ }
658+ default return $part
659+ )
660+ };
624661
625662(:
626663 base-name : Original forest base name - this should be the name from the config.
0 commit comments