Commit 44a6a56c authored by jbierma's avatar jbierma
Browse files

Merge branch 'feature/#122-Confluence' into 'develop'

bugfix for confluence module (closes #122)

Closes #122

See merge request !88
parents 60ba1062 9f26d779
...@@ -19,50 +19,49 @@ declare namespace xhtml="http://www.w3.org/1999/xhtml"; ...@@ -19,50 +19,49 @@ declare namespace xhtml="http://www.w3.org/1999/xhtml";
declare variable $confluence:collection := $config:app-root || '/docs'; declare variable $confluence:collection := $config:app-root || '/docs';
declare variable $confluence:httprequestget := "<http:request method='get' />"; declare variable $confluence:httprequestget := "<http:request method='get' />";
declare function confluence:confluence($node as node(), $model as map(*), $id as xs:string) as node()* declare function confluence:confluence($node as node(), $model as map(*), $id as xs:string) as node()* {
{
let $lastRevinDb := confluence:getLastRevInDb($id)
let $revisionInWiki := confluence:getLastRevInWiki($id)
let $revisionInWiki := if ($revisionInWiki=-1) then ($lastRevinDb) else ()
(: Only for debugging, needs to be commented out for productive state :) let $httprequestget := "<http:request method='get'><http:header name='connection' value='close' /></http:request>"
(: let $lastRevinDb := 0:) let $lastRevinDb := confluence:getLastRevInDb($id)
let $revisionInWiki := confluence:getLastRevInWiki($id)
let $revisionInWiki := if ($revisionInWiki=-1) then ($lastRevinDb) else ($revisionInWiki)
let $config-lang := string(config:get("lang.default", "multilanguage")) let $config-lang := string(config:get("lang.default", "multilanguage")),
let $lang := if($config-lang = "") then "" else app:getLanguage() $lang := if($config-lang = "") then "" else app:getLanguage()
return return
if( $revisionInWiki = $lastRevinDb ) if( $revisionInWiki = $lastRevinDb )
then doc($confluence:collection || "/" || $id || '_' || $lang || '.rev' || $lastRevinDb || '.xml' ) then (
else ( doc($confluence:collection || "/" || $id || '_' || $lang || '.rev' || $lastRevinDb || '.xml' )
let $login := xmldb:login("/db", "admin", "" ) )
let $remove := else (
xmldb:get-child-resources( $confluence:collection )[starts-with(., $id)] let $login := xmldb:login("/db", "admin", "" )
! xmldb:remove($confluence:collection , . ) let $remove :=
let $url:= config:get("confluence.url", "wiki") || $id || '?expand=body.storage' xmldb:get-child-resources( $confluence:collection )[starts-with(., $id)]
let $export := http:send-request($httprequestget, $url) ! xmldb:remove($confluence:collection , . )
let $map := xs:base64Binary($export[2]/text()) let $url:= config:get("confluence.url", "wiki") || $id || '?expand=body.storage'
=> string() let $httprequestget := <http:request href="{ $url }" method="get" />
=> util:base64-decode() let $export := http:send-request($httprequestget)
=> parse-json() let $map := parse-json(util:base64-decode($export[2]))
let $result := map:get(map:get(map:get($map, "body")[1], "storage"), "value") let $result := map:get(map:get(map:get($map, "body"), "storage"), "value")
let $result := local:replaceParsingErrors($result) let $result := local:replaceParsingErrors($result)
let $result := '<ac:confluence xmlns:ac="http://www.atlassian.com/schema/confluence/4/ac/" xmlns:ri="http://www.atlassian.com/schema/confluence/4/ri/" xmlns="http://www.atlassian.com/schema/confluence/4/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.atlassian.com/schema/confluence/4/ac/ ">' || $result || "</ac:confluence>" let $result := '<ac:confluence xmlns:ac="http://www.atlassian.com/schema/confluence/4/ac/" xmlns:ri="http://www.atlassian.com/schema/confluence/4/ri/" xmlns="http://www.atlassian.com/schema/confluence/4/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.atlassian.com/schema/confluence/4/ac/ ">' || $result || "</ac:confluence>"
let $result as element() := parse-xml( $result )/* let $result as element() := parse-xml( $result )/*
let $result := local:remove-element-ns-deep( $result ) let $result := local:remove-element-ns-deep( $result )
let $result := <div id="wiki">{ local:confluenceparser($result, $id) }</div> let $result := <div id="wiki">{local:confluenceparser($result, $id)}</div>
let $allLanguages := app:getAllLanguages()
let $forLoop := map:merge(
for $el in $allLanguages
let $resultLangSpecific := local:confluenceparseLanguage($result, $el)
let $store := xmldb:store( $confluence:collection, $id || '_' || $el || '.rev' || $revisionInWiki || '.xml' , $resultLangSpecific )
return map:entry($el, $store)
)
let $allLanguages := app:getAllLanguages() let $result := doc( $forLoop( $lang ) )
let $forLoop := map:merge( return ($result)
for $el in $allLanguages )
let $resultLangSpecific := local:confluenceparseLanguage($result, $el)
let $store := xmldb:store( $confluence:collection, $id || '_' || $el || '.rev' || $revisionInWiki || '.xml' , $resultLangSpecific )
return map:entry($el, $store)
)
let $result := doc( $forLoop( $lang ) )
return ($result)
)
}; };
(:~ (:~
...@@ -175,7 +174,7 @@ declare function local:confluenceparser($nodes as node()*, $id) ...@@ -175,7 +174,7 @@ declare function local:confluenceparser($nodes as node()*, $id)
attribute class {"title"} attribute class {"title"}
} }
}) })
default default
return return
element xhtml:span { element xhtml:span {
...@@ -232,7 +231,7 @@ declare function local:retrieveImageUrl($pageId, $imageName) { ...@@ -232,7 +231,7 @@ declare function local:retrieveImageUrl($pageId, $imageName) {
}; };
:) :)
declare function confluence:getLastRevInDb($id) as xs:integer declare function confluence:getLastRevInDb($id) as xs:integer
{ {
let $num := xmldb:get-child-resources( $confluence:collection )[contains(., $id)][1] let $num := xmldb:get-child-resources( $confluence:collection )[contains(., $id)][1]
=> substring-after('.rev') => substring-after('.rev')
...@@ -248,30 +247,27 @@ declare function confluence:getLastRevInDb($id) as xs:integer ...@@ -248,30 +247,27 @@ declare function confluence:getLastRevInDb($id) as xs:integer
: Returns the last revision number we get from Confluence : Returns the last revision number we get from Confluence
: @param $id – the ID of a Confluence page : @param $id – the ID of a Confluence page
: :) : :)
declare function confluence:getLastRevInWiki($id as xs:string) as xs:integer declare function confluence:getLastRevInWiki($id as xs:string) as xs:integer {
{ let $url := config:get("confluence.url", "wiki")||$id||"/history?expand=lastUpdated"
let $rest := let $httprequestget := <http:request href="{ $url }" method="get" />
http:send-request let $rest := http:send-request($httprequestget)
( let $statuscode := $rest[1]/@status
$httprequestget,
config:get("confluence.url", "wiki")||$id||"/history?expand=lastUpdated"
)
let $map := if ($statuscode = 200) then (
parse-json(util:base64-decode($rest[2]))
)
else ()
let $statuscode := $rest/@statusCode let $revision := if ($statuscode = 200) then (
string(map:get (map:get($map, "lastUpdated"), "number"))
)
else (-1)
let $map := if ($statuscode = 200) then (parse-json( return
util:base64-decode(string(xs:base64Binary($rest[2]/text()))) $revision
)) };
else ()
let $revision := if ($statuscode = 200) then (string(map:get (map:get($map, "lastUpdated"), "number")))
else (-1)
return
$revision
};
declare function local:HTML2html($node) declare function local:HTML2html($node)
{ {
for $node in $node for $node in $node
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment