[init] 13 dec 2021

This commit is contained in:
Andy Bunce 2021-12-13 10:54:35 +00:00
commit 7548f1e1c0
7 changed files with 2933 additions and 0 deletions

11
.project Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>psrv</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>

98
audit-psrv.xqm Normal file
View File

@ -0,0 +1,98 @@
(:~
: 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 || "]")
)
};

130
config-psrv.xqm Normal file
View File

@ -0,0 +1,130 @@
(:~
: Global constants and functions.
:
: @author Rave Technologies, https://www.rave-tech.com/, 2017
:)
module namespace cpsrv = 'http://www.rave-tech.com/bloomsbury/config-psrv';
import module namespace Session = 'http://basex.org/modules/session';
(:~ Processing Server. :)
declare variable $cpsrv:DataServer as xs:string := 'http://172.20.2.16:8984/rest/';
declare variable $cpsrv:User as xs:string := 'admin';
declare variable $cpsrv:Password as xs:string := 'admin';
declare variable $cpsrv:ReadyToMove as xs:string := '/ReadyToMove/';
(:~ Main Database. :)
declare variable $cpsrv:Database as xs:string := 'bloomsbury';
(:~ Debug on/off. :)
declare variable $cpsrv:Debug as xs:boolean := fn:true();
(:~ Main Directories of the application. :)
(:~ User Directory. :)
declare variable $cpsrv:UserDir as xs:string := '/user/';
(:~ Taxonomy Directory. :)
declare variable $cpsrv:TaxonomyDir as xs:string := '/taxonomies/';
(:~ Configuration Directory. :)
declare variable $cpsrv:ConfigDir as xs:string := '/config/';
(:~ Pipeline Directory. :)
declare variable $cpsrv:PipelineDir as xs:string := '/pipelines/';
(:~ Transformation Directory. :)
declare variable $cpsrv:TransformDir as xs:string := '/transforms/';
(:~ Validation Directory. :)
declare variable $cpsrv:ValidationDir as xs:string := '/validation/';
(:~ Product Directory. :)
declare variable $cpsrv:ProductDir as xs:string := '/products/';
(:~ Content Directory. :)
declare variable $cpsrv:ContentDir as xs:string := '/content/';
(:~ Latest Directory to keep latest version. :)
declare variable $cpsrv:LatestDir as xs:string := '/latest/';
(:~ Jobs Directory. :)
declare variable $cpsrv:JobDir as xs:string := '/jobs/';
(:~ docx Directory. :)
declare variable $cpsrv:WordDir as xs:string := '/word/';
(:~ Version Directory to keep old version. :)
declare variable $cpsrv:VersionDir as xs:string := '/version/';
(:~ metadata Directory to keep content metadata xml. :)
declare variable $cpsrv:Metadata as xs:string := '/metadata/';
(:~ Audit Directory. :)
declare variable $cpsrv:AuditDir as xs:string := 'audit/';
(:~ Report Directory. :)
declare variable $cpsrv:ReportDir as xs:string := '/reports/';
(:~ To keep lock information. :)
declare variable $cpsrv:LockDir as xs:string := '/locks/';
(:~ Temp Directory. :)
declare variable $cpsrv:TempDir as xs:string := '\\172.20.2.16\bloomsbury-CMS\bl-workspace\';
(:~ Pipeline output directory for temp :)
declare variable $cpsrv:TempPipelineDir as xs:string := fn:concat($cpsrv:TempDir,'pipeline_output/');
declare variable $cpsrv:SchemaDir as xs:string := 'file:///D:/schemas/';
declare variable $cpsrv:XsdDir as xs:string := '\\172.20.2.16\schemas\';
declare variable $cpsrv:XprocTempResultDir as xs:string := 'file:///D:/bloomsbury-CMS/';
declare variable $cpsrv:SchemaxplLocation := "file:///D:/xproc/calabash/extensions/transpect/rng-extension/xpl/rng-validate.xpl";
(:~ Global prefixes :)
(:~ Job ID prefix. :)
declare variable $cpsrv:JobIDPrefix as xs:string := "SCH";
(:~ Global file name :)
(:~ Common file name to keep audit information :)
declare variable $cpsrv:AuditFileName as xs:string := 'audit.xml';
(:~ Common file name to keep version control :)
declare variable $cpsrv:VersionControlFileName as xs:string := 'version.xml';
(:~ DOC XML Path :)
declare variable $cpsrv:DocXml as xs:string := "word/document.xml";
(:~ Looseleaf header file :)
declare variable $cpsrv:HeaderXml as xs:string := "header.xml";
(:~ To keep extra information of the documents: like Area/Content Type :)
declare variable $cpsrv:InfoXml as xs:string := 'properties.xml';
(:~ To keep content metadata information :)
declare variable $cpsrv:MetaXml as xs:string := 'metadata.xml';
(:~ To keep content classify information :)
declare variable $cpsrv:ClassifyXml as xs:string := 'classify.xml';
(:~ Configurable XML files location :)
declare variable $cpsrv:PipelineConfig as xs:string := fn:concat($cpsrv:ConfigDir,'ingest-pipeline-config.xml');
(:~ Pipeline Configuration file path :)
declare variable $cpsrv:DownloadConfig as xs:string := fn:concat($cpsrv:ConfigDir,'content-download.xml');
(:~ Global path to support XProc, Temp, and Published folder directory :)
(:~ XProc: The path where calabash.bat file exist :)
declare variable $cpsrv:CalabashBatch as xs:string := '\\172.20.2.16\SharedData\xproc\calabash\calabash.bat';
(:~ Output Directory to store downloaded content. :)
declare variable $cpsrv:OutDir as xs:string := 'C:\Program Files (x86)\BaseX\output\download\';
(:~ Output Directory to store published content. :)
declare variable $cpsrv:PublishDir as xs:string := 'C:\Program Files (x86)\BaseX\output\publish\';
declare variable $cpsrv:bloomsburydbk as xs:string := '\transpact-dbk-to-bloomsbury-dbk\';
(:~
: Display debug message in serer log
: @param message The message to print in log file
: @return empty sequence
:)
declare %updating function cpsrv:update-message(
$message as xs:string
)
{
if($cpsrv:Debug)
then admin:write-log($message)
else ()
};
(:~
: Display debug message in serer log
: @param message The message to print in log file
: @return empty sequence
:)
declare function cpsrv:non-update-message(
$message as xs:string
)
{
if($cpsrv:Debug)
then admin:write-log($message)
else ()
};

