99 lines
3.8 KiB
Plaintext
99 lines
3.8 KiB
Plaintext
(:~
|
|
: Library to control audit.
|
|
:
|
|
: @author Rave Technologies, https://www.rave-tech.com/, 2017
|
|
:)
|
|
|
|
module namespace apsrv = 'http://www.rave-tech.com/bloomsbury/audit-psrv';
|
|
import module namespace cpsrv = 'http://www.rave-tech.com/bloomsbury/config-psrv' at 'config-psrv.xqm';
|
|
|
|
(:~
|
|
: Add/append audit information whenever content ingest into the system`.
|
|
: @param $auditUri Location of the audit file to update
|
|
: @param $sessionValue Session Value
|
|
: @param $jobID Job ID
|
|
: @return empty sequence
|
|
:)
|
|
declare %updating function apsrv:content-ingest(
|
|
$auditUri as xs:string,
|
|
$sessionValue as xs:string,
|
|
$jobID as xs:string
|
|
)
|
|
{
|
|
let $auditUri := fn:concat($cpsrv:TempPipelineDir,$jobID,$cpsrv:ReadyToMove,$auditUri)
|
|
let $AuditChunk := <audit>
|
|
<id>{random:uuid()}</id>
|
|
<requester-id>{fn:substring-before($sessionValue,'$$$$')}</requester-id>
|
|
<requester-email>{fn:substring-after($sessionValue,'$$$$')}</requester-email>
|
|
<type>Ingestion</type>
|
|
<version>1</version>
|
|
<date-time>{fn:adjust-dateTime-to-timezone(convert:integer-to-dateTime(prof:current-ms()))}</date-time>
|
|
</audit>
|
|
let $IsAudit := if(file:exists($auditUri)) then fn:true() else fn:false()
|
|
return
|
|
if($IsAudit)
|
|
then
|
|
(
|
|
insert node $AuditChunk into fn:doc($auditUri)/audits,
|
|
cpsrv:update-message("[Content Ingest][Audit record has been updated " || $auditUri || "]")
|
|
)
|
|
else
|
|
(
|
|
file:create-dir(fn:substring-before($auditUri,fn:tokenize($auditUri,'/')[fn:last()]))
|
|
,
|
|
file:write($auditUri,<audits>{$AuditChunk}</audits>)
|
|
,
|
|
cpsrv:update-message("[Content Ingest][Audit record has been created " || $auditUri || "]")
|
|
)
|
|
};
|
|
|
|
|
|
|
|
(:~
|
|
: Add/append audit information whenever user will perform some action on content
|
|
: @param $contentUri URI of the content to download
|
|
: @param $sessionValue Session Value
|
|
: @param $action Audit action (download,checkout,undo checkout,delete)
|
|
: @param $jobID Job ID
|
|
: @return empty sequence
|
|
:)
|
|
declare %updating function apsrv:update(
|
|
$contentUri as xs:string,
|
|
$sessionValue as xs:string,
|
|
$action as xs:string,
|
|
$jobID as xs:string
|
|
)
|
|
{
|
|
let $cid := fn:substring-before(fn:substring-before(fn:substring-after($contentUri,$cpsrv:ContentDir),$cpsrv:ContentDir),'/')
|
|
let $coid := fn:substring-after(fn:substring-before(fn:substring-after($contentUri,$cpsrv:ContentDir),$cpsrv:ContentDir),'/')
|
|
let $auditUri := fn:concat('concurrency',$cpsrv:ContentDir,$cid,'/',$coid,'/',$cpsrv:AuditFileName)
|
|
let $tempUri := fn:concat($cpsrv:TempPipelineDir,$jobID,$cpsrv:ReadyToMove,fn:substring-before($auditUri,fn:tokenize($auditUri,'/')[fn:last()]))
|
|
let $version := let $versionUri := fn:replace($auditUri,$cpsrv:AuditFileName,$cpsrv:VersionControlFileName)
|
|
return
|
|
if(fn:doc-available($versionUri))
|
|
then
|
|
let $versionXml := fn:doc($versionUri)
|
|
let $version := $versionXml/versions/version[fn:contains(@uri,fn:tokenize($contentUri,'/')[fn:last()])]/@number/string()
|
|
return
|
|
if($version)
|
|
then $version
|
|
else fn:sum(fn:max($versionXml/versions/version/@number) + 1)
|
|
else 1
|
|
let $AuditChunk := <audit>
|
|
<id>{random:uuid()}</id>
|
|
<requester-id>{fn:substring-before($sessionValue,'$$$$')}</requester-id>
|
|
<requester-email>{fn:substring-after($sessionValue,'$$$$')}</requester-email>
|
|
<type>{$action}</type>
|
|
<version>{$version}</version>
|
|
<date-time>{fn:adjust-dateTime-to-timezone(convert:integer-to-dateTime(prof:current-ms()))}</date-time>
|
|
</audit>
|
|
return
|
|
(
|
|
file:create-dir($tempUri)
|
|
,
|
|
file:write(fn:concat($tempUri,$cpsrv:AuditFileName),$AuditChunk)
|
|
,
|
|
cpsrv:update-message("[Audit Record][Audit record has been created " || $tempUri || "]")
|
|
)
|
|
};
|