PageRenderTime 17ms CodeModel.GetById 11ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/xquery/create-event.xql

http://transcriptstudio4isha.googlecode.com/
Unknown | 29 lines | 26 code | 3 blank | 0 comment | 0 complexity | ce5a209a3f1bc0d22fd6aedd5b80683d MD5 | raw file
 1xquery version "1.0";
 2
 3import module namespace id-utils = "http://www.ishafoundation.org/ts4isha/xquery/id-utils" at "id-utils.xqm";
 4import module namespace utils = "http://www.ishafoundation.org/ts4isha/xquery/utils" at "utils.xqm";
 5
 6declare option exist:serialize "media-type=application/xml";
 7
 8let $eventType := request:get-parameter('type', ())
 9let $metadataXMLStr := request:get-parameter('metadataXML', ())
10return
11	if (empty($eventType) or $eventType eq '') then
12		error(xs:QName('missing-argument-exception'), 'No type specified')
13	else if (empty($metadataXMLStr)) then
14		error(xs:QName('missing-argument-exception'), 'No metadataXML specified')
15	else if (empty(utils:get-event-type($eventType))) then
16		error(xs:QName('illegal-argument-exception'), concat('Unknown type: ', $eventType))
17	else 
18		let $collectionPath := concat($utils:dataCollectionPath, '/', $eventType)
19		return
20			if (not(xmldb:collection-exists($collectionPath))) then
21				error(xs:QName('illegal-state-exception'), concat('Could not find event type collection: ', $collectionPath))
22			else
23				let $metadataXML := (util:parse($metadataXMLStr), <metadata/>)[1]
24				let $newId := id-utils:generate-event-id($eventType)
25				let $eventXML := <event id="{$newId}" type="{$eventType}">{$metadataXML}</event>
26				let $documentURI :=	utils:build-event-path($eventXML)
27				let $null := utils:store($documentURI, $eventXML)
28				return
29					$eventXML