2263
content-psrv.xqm Normal file

File diff suppressed because it is too large Load Diff

306
jobs-psrv.xqm Normal file
View File

@ -0,0 +1,306 @@
(:~
: Job Library.
:
: @author Rave Technologies, https://www.rave-tech.com/, 2017
:)
module namespace jpsrv = 'http://www.rave-tech.com/bloomsbury/jobs-psrv';
import module namespace cpsrv = 'http://www.rave-tech.com/bloomsbury/config-psrv' at 'config-psrv.xqm';
import module namespace copsrv = 'http://www.rave-tech.com/bloomsbury/contents-psrv' at 'content-psrv.xqm';
import module namespace apsrv = 'http://www.rave-tech.com/bloomsbury/audit-psrv' at 'audit-psrv.xqm';
import module namespace rpsrv = 'http://www.rave-tech.com/bloomsbury/report-psrv' at 'report-psrv.xqm';
declare namespace product = 'http://cms.bloomsbury.com/product-manifest';
declare namespace pipeline = 'http://cms.bloomsbury.com/pipeline';
(:~
: Run Jobs
: @param $body <job><ingest><area>Professional</area><ctype>looseleaf</ctype><ignore-validation>true</ignore-validation><mail>true</mail><path>D:\Backup\Projects\bloomsbury\SharedData\Steve\word2xml\small66.zip</path></ingest></job>
: @return empty sequence
:)
declare %updating function jpsrv:run-job(
$body as document-node()
)
{
admin:write-log('=============process starts================')
,
if($body/job/job-info/id)
then
let $jobLocation := fn:concat($cpsrv:TempPipelineDir,'/',$body/job/job-info/id)
let $jobType := $body/job/job-info/job-type/text()
return
if(($jobType='Ingest') or ($jobType='Checkin') or ($jobType='Publish'))
then
if((file:exists($jobLocation)) and ($jobType='Ingest'))
then ()
else jpsrv:jobs($body)
else ()
else admin:write-log('=============Invalid Job ID================')
};
(:~
: To ingest a content
: @param $body Job Chunk
: @header $authorization Authorization key
: @return element(result)
:)
declare %updating function jpsrv:jobs(
$body as document-node()
)
{
try
{ (:let $DataServer := 'http://10.102.200.111:8984/rest/':)
let $DataServer := 'http://172.20.2.16:8984/rest/'
let $area := $body/job/job-info/area/text()
let $ctype := $body/job/job-info/content-type/text()
let $ignoreValidation := $body/job/job-info/ignore-validation/text()
let $sendMail := $body/job/job-info/mail-required/text()
let $contentPath := fn:replace($body/job/job-info/uploaded-file/text(),'\\','/')
let $sessionValue := fn:concat($body/job/job-info/requester-id/text(),'$$$$',$body/job/job-info/requester-email/text())
let $UploadFileName := fn:tokenize($contentPath,'\\')[fn:last()]
let $jobID := $body/job/job-info/id/text()
let $cid := $body/job/job-info/cid/text()
let $createJobLocation := file:create-dir(fn:concat($cpsrv:TempPipelineDir,$jobID,$cpsrv:ReadyToMove))
let $cformat := $body/job/job-info/content-format/text()
let $pid := $body/job/job-info/pipeline-id/text()
let $jobType := $body/job/job-info/job-type/text()
let $lockInfo := if($body/job/job-info/lock)
then $body/job/job-info/lock
else <lock/>
return
if(($jobType='Ingest') or ($jobType='Checkin'))
then
if($cid)
then
(
let $reportPath := fn:concat($cpsrv:TempPipelineDir,$jobID,$cpsrv:ReadyToMove,$cpsrv:JobDir)
let $createDir := file:create-dir($reportPath)
return file:write(fn:concat($reportPath,$jobID,'.xml'),$body)
,
if($cformat='zip')
then copsrv:upload-zip($cid,$pid,$contentPath,$jobID,$ctype,$ignoreValidation,$area,$sessionValue,'zip',$jobType,$lockInfo)
else
if($cformat='xml')
then copsrv:upload-xml($cid,$pid,$contentPath,$jobID,$ctype,$ignoreValidation,$area,$sessionValue,'xml',$jobType)
else
if($cformat='docx')
then copsrv:upload-docx($cid,$pid,$contentPath,$jobID,$ctype,$ignoreValidation,$area,$sessionValue,'docx',$jobType)
else ()
)
else admin:write-log('************************ System error ************************')
else
if($jobType='Publish')
then
(
let $reportPath := fn:concat($cpsrv:TempPipelineDir,$jobID,$cpsrv:ReadyToMove,$cpsrv:JobDir)
let $createDir := file:create-dir($reportPath)
return file:write(fn:concat($reportPath,$jobID,'.xml'),$body)
,
let $jobTempDir := fn:concat($cpsrv:TempPipelineDir,$jobID)
let $productID := $body/job/job-info/product-id/text()
let $httpTarget := fn:concat($cpsrv:DataServer,$cpsrv:Database,$cpsrv:ProductDir,$productID,$cpsrv:LatestDir,$productID,'.xml')
let $appliedProduct := (http:send-request(
<http:request method='get' username='{$cpsrv:User}' password='{$cpsrv:Password}' send-authorization='true'
href='{$httpTarget}' auth-method='Basic'>
</http:request>
))[2]
let $pipelineID := $body/job/job-info/pipeline-id/text()
let $RootpipelineID := $appliedProduct/product:product/@pipelineRef/string()
let $ProductName := $appliedProduct/product:product/@name/string()
let $PipelinehttpTarget := fn:concat($DataServer,'bloomsbury','/pipelines/',$pipelineID,'.xml')
let $PipelineXml := (http:send-request(
<http:request method='get' username='admin@bloomsbury.com' password='admin' send-authorization='true'
href='{$PipelinehttpTarget}' auth-method='Basic'>
</http:request>
))[2]
let $steps := for $eachStep in $PipelineXml/*:pipeline/child::*/local-name()
return $eachStep
let $normalizedsteps := string-join($steps,'|')
return
if(fn:contains($normalizedsteps,'xquery'))
then
let $PublishedContent := for $XqueryStep at $pos in $PipelineXml/*:pipeline/*:xquery
let $ProductContent := $appliedProduct/*:product/*:contents/*:content
(: let $BaseUriToken := fn:concat(fn:string-join(fn:tokenize($XqueryStep,'\\')[position()=1 to fn:last()-1],'\'),'\'):)
let $BaseUriToken := $XqueryStep/@xml:base/string()
let $XQueryUri := ($BaseUriToken||$XqueryStep/@href/string())
let $XqueryInputLocation := if($pos = 1) then ($jobID||'/step-'||$pos) else ($jobID||'/step-'||$pos)
return
(
xquery:eval(
'declare base-uri "' || $BaseUriToken || '";'||
file:read-text($XQueryUri),
map
{
'{http://cms.bloomsbury.com/export}JOB_ID':$XqueryInputLocation,
'{http://cms.bloomsbury.com/export}product':$ProductName,
'{http://cms.bloomsbury.com/export}PUBLISH_JOB_BASE':$cpsrv:TempPipelineDir
}
)
,
let $tempFilePath := if($pos = 1) then fn:concat($cpsrv:TempPipelineDir,$jobID,'\step-',$pos,'\output\')
else fn:concat($cpsrv:TempPipelineDir,$jobID,'\step-',$pos,'\input\')
let $productName := $body/job/job-info/product-name/text()
let $ProductUri := file:children($cpsrv:TempPipelineDir||$jobID||'\step-1'||'\manifest\')
let $product := fn:doc($ProductUri)
let $ctype := $product/*:content/@sourceContentType/string()
let $httpTarget := fn:concat($cpsrv:DataServer,$cpsrv:Database,$cpsrv:PipelineDir,$pipelineID,'.xml')
let $appliedPipeline := (http:send-request(
<http:request method='get' username='{$cpsrv:User}' password='{$cpsrv:Password}' send-authorization='true'
href='{$httpTarget}' auth-method='Basic'>
</http:request>
))[2]
for $PublishedContentUri in file:list($cpsrv:TempPipelineDir||$jobID||'\step-'||$pos||'\output\',true())[fn:contains(.,'.xml')]
let $PublishedContentId := substring-before(fn:tokenize($PublishedContentUri,'\\')[fn:last()],'_')
return
(
copsrv:run-pipeline($jobID,$PublishedContentId,$tempFilePath,$ignoreValidation,$sessionValue,$pipelineID,$ctype,$productID,(),$tempFilePath,$appliedPipeline/pipeline:pipeline,$jobType)
,
(
if(
file:is-dir($cpsrv:TempPipelineDir||$jobID||'/step-'||$pos+1||'/input')
)
then jpsrv:CopyFilesFromInputDirToInputDir($cpsrv:TempPipelineDir,$jobID,$pos)
else()
)
)
)
return
(
copsrv:move-to-db(
<job>
<job-id>{$jobID}</job-id>
<content-type>{$ctype}</content-type>
<pipelineid>{$pipelineID}</pipelineid>
<cid></cid>
<temp-location>{fn:concat($cpsrv:TempPipelineDir,$jobID)}</temp-location>
<ignore-validation>{$ignoreValidation}</ignore-validation>
<session-value>{$sessionValue}</session-value>
<input-type>{$body/job/job-info/product-name/text()}</input-type>
<job-type>{$jobType}</job-type>
</job>
)
)
else
let $PublishedContent := for $item in $appliedProduct/product:product/product:contents/product:content[@pipelineRef/string()=$pipelineID]/product:item
let $ctype := $item/parent::product:content/@sourceContentType/string()
let $httpTarget := fn:concat($cpsrv:DataServer,$cpsrv:Database,$cpsrv:PipelineDir,$pipelineID,'.xml')
let $appliedPipeline := (http:send-request(
<http:request method='get' username='{$cpsrv:User}' password='{$cpsrv:Password}' send-authorization='true'
href='{$httpTarget}' auth-method='Basic'>
</http:request>
))[2]
let $cid := $item/@id/string()
let $tempFilePath := fn:concat($cpsrv:TempPipelineDir,$jobID,'/','content/',$ctype,'/',$cid)
return
copsrv:run-pipeline($jobID,$cid,$tempFilePath,$ignoreValidation,$sessionValue,$pipelineID,$ctype,$productID,(),$tempFilePath,$appliedPipeline/pipeline:pipeline,$jobType)
return
(
$PublishedContent,
copsrv:move-to-db(
<job>
<job-id>{$jobID}</job-id>
<content-type>{$ctype}</content-type>
<pipelineid>{$pipelineID}</pipelineid>
<cid></cid>
<temp-location>{fn:concat($cpsrv:TempPipelineDir,$jobID)}</temp-location>
<ignore-validation>{$ignoreValidation}</ignore-validation>
<session-value>{$sessionValue}</session-value>
<input-type>{$body/job/job-info/product-name/text()}</input-type>
<job-type>{$jobType}</job-type>
</job>
)
)
)
else ()
}
catch *
{
let $stepChunk := <step>
<type>Job Process Error</type>
<error>
<code>{$err:code}</code>
<description>{$err:description}</description>
<additional>{$err:additional}</additional>
</error>
</step>
return
(
rpsrv:update($body/job/job-info/id/text(),$stepChunk),
copsrv:move-to-db(
<job>
<job-id>{$body/job/job-info/id/text()}</job-id>
<content-type>{$body/job/job-info/content-type/text()}</content-type>
<temp-location>{fn:concat($cpsrv:TempPipelineDir,$body/job/job-info/id/text())}</temp-location>
<ignore-validation>{$body/job/job-info/ignore-validation/text()}</ignore-validation>
<session-value>{ fn:concat($body/job/job-info/requester-id/text(),'$$$$',$body/job/job-info/requester-email/text())}</session-value>
<input-type>{$body/job/job-info/product-name/text()}</input-type>
<job-type>{$body/job/job-info/job-type/text()}</job-type>
<failure>yes</failure>
</job>
),
admin:write-log("[Process Job][Error: " || $err:description || "]"),
admin:write-log("[Process Job][Error: " || $err:additional || "]"),
fn:error(xs:QName('jpsrv:error'), $err:additional)
)
}
};
declare %updating function jpsrv:CopyFilesFromInputDirToInputDir(
$PublishBaseDir as xs:string,
$JobId as xs:string,
$pos as xs:integer
)
{
let $Outputdir := ($PublishBaseDir||$JobId||'/step-'||$pos||'\output\')
for $files in file:list($Outputdir,true())[fn:ends-with(.,'xml')]
let $Filename := fn:tokenize($files,'\\')[fn:last()]
let $DocUri := ($PublishBaseDir||$JobId||'\step-'||$pos||'\output\'||$files)
let $TargetUri := ($PublishBaseDir||$JobId||'\step-'||$pos+1||'\input\'||$Filename)
return
file:write($TargetUri,fn:doc($DocUri))
};
declare %updating function jpsrv:Delete-Files(
$PublishBaseDir as xs:string,
$JobId as xs:string
)
{
let $ContentDir := ($PublishBaseDir||$JobId||'\output\')
for $Files in file:list($ContentDir,fn:true())[fn:ends-with(.,'xml')]
let $DocUri := ($PublishBaseDir||$JobId||'\output\'||$Files)
return
file:delete($DocUri)
};
(: Job Scheduler :)
declare
%rest:path("/jpsrv/scheduler")
%rest:GET
function jpsrv:create-scheduler(
)
{
let $job := jobs:invoke('C:\Program Files (x86)\BaseX\webapp\eBloomsbury\psrv\sch-psrv.xqm',(),map {'interval':'PT30S'})
return admin:write-log('=========== scheduler registered ================')
};
(:~ Return error message to the UI if authentication fails :)
declare
%rest:error("jpsrv:error")
%rest:error-param("description", "{$message}")
function jpsrv:error($message)
{
admin:write-log($message)
};

91
report-psrv.xqm Normal file
View File

@ -0,0 +1,91 @@
(:~
: Report library.
:
: @author Rave Technologies, https://www.rave-tech.com/, 2017
:)
module namespace rpsrv = 'http://www.rave-tech.com/bloomsbury/report-psrv';
import module namespace cpsrv = 'http://www.rave-tech.com/bloomsbury/config-psrv' at 'config-psrv.xqm';
import module namespace copsrv = 'http://www.rave-tech.com/bloomsbury/contents-psrv' at 'content-psrv.xqm';
declare namespace pipeline = 'http://cms.bloomsbury.com/pipeline';
(:~
: Append error report to the specific job.
: @param $jobID ID of the job to update status
: @param $stepReport The step information to record
: @return empty sequence
:)
declare %updating function rpsrv:update(
$jobID as xs:string,
$stepReport as element(step)
)
{
file:append(fn:concat($cpsrv:TempPipelineDir,$jobID,$cpsrv:ReadyToMove,$cpsrv:JobDir,$jobID,'.xml'),$stepReport)
};
(:~
: Append final status of the report.
: @param $jobID ID of the job to update status
: @param $ignoreValidation Ignore validation if error happens
: @param $contentID ID of the content
: @return empty sequence
:)
declare %updating function rpsrv:update-final-status(
$jobID as xs:string,
$ignoreValidation as xs:string,
$contentID as xs:string
)
{
let $reportUri := fn:concat($cpsrv:TempPipelineDir,$jobID,$cpsrv:ReadyToMove,$cpsrv:JobDir,$jobID,'.xml')
let $file := file:read-text($reportUri)
let $steps := fn:substring-after($file,'</job>')
let $jobText := fn:parse-xml(fn:substring-before($file,$steps))
let $jobXml := copy $c := $jobText
modify replace node $c/job/ingestion-report/steps with fn:parse-xml(fn:concat('<steps>',fn:normalize-space($steps),'</steps>'))
return $c
return
if($jobXml/job/ingestion-report/status[.='InProgress'] or $jobXml/job/ingestion-report/status[.=''])
then
(
if($jobXml/job/ingestion-report/steps/step/error/*)
then
if($ignoreValidation='true')
then
let $jobXml := copy $c := $jobXml
modify
(
replace node $c/job/ingestion-report/status with <status>SuccessWithWarnings</status>,
replace node $c/job/ingestion-report/finished-on with <finished-on>{fn:adjust-dateTime-to-timezone(convert:integer-to-dateTime(prof:current-ms()))}</finished-on>
)
return $c
return file:write($reportUri,$jobXml)
else
(
let $jobXml := copy $c := $jobXml
modify
(
replace node $c/job/ingestion-report/status with <status>Failure</status>,
replace node $c/job/ingestion-report/finished-on with <finished-on>{fn:adjust-dateTime-to-timezone(convert:integer-to-dateTime(prof:current-ms()))}</finished-on>,
for $d in $c/job/job-info/lock/file
return
replace node $d/latest-version with <latest-version>{$d/previous-version/string()}</latest-version>
)
return $c
return file:write($reportUri,$jobXml)
,
file:delete(fn:concat($cpsrv:TempPipelineDir,$jobID,$cpsrv:ReadyToMove,$cpsrv:ContentDir),fn:true())
)
else
let $jobXml := copy $c := $jobXml
modify
(
replace node $c/job/ingestion-report/status with <status>Success</status>,
replace node $c/job/ingestion-report/finished-on with <finished-on>{fn:adjust-dateTime-to-timezone(convert:integer-to-dateTime(prof:current-ms()))}</finished-on>
)
return $c
return file:write($reportUri,$jobXml)
)
else ()
};

34
sch-psrv.xqm Normal file
View File

@ -0,0 +1,34 @@
(:~
: Execute jobs
:
: @author Rave Technologies, https://www.rave-tech.com/, 2017
:)
import module namespace cpsrv = 'http://www.rave-tech.com/bloomsbury/config-psrv' at 'config-psrv.xqm';
import module namespace jpsrv = 'http://www.rave-tech.com/bloomsbury/jobs-psrv' at 'jobs-psrv.xqm';
let $httpTarget := admin:write-log('--------job invoke --------')
let $httpTarget := fn:concat(fn:substring-before($cpsrv:DataServer,'/rest/'),'/data/jobs')
let $file := fn:string(convert:dateTime-to-integer(fn:adjust-dateTime-to-timezone(convert:integer-to-dateTime(prof:current-ms()))))
let $job := (http:send-request(<http:request method='get' username='admin' password='admin' send-authorization='true'
href='{$httpTarget}' auth-method='Basic'>
</http:request>)
)[2]
return
if($job/job[.='NONE'])
then admin:write-log('============= No job to process ==================')
else
(
let $jobID := $job/job/job-info/id/text()
let $httpTarget := fn:concat(fn:substring-before($cpsrv:DataServer,'/rest/'),'/data/job/update')
let $file := fn:string(convert:dateTime-to-integer(fn:adjust-dateTime-to-timezone(convert:integer-to-dateTime(prof:current-ms()))))
let $jobUpdate := (http:send-request(<http:request method='post' username='admin' password='admin' send-authorization='true'
href='{$httpTarget}' auth-method='Basic'>
<http:header name="Content-Type" value="application/xml"/>
<http:body media-type='application/xml'>
<job>{$jobID}</job>
</http:body>
</http:request>)
)
return jpsrv:run-job($job)
)