teacup/locks.xqm

568 lines
27 KiB
Plaintext

(:~
: Lock Library.
:
: @author Rave Technologies, https://www.rave-tech.com/, 2017
:)
module namespace locks = 'http://www.rave-tech.com/bloomsbury/locks';
import module namespace config = 'http://www.rave-tech.com/bloomsbury/config' at './module/config.xqm';
import module namespace audit = 'http://www.rave-tech.com/bloomsbury/audit' at './module/manage-audit.xqm';
import module namespace blcommon = 'http://www.rave-tech.com/bloomsbury/common' at 'common.xqm';
declare namespace dbk = "http://docbook.org/ns/docbook";
(:~
: Checkout/lock files to work on. This will checkout latest version only.
: <lock><content><coid></coid><version>v1</version><uri>../dummy/fileurl</uri></content>...</lock>
: @param $body Paremeters to lock content into the system <lock><content><coid></coid><version>v1</version><uri>../dummy/fileurl</uri></content>...</lock>
: <cid> = content id
: <coid> = component id
: @param $type A flat to download all content (all,none)
: @header $authorization Authorization key
: @return element(result)
:)
declare
%updating
%rest:path("/locks")
%rest:POST("{$body}")
%rest:query-param("type", "{$type}", "NONE")
%rest:header-param("Authorization", "{$authorization}", "none")
%rest:consumes("application/xml", "text/xml")
function locks:checkout(
$body as document-node(),
$type as xs:string,
$authorization as xs:string
)
{
config:session-check($authorization),
try
{
if($type='NONE' or ($type!="none" and $type!="all"))
then
update:output(<result><status>Failure</status><message>Please supply correct format type</message></result>)
else
let $userID := fn:substring-before(config:session-value($authorization),'$$$$')
let $userName := fn:doc(fn:concat($config:CoreDatabase,$config:UserDir,$userID,'.xml'))/user/name/string()
let $lockUri := fn:concat($config:LockDir,$userID,'.xml')
let $prepareLock := let $countRequiredCheckout := fn:count($body/lock/content)
for $dbUri in if(($countRequiredCheckout eq 1) and ($type!='all'))
then $body/lock/content/uri/text()
else
if(($countRequiredCheckout gt 1) and ($type!="all"))
then $body/lock/content/uri/text()
else
if(($countRequiredCheckout eq 1 or $countRequiredCheckout gt 1) and ($type='all'))
then
for $db in db:list()[not(contains(.,$config:CoreDatabase) or contains(.,$config:ContentManagementDatabase) or contains(.,$config:MetadataOnlyContentDatabase) or contains(.,$config:OnixDB ))]
for $contentid in $body/lock/content/cid
for $uri in fn:uri-collection(fn:concat($db ,$config:ContentDir,$body/lock/content/$contentid))[fn:not(fn:contains(.,$config:AuditFileName)
or fn:contains(.,$config:InfoXml)
or fn:contains(.,$config:MetaXml)
or fn:contains(.,$config:WordDir)
or fn:contains(.,$config:VersionControlFileName)
or fn:contains(.,$config:VersionDir))]
[fn:contains(.,'/content/latest/')]
return $uri
else $body/lock/content/uri/text()
let $version := let $versionControlUri := fn:concat(fn:substring-before($dbUri, 'content/latest/'),$config:VersionControlFileName)
return
if(fn:doc-available($versionControlUri))
then
let $versionDoc := doc($versionControlUri)
let $nextVersion := fn:sum(fn:max($versionDoc/versions/version/@number) + 1)
return $nextVersion
else 1
let $isAlreadyCheckedOut := db:open($config:CoreDatabase,$config:LockDir)/locks/lock/files/file[uri=$dbUri]
[version=$version]
for $ctype in fn:tokenize($dbUri,'/')[2]
return
if($isAlreadyCheckedOut)
then <error>Already Checkout {$dbUri}</error>
else
<file>
<uri>{$dbUri}</uri>
<version>{$version}</version>
<title>{if((fn:doc($dbUri)//*:title)[1]//text()) then (fn:doc($dbUri)//*:title)[1]//text() else fn:replace(fn:tokenize($dbUri,'/')[fn:last()],'.xml','')}</title>
<ctype>{$ctype}</ctype>
</file>
let $lockChunk := <lock>
<id>{random:uuid()}</id>
<requester-id>{fn:substring-before(config:session-value($authorization),'$$$$')}</requester-id>
<name>{$userName}</name>
<requester-email>{distinct-values(db:open($config:CoreDatabase,$config:UserDir)/user[fn:not(fn:matches(fn:base-uri(.),'(/version/|/audit/)'))][id=fn:substring-before(config:session-value($authorization),'$$$$')]/email)}</requester-email>
<checked-out-on>{fn:current-dateTime()}</checked-out-on>
<files>{$prepareLock}</files>
</lock>
return
if($lockChunk/files/error)
then
(
update:output(<result><status>Failure</status><message>Some files are already checked-out</message></result>)
,
config:update-message("[Checkout][Some files are already checked-out : " || fn:string-join(for $file in $lockChunk/files/error return fn:substring-after($file,'Already Checkout'),';') || "]")
)
else
if(fn:count($lockChunk/files/file) gt 0)
then
(
if(fn:doc-available(fn:concat($config:CoreDatabase,$lockUri)))
then insert node $lockChunk into fn:doc(fn:concat($config:CoreDatabase,$lockUri))/locks
else db:replace($config:CoreDatabase,$lockUri,<locks>{$lockChunk}</locks>)
,
update:output(<result><status>Success</status><message>File(s) locked</message><lockedfiles>{fn:count($lockChunk/files/file)}</lockedfiles></result>)
,
config:update-message("[Checkout][" || fn:count($lockChunk/files/file) || " file(s) has been checked-out by user: " || fn:substring-after(config:session-value($authorization),'$$$$') ||"]")
,
for $eachFile in $lockChunk/files/file
let $ctype := fn:tokenize($eachFile/uri/text(),'/')[2]
return audit:update($eachFile,$ctype,config:session-value($authorization),'Checkout')
)
else
(
update:output(<result><status>Failure</status><message>No file(s) has been checked-out. Please supply correct information</message></result>)
,
config:update-message("[Checkout][No file(s) has been checked-out by user: " || config:session-value($authorization) ||"]")
)
}
catch *
{
admin:write-log("[Checkout][Error: " || $err:description || "]"),
admin:write-log("[Checkout][Error: " || $err:additional || "]"),
update:output(<result><status>Error</status><message>Error generated. Please check system log</message></result>)
}
};
(:~
: To get all checked-out files by a specific user
: @param $user User ID of the user
: @param $page Page number of the list optional
: @param $size Total number of records to display in a page optional
: @header $authorization Authorization key
: @return element(result)
:)
declare
%rest:path("/locks")
%rest:GET
%rest:query-param("query", "{$query}","")
%rest:query-param("user", "{$userid}")
%rest:query-param("allrecords", "{$allrecords}","")
%rest:query-param("page", "{$page}")
%rest:query-param("size", "{$size}")
%rest:header-param("Authorization", "{$authorization}", "none")
function locks:list(
$userid as xs:string,
$query as xs:string?,
$allrecords as xs:string,
$page as xs:integer?,
$size as xs:integer?,
$authorization as xs:string
)
{
config:session-check($authorization),
try
{
let $lockRecords := <locks>{
for $eachLock in db:open($config:CoreDatabase,$config:LockDir)/locks/lock[if($userid and $allrecords='true') then (db:open('bloomsbury','/user/')/user[role='admin'][id=$userid]) else requester-id=$userid]
[if($query!='') then fn:matches(name,$query,'i') else .]
for $eachFile in $eachLock/files/file[fn:contains(uri,'header.xml')]
let $uri := $eachFile/uri
let $requester-id := $eachLock/requester-id/string()
let $version := $eachFile/version
let $title := $eachFile/title
let $cid := <cid>{fn:substring-before(fn:substring-before(fn:substring-after($uri,$config:ContentDir),$config:ContentDir),'/')}</cid>
let $coid := <coid>{fn:substring-after(fn:substring-before(fn:substring-after($uri,$config:ContentDir),$config:ContentDir),'/')}</coid>
let $ctype := $eachFile/ctype/string()
let $username := <user>{distinct-values(db:open($config:CoreDatabase,$config:UserDir)/user[id=$requester-id][fn:not(fn:matches(fn:base-uri(.),'(/version/|/audit/)'))]/name/string())}</user>
let $delete := <deleted>{
if(fn:doc( fn:concat(blcommon:get-db-name($ctype),$config:ContentDir,fn:data($cid),'/',fn:data($coid),'/',$config:InfoXml) )/info[delete='yes'] )
then 'true' else 'false'
}</deleted>
let $checkedOutOn := $eachLock/checked-out-on
let $headeruri := fn:uri-collection(fn:concat(blcommon:get-db-name($ctype),$config:ContentDir))[fn:contains(.,'/content/latest')]
[contains(.,$config:HeaderXml)]
[fn:tokenize(.,'/')[4]=$cid]
[fn:not(fn:contains(.,$config:VersionDir))]
let $headertitle := <header-title>{(fn:doc($headeruri)//*:title/text())[1]}</header-title>
let $ctype := <content-type>{$ctype}</content-type>
let $job := db:open($config:CoreDatabase,$config:JobDir)/job[job-info/job-type='Checkin'][job-info/lock/file/uri=$uri]
[ingestion-report/status='InQueue' or ingestion-report/status='InProgress']
let $jobSubmitted := <JobSubmitted>{if($job) then 'Yes' else 'No'}</JobSubmitted>
return <lock>{$uri,$headertitle,$version,$title,$checkedOutOn,$cid,$coid,$ctype,$username,$jobSubmitted}</lock>
}</locks>
let $countRecord := fn:count($lockRecords/lock)
return
if($lockRecords/lock)
then
(
(:<result><status>Success</status><total>{$countRecord}</total><entities>{$lockRecords/lock[fn:position() = $start to $end]}</entities></result>,:)
<result><status>Success</status><total>{$countRecord}</total><entities>{$lockRecords/lock}</entities></result>,
config:non-update-message("[Lock List][Lock list has been sent successfully]")
)
else
(
<result><status>Success</status><message>Lock information is unavailable</message></result>,
config:non-update-message("[Lock List][Lock list is not available]")
)
}
catch *
{
admin:write-log("[Lock List][Error: " || $err:description || "]"),
admin:write-log("[Lock List][Error: " || $err:additional || "]"),
<result><status>Error</status><message>Error generated. Please check system log</message></result>
}
};
(:~
: To check file is checked-out or not, specific to Content ID/Component ID
: @param $cid Content ID to download its component, not multiple
: @param $coid Component ID, not multiple
: @header $authorization Authorization key
: @return element(result)
:)
declare
%rest:path("/locks/{$cid=.+}/{$coid=.+}")
%rest:GET
%rest:header-param("Authorization", "{$authorization}", "none")
function locks:is-locked(
$cid as xs:string,
$coid as xs:string,
$authorization as xs:string
)
{
config:session-check($authorization),
try
{
let $lockRecord := db:open($config:CoreDatabase,$config:LockDir)/locks/lock/files/file[if($cid) then fn:matches(fn:tokenize(uri,'/')[4],$cid) else .]
[if($coid) then fn:matches(fn:tokenize(uri,'/')[5],$coid) else .]
return
if($lockRecord)
then
(
<result><status>Success</status><message>File is locked</message></result>,
config:non-update-message("[Lock File][File is locked : " || $cid || " / " || $coid || "]")
)
else
(
<result><status>Failure</status><message>File is not locked</message></result>,
config:non-update-message("[Lock File][File is not locked : " || $cid || " / " || $coid || "]")
)
}
catch *
{
admin:write-log("[Lock File][Error: " || $err:description || "]"),
admin:write-log("[Lock File][Error: " || $err:additional || "]"),
<result><status>Error</status><message>Error generated. Please check system log</message></result>
}
};
(:~
: Undo checked-out, specific to Content ID/Content Type
: @param $cid Content ID to download its component, not multiple
: @param $coid Component ID, not multiple
: @header $authorization Authorization key
: @return element(result)
:)
declare
%updating
%rest:path("/locks/{$ctype=.+}/{$cid=.+}/{$coid=.+}")
%rest:DELETE
%rest:header-param("Authorization", "{$authorization}", "none")
function locks:delete(
$ctype as xs:string,
$cid as xs:string,
$coid as xs:string,
$authorization as xs:string
)
{
config:session-check($authorization),
try
{
for $lockRecord in db:open($config:CoreDatabase,$config:LockDir)/locks/lock/files/file[if($cid) then fn:matches(fn:tokenize(uri,'/')[4],$cid) else .]
[if($coid) then fn:matches(fn:tokenize(uri,'/')[5],$coid) else .]
return
if($lockRecord)
then
(
update:output(<result><status>Success</status><message>Successfully unlocked the file</message></result>),
config:update-message("[Un-lock File][File unlocked : " || $cid || " / " || $coid || "]"),
if(fn:count($lockRecord/parent::files/file) eq 1)
then
(
delete node $lockRecord/parent::files(:,
audit:update($lockRecord/uri/text(),$ctype,config:session-value($authorization),'UnDo Checkout'):)
)
else
(
delete node $lockRecord(:,
audit:update($lockRecord/uri/text(),$ctype,config:session-value($authorization),'UnDo Checkout'):)
)
)
else
(
update:output(<result><status>Failure</status><message>File is not locked</message></result>),
config:update-message("[Un-lock File][File is not locked : " || $cid || " / " || $coid || "]")
)
}
catch *
{
admin:write-log("[Un-lock File][Error: " || $err:description || "]"),
admin:write-log("[Un-lock File][Error: " || $err:additional || "]"),
update:output(<result><status>Error</status><message>Error generated. Please check system log</message></result>)
}
};
declare
%updating
%rest:path("/delete-lock")
%rest:POST("{$body}")
%rest:header-param("Authorization", "{$authorization}", "none")
%rest:consumes("application/xml", "text/xml")
function locks:bulk-unlock(
$body as document-node(),
$authorization as xs:string
)
{
config:session-check($authorization),
try{
<results>{
let $isAllfilesLocked :=let $uris := for $uri in $body/delete/content/uri/string()
let $lockRecordArray := string-join(db:open('bloomsbury','/locks/')/locks/lock/files/file/uri/string(),'|')
return
if(fn:matches($lockRecordArray,$uri))
then ()
else $uri[not(matches($lockRecordArray,$uri))]
return
$uris
return
if($isAllfilesLocked!='')
then
<result><status>Failure</status><message>Some files are not locked</message></result>
else
for $uri in $body/delete/content/uri/string()
let $lockRecord := db:open('bloomsbury','/locks/')/locks/lock/files/file[uri=$uri]
let $lockedUri := $lockRecord/uri/string()
let $ctype := fn:tokenize($lockedUri,'/')[2]
return
(
<result><status>Success</status><message>Successfully unlocked the file</message></result>,
config:update-message("[Un-lock File][File unlocked : " || $lockedUri || " / " || $lockedUri || "]"),
delete node $lockRecord,
audit:update($lockRecord/uri/text(),$ctype,config:session-value($authorization),'UnDo Checkout')
)
}
</results>
}
catch *
{
admin:write-log("[Unlock content][Error: " || $err:description || "]"),
admin:write-log("[Unlock content][Error: " || $err:additional || "]"),
update:output(<result><status>Error</status><message>Error generated. Please check system log</message></result>)
}
};
declare
%rest:path("/locks-content")
%rest:GET
%rest:query-param("query", "{$query}","")
%rest:query-param("user", "{$userid}")
%rest:query-param("allrecords", "{$allrecords}","")
%rest:query-param("page", "{$page}")
%rest:query-param("size", "{$size}")
%rest:header-param("Authorization", "{$authorization}", "none")
function locks:list-content(
$userid as xs:string,
$query as xs:string?,
$allrecords as xs:string,
$page as xs:integer?,
$size as xs:integer?,
$authorization as xs:string
)
{
config:session-check($authorization),
try
{
let $lockRecords := <locks>{
for $eachLock in db:open($config:CoreDatabase,$config:LockDir)/locks/lock[if($userid and $allrecords='true') then (db:open('bloomsbury','/user/')/user[role='admin'][id=$userid]) else requester-id=$userid]
(:[if($query!='') then fn:matches(name,$query,'i') else .]:)
[if($query!='') then let $requesterid := requester-id/string() return fn:matches((fn:collection(fn:concat('bloomsbury/user/',$requesterid,'.xml'))/user/name/string()),$query,'i' ) else .]
for $eachFile in $eachLock/files/file[if($eachLock/files/file/ctype='looseleaf') then fn:contains(uri,'header.xml') else .]
let $uri := $eachFile/uri
let $requester-id := $eachLock/requester-id/string()
let $version := $eachFile/version
let $title := $eachFile/title
let $cid := <cid>{fn:substring-before(fn:substring-before(fn:substring-after($uri,$config:ContentDir),$config:ContentDir),'/')}</cid>
let $coid := <coid>{fn:substring-after(fn:substring-before(fn:substring-after($uri,$config:ContentDir),$config:ContentDir),'/')}</coid>
(:let $ctype := $eachFile/ctype/string():)
let $ctype := if($eachFile/ctype) then $eachFile/ctype/string() else 'looseleaf'
let $username := <user>{distinct-values(db:open($config:CoreDatabase,$config:UserDir)/user[id=$requester-id][fn:not(fn:matches(fn:base-uri(.),'(/version/|/audit/)'))]/name/string())}</user>
let $delete := <deleted>{
if(fn:doc( fn:concat(blcommon:get-db-name($ctype),$config:ContentDir,fn:data($cid),'/',fn:data($coid),'/',$config:InfoXml) )/info[delete='yes'] )
then 'true' else 'false'
}</deleted>
let $checkedOutOn := $eachLock/checked-out-on
let $headeruri := fn:uri-collection(fn:concat(blcommon:get-db-name($ctype),$config:ContentDir))[fn:contains(.,'/content/latest')]
[contains(.,$config:HeaderXml)]
[fn:tokenize(.,'/')[4]=$cid]
[fn:not(fn:contains(.,$config:VersionDir))]
let $headertitle := <header-title>{(fn:doc($headeruri)//*:title/text())[1]}</header-title>
let $ctype := <content-type>{$ctype}</content-type>
let $job := db:open($config:CoreDatabase,$config:JobDir)/job[job-info/job-type='Checkin'][job-info/lock/file/uri=$uri]
[ingestion-report/status='InQueue' or ingestion-report/status='InProgress']
let $jobSubmitted := <JobSubmitted>{if($job) then 'Yes' else 'No'}</JobSubmitted>
return <lock>{$uri,$headertitle,$version,$title,$checkedOutOn,$cid,$coid,$ctype,$username,$jobSubmitted}</lock>
,
for $eachLock in db:open($config:CoreDatabase,$config:LockDir)/locks/lock[if($userid and $allrecords='true') then (db:open('bloomsbury','/user/')/user[role='admin'][id=$userid]) else requester-id=$userid]
for $eachFile in $eachLock/files[file/ctype='looseleaf'][not(contains(string-join(file/uri/string(),'|'),'header.xml'))]/file[1]
let $uri := $eachFile/uri
let $requester-id := $eachLock/requester-id/string()
let $version := $eachFile/version
let $title := $eachFile/title
let $cid := <cid>{fn:substring-before(fn:substring-before(fn:substring-after($uri,$config:ContentDir),$config:ContentDir),'/')}</cid>
let $coid := <coid>{fn:substring-after(fn:substring-before(fn:substring-after($uri,$config:ContentDir),$config:ContentDir),'/')}</coid>
let $ctype := (:$eachFile/file/ctype/string():) fn:tokenize($uri,'/')[2]
let $username := <user>{distinct-values(db:open($config:CoreDatabase,$config:UserDir)/user[id=$requester-id][fn:not(fn:matches(fn:base-uri(.),'(/version/|/audit/)'))]/name/string())}</user>
let $delete := <deleted>{
if(fn:doc( fn:concat(blcommon:get-db-name($ctype),$config:ContentDir,fn:data($cid),'/',fn:data($coid),'/',$config:InfoXml) )/info[delete='yes'] )
then 'true' else 'false'
}</deleted>
let $checkedOutOn := $eachLock/checked-out-on
let $headeruri := <uri>{fn:uri-collection(fn:concat(blcommon:get-db-name($ctype),$config:ContentDir))[fn:contains(.,'/content/latest')]
[contains(.,$config:HeaderXml)]
[fn:tokenize(.,'/')[4]=$cid]
[fn:not(fn:contains(.,$config:VersionDir))]}</uri>
let $job := db:open($config:CoreDatabase,$config:JobDir)/job[job-info/job-type='Checkin'][job-info/lock/file/uri=$uri]
[ingestion-report/status='InQueue' or ingestion-report/status='InProgress']
let $jobSubmitted := <JobSubmitted>{if($job) then 'Yes' else 'No'}</JobSubmitted>
let $headertitle := <header-title>{(fn:doc($headeruri/string())//*:title/text())[1]}</header-title>
let $ctype := <content-type>{$ctype}</content-type>
let $username := <user>{distinct-values(db:open($config:CoreDatabase,$config:UserDir)/user[id=$requester-id][fn:not(fn:matches(fn:base-uri(.),'(/version/|/audit/)'))]/name/string())}</user>
return <lock>{$headeruri,<title>{$headertitle/string()}</title>,$checkedOutOn,$cid,$coid,$ctype,$headertitle,$username,$jobSubmitted}</lock>
}</locks>
let $countRecord := fn:count($lockRecords/lock)
return
if($lockRecords/lock)
then
(
(:<result><status>Success</status><total>{$countRecord}</total><entities>{$lockRecords/lock[fn:position() = $start to $end]}</entities></result>,:)
<result><status>Success</status><total>{$countRecord}</total><entities>{$lockRecords/lock}</entities></result>,
config:non-update-message("[Lock List][Lock list has been sent successfully]")
)
else
(
<result><status>Success</status><message>Lock information is unavailable</message></result>,
config:non-update-message("[Lock List][Lock list is not available]")
)
}
catch *
{
admin:write-log("[Lock List][Error: " || $err:description || "]"),
admin:write-log("[Lock List][Error: " || $err:additional || "]"),
<result><status>Error</status><message>Error generated. Please check system log</message></result>
}
};
declare
%rest:path("/locks-compononent")
%rest:GET
%rest:query-param("cid", "{$cid}","")
%rest:query-param("query", "{$query}","")
%rest:query-param("user", "{$userid}")
%rest:query-param("allrecords", "{$allrecords}","")
%rest:query-param("page", "{$page}")
%rest:query-param("size", "{$size}")
%rest:header-param("Authorization", "{$authorization}", "none")
function locks:list-compononent(
$cid as xs:string,
$userid as xs:string,
$query as xs:string?,
$allrecords as xs:string,
$page as xs:integer?,
$size as xs:integer?,
$authorization as xs:string
)
{
config:session-check($authorization),
try
{
let $lockRecords := <locks>{
for $eachLock in db:open($config:CoreDatabase,$config:LockDir)/locks/lock[if($userid and $allrecords='true') then (db:open('bloomsbury','/user/')/user[role='admin'][id=$userid]) else requester-id=$userid]
[if($query!='') then fn:matches(name,$query,'i') else .]
for $eachFile in $eachLock/files/file[fn:contains(uri,$cid)]
let $uri := $eachFile/uri
let $requester-id := $eachLock/requester-id/string()
let $version := $eachFile/version
let $title := $eachFile/title
let $cid := <cid>{fn:substring-before(fn:substring-before(fn:substring-after($uri,$config:ContentDir),$config:ContentDir),'/')}</cid>
let $coid := <coid>{fn:substring-after(fn:substring-before(fn:substring-after($uri,$config:ContentDir),$config:ContentDir),'/')}</coid>
(:let $ctype := $eachFile/ctype/string():)
let $ctype := if($eachFile/ctype) then $eachFile/ctype/string() else 'looseleaf'
let $username := <user>{distinct-values(db:open($config:CoreDatabase,$config:UserDir)/user[id=$requester-id][fn:not(fn:matches(fn:base-uri(.),'(/version/|/audit/)'))]/name/string())}</user>
let $delete := <deleted>{
if(fn:doc( fn:concat(blcommon:get-db-name($ctype),$config:ContentDir,fn:data($cid),'/',fn:data($coid),'/',$config:InfoXml) )/info[delete='yes'] )
then 'true' else 'false'
}</deleted>
let $checkedOutOn := $eachLock/checked-out-on
let $headeruri := fn:uri-collection(fn:concat(blcommon:get-db-name($ctype),$config:ContentDir))[fn:contains(.,'/content/latest')]
[contains(.,$config:HeaderXml)]
[fn:tokenize(.,'/')[4]=$cid]
[fn:not(fn:contains(.,$config:VersionDir))]
let $headertitle := <header-title>{(fn:doc($headeruri)//*:title/text())[1]}</header-title>
let $ctype := <content-type>{$ctype}</content-type>
let $job := db:open($config:CoreDatabase,$config:JobDir)/job[job-info/job-type='Checkin'][job-info/lock/file/uri=$uri]
[ingestion-report/status='InQueue' or ingestion-report/status='InProgress']
let $jobSubmitted := <JobSubmitted>{if($job) then 'Yes' else 'No'}</JobSubmitted>
return <lock>{$uri,$headertitle,$version,$title,$checkedOutOn,$cid,$coid,$ctype,$username,$jobSubmitted}</lock>
}</locks>
let $countRecord := fn:count($lockRecords/lock)
return
if($lockRecords/lock)
then
(
(:<result><status>Success</status><total>{$countRecord}</total><entities>{$lockRecords/lock[fn:position() = $start to $end]}</entities></result>,:)
<result><status>Success</status><total>{$countRecord}</total><entities>{$lockRecords/lock}</entities></result>,
config:non-update-message("[Lock List][Lock list has been sent successfully]")
)
else
(
<result><status>Success</status><message>Lock information is unavailable</message></result>,
config:non-update-message("[Lock List][Lock list is not available]")
)
}
catch *
{
admin:write-log("[Lock List][Error: " || $err:description || "]"),
admin:write-log("[Lock List][Error: " || $err:additional || "]"),
<result><status>Error</status><message>Error generated. Please check system log</message></result>
}
};