xquery version "3.0"; (: $Id$ :) (: Module: display status information on the current database instance. :) module namespace metadata = "http://exist-db.org/xquery/rebind/edit-metadata"; declare namespace abcd = "http://www.tdwg.org/schemas/abcd/2.06"; declare namespace xdb="http://exist-db.org/xquery/xmldb"; declare function metadata:header() as element()* { let $fileName := request:get-parameter("name", "") let $collection := request:get-parameter("collection", "") (:let $fileNameInDB := concat("/db/test/xform/",$fileName):) let $fileNameInDB := concat($collection, "/metadata.xml") let $copiedEmpty := if(not(exists(doc($fileNameInDB)))) then (metadata:create-metadata($collection)) else (false())(:/db/test/xform":) (:let $up := update replace doc($fileNameInDB)//temporalCoverage/rangeOfDates/beginDate/calendarDate with 2014-08-30:) (:update insert todays date into the first empty date template the date cannot be empty for the form to validate before saving :) (:let $up := update insert 2014-09-302014-09-30 into doc($fileNameInDB)//coverage :) (:let $up := if(not(exists(doc($fileNameInDB//coverage/temporalCoverage[2])))) then ( update insert 2014-09-302014-09-30 into doc($fileNameInDB)//coverage ) else () :) let $oldDate := for $date in collection($collection)//coverage/temporalCoverage/rangeOfDates/beginDate/calendarDate return $date let $currentDate := substring-before(xs:string(current-date()), '+') (:let $up := if(count(collection($collection//coverage/temporalCoverage) < 2)) then ( update insert 2014-09-302014-09-30 into doc($fileNameInDB)//coverage ) else () :) (: Need to insert a date into the XML file otherwise the form does not open with an empty string - xs:date cannot be blank:) let $up := if($oldDate) then ( ) else (update insert {$currentDate}{$currentDate} into doc($fileNameInDB)//coverage ) (: if it doesn't exist copy the empty template metadata.xml into the collection :) (:let $copy := xmldb:copy("/db/test/xform", $collection, "metadata.xml"):) (:let $metadataTemplate := "/exist/rest/db/test/xform/template.xml" :) (:let $attribute := request:set-attribute("betterform.filter.ignoreResponseBody", "true"):) let $attribute := request:set-attribute("betterform.debug-allowed", "true") (::) return KingdomPhylumClassOrderFamilyGenusSpecies 5
Failed to save data. Check form for invalid values highlighted in red. Remove or edit these values. You have submitted the data successfully.
}; (: Create a new metadata file from the metadata template and transfer any data already existing in the abcd data file into it :) declare function metadata:create-metadata($collection as xs:string) as item()* { let $result := xmldb:copy("/db/rebind/template", $collection, "metadata.xml") let $document := doc(concat($collection,"/metadata.xml")) (:let $data-collection := '/db/rebind/protected/Dinter':) (:let $up := update replace $document//contact/individualName/surName/text() with 'HELLO0000000000000':) (:let $up := update replace $document//creator/individualName/surName with {collection($data-collection)//abcd:ContentContact/abcd:Name/text()}:) let $up := update replace $document//creator/individualName/surName with {collection($collection)//abcd:ContentContact/abcd:Name/text()} let $up3 := update replace $document//creator/organizationName with {collection($collection)//abcd:Organisation/abcd:Name//abcd:Representation/abcd:Text/text()} let $up4 := update replace $document//dataset/title with {collection($collection)//abcd:Metadata/abcd:Description/abcd:Representation/abcd:Title/text()} let $up5 := update replace $document//dataset/abstract/para with {collection($collection)//abcd:Metadata/abcd:Description/abcd:Representation/abcd:Details/text()} let $up6 := update replace $document//geographicDescription with {collection($collection)//abcd:Metadata/abcd:Scope/abcd:GeoecologicalTerms/abcd:GeoEcologicalTerm/text()} (: If there isn't already a geographicDescription then get it from abcd:Representation/abcd:Coverage :) let $up6b := update replace $document//geographicDescription[string-length(.) < 1] with {collection($collection)//abcd:Metadata/abcd:Description/abcd:Representation/abcd:Coverage/text()} let $up7 := update replace $document//creator/electronicMailAddress with {collection($collection)//abcd:ContentContact/abcd:Email/text()} let $up8 := update replace $document//intellectualRights/para with {collection($collection)//abcd:IPRStatements/*/*/abcd:Text/text()} (: check some of the other metadata files and agnes's mapping doc to see if there are any fields to transfer from abcd :) return $result }; declare function metadata:create-metadata-old($collection as xs:string) as item()* { xmldb:copy("/db/rebind/template", $collection, "metadata.xml") }; (: Save metadata file. :) declare function metadata:save-metadata($colName as xs:string) as element() { let $data := request:get-data() let $file-name := rebind:getSetting('metadata-file') (: check to make sure we have valid post data :) return if (not($data)) then No Post Data else (

Actions:

) }; declare function metadata:main() as element() {

Dataset Metadata Editor

Project: {substring-after(request:get-parameter("collection", ""), '/db/rebind/protected/')}

Description The description should distinguish your data from other data and provide an abstract to describe key features, study design or methods used in the study. Keywords Keywords enable better searching and categorisation of the data. Keywords can be added in sets to multiple thesauri. Owner/Contact The primary person and/or organisation to contact with questions regarding the use and interpretation of the data. Usage Rights Geographic Coverage Temporal Coverage Taxonomic Coverage Methods

Dataset Description

Enter a title long enough to distinguish your data from other data Title:
Enter an abstract to describe key features, study design or methods used in the study. Abstract:

Keywords

edit
Enter a thesaurus name to describe the list of keywords. Thesaurus:

Keyword: remove add keyword

add keyword set save keyword set remove keyword set cancel

Contact

Salutation: Given name: Surname: You must provide at least one contact. Organisation name: Email address:

Usage Rights

Geographic Coverage

Geographic Description:

North Enter coordinates in decimal
West Enter coordinates in decimal East Enter coordinates in decimal
South Enter coordinates in decimal

Temporal Coverage

Date Start Date format DD-MM-YYYY Date End Date format DD-MM-YYYY 'Date End' should be after 'Date Start' remove Deletes the begin and end dates for this temporal coverage.
add Adds a new temporal coverage section with begin and end dates.

Taxonomic Coverage

Rank Name Common Name
Add Taxon Rank Name Common name

Methods

Title: Description: Instrumentation: edit
Please enter the title Title:
Description:
Instrumentation:

add method add method remove method cancel

If you’ve added or modified taxonomic coverage, keywords or methods please make sure you click ‘Add Taxon’, ‘Add keyword set’, and ‘Add method’ in each individual form before saving and exiting. Save and exit Exit without saving
};