├── LICENSE.txt
├── README.markdown
├── config
├── endpoints.xqy
├── setup.xqy
└── site
│ ├── env.xqy
│ ├── index.xqy
│ ├── namespaces.xqy
│ ├── search.xqy
│ └── transformers.xqy
├── corona
├── facet.xqy
├── htools
│ ├── css
│ │ ├── ie.css
│ │ ├── print.css
│ │ └── screen.css
│ ├── img
│ │ ├── loader.gif
│ │ ├── ml_btn_bg_blue.png
│ │ ├── ml_btn_bg_blue_hover.png
│ │ ├── ml_btn_bg_disabled.png
│ │ ├── ml_icon-note.png
│ │ ├── ml_icons_note.png
│ │ ├── ml_icons_warning.png
│ │ ├── ml_logo.png
│ │ ├── ml_sep_line.png
│ │ ├── ml_sep_line_vert.png
│ │ └── ml_subnav_bullet.png
│ ├── js
│ │ ├── DataTables-1.8.2
│ │ │ ├── .gitignore
│ │ │ ├── css
│ │ │ │ └── demo_table_jui.css
│ │ │ ├── images
│ │ │ │ ├── back_disabled.jpg
│ │ │ │ ├── back_enabled.jpg
│ │ │ │ ├── forward_disabled.jpg
│ │ │ │ ├── forward_enabled.jpg
│ │ │ │ ├── sort_asc.png
│ │ │ │ ├── sort_asc_disabled.png
│ │ │ │ ├── sort_both.png
│ │ │ │ ├── sort_desc.png
│ │ │ │ └── sort_desc_disabled.png
│ │ │ └── js
│ │ │ │ ├── jquery.dataTables.editable.js
│ │ │ │ ├── jquery.dataTables.min.js
│ │ │ │ └── jquery.jeditable.js
│ │ ├── env.js
│ │ ├── namespaces.js
│ │ ├── search.js
│ │ ├── setup.js
│ │ └── transformers.js
│ └── template.xqy
├── kvquery.xqy
├── lib
│ ├── analyze-string.xqy
│ ├── common.xqy
│ ├── constants.xqy
│ ├── date-parser.xqy
│ ├── error-handler.xqy
│ ├── index-config.xqy
│ ├── json.xqy
│ ├── manage.xqy
│ ├── path-parser.xqy
│ ├── properties.xqy
│ ├── rest
│ │ ├── rest-impl.xqy
│ │ └── rest.xqy
│ ├── rewriter.xqy
│ ├── search.xqy
│ ├── store.xqy
│ ├── string-query.xqy
│ ├── structured-query-translator.xqy
│ └── structured-query.xqy
├── manage
│ ├── bucketedrange.xqy
│ ├── env.xqy
│ ├── geo.xqy
│ ├── namedqueryprefix.xqy
│ ├── namespace.xqy
│ ├── places.xqy
│ ├── range.xqy
│ ├── schemas.xqy
│ ├── summary.xqy
│ └── transformer.xqy
├── misc
│ └── 404.xqy
├── named-query.xqy
├── search.xqy
├── store-get.xqy
├── store.xqy
└── transaction.xqy
└── test
├── bulk-store.html
├── css
└── qunit.css
├── data
├── json.tar.gz
└── xml.tar.gz
├── dateparser.html
├── env.html
├── index.html
├── indexmgmt.html
├── js
├── bulk-store-tests.js
├── common.js
├── dateparser-tests.js
├── env-tests.js
├── indexmgmt-tests.js
├── jquery.js
├── kvquery-tests.js
├── mljson-tests.js
├── named-query-tests.js
├── path-parser-tests.js
├── qunit.js
├── schema-tests.js
├── store-tests.js
├── string-query-parser-tests.js
├── string-query-tests.js
├── structured-query-parser-tests.js
├── structured-query-tests.js
└── transaction-tests.js
├── kvquery.html
├── load.pl
├── mljson.html
├── named-query.html
├── path-parser.html
├── schema.html
├── shapefile
├── loadStates.py
├── loadStatesXML.py
├── loadZips.py
├── loadZipsXML.py
├── shapefile.py
└── shapefile.pyc
├── store.html
├── string-query-parser.html
├── string-query.html
├── structured-query-parser.html
├── structured-query.html
├── transactions.html
└── xq
├── array-construction.xqy
├── isomorphic.xqy
├── object-construction-dup-keys.xqy
├── object-construction.xqy
├── parse-string-query.xqy
├── parse-structured-query.xqy
├── parsedate.xqy
└── parsepath.xqy
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Copyright 2011 MarkLogic Corporation
2 |
3 | Licensed under the Apache License, Version 2.0 (the "License");
4 | you may not use this file except in compliance with the License.
5 | You may obtain a copy of the License at
6 |
7 | http://www.apache.org/licenses/LICENSE-2.0
8 |
9 | Unless required by applicable law or agreed to in writing, software
10 | distributed under the License is distributed on an "AS IS" BASIS,
11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | See the License for the specific language governing permissions and
13 | limitations under the License.
14 |
--------------------------------------------------------------------------------
/README.markdown:
--------------------------------------------------------------------------------
1 | # Corona - A REST interface to MarkLogic
2 |
3 | The Corona project is a community-sponsored set of REST endpoints that enable usage of [MarkLogic Server](http://developer.marklogic.com) without knowledge of XQuery.
4 |
5 | Corona provides endpoints for storing, searching and transforming XML, JSON, text and binary documents.
6 |
7 | Inside each of the REST endpoints exists a number of other powerful features. For example, the entire structure of the documents can be queried with either key/value lookups, a search box query string, or a powerful structured query language. When retrieving documents, a path may be provided to extract out specific sections and XSLT/XQuery transformations can be applied to the content.
8 |
9 | Specific to JSON content, dates in dozens of formats can be parsed and stored as actual dates. If the value of a key is a string of XML, that XML can be unquoted, stored and queried as actual XML.
10 |
11 | On top of this, you get the built in scalability, speed and database features that MarkLogic Server provides. Need geospatial support? It's included. Clustering? Yep, that's there too. Multiple languages? Of course! Powerful fulltext search? Nobody does it better.
12 |
13 | There is a tutorial at http://developer.marklogic.com/try/corona/index
14 |
15 | Corona runs on MarkLogic 4.1 or later. Some features require 4.2 or 5.0.
16 |
17 | ## [Installation](https://github.com/marklogic/Corona/wiki/Installation)
18 |
19 | ## [API Documentation](http://github.com/marklogic/Corona/wiki)
20 | [Check the wiki for documentation on how to store, index and query the documents.](http://github.com/marklogic/Corona/wiki)
21 |
22 | ## Get Involved
23 | There is a mailing list for Corona users at http://developer.marklogic.com/mailman/listinfo/corona
--------------------------------------------------------------------------------
/config/site/env.xqy:
--------------------------------------------------------------------------------
1 | (:
2 | Copyright 2012 MarkLogic Corporation
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | :)
16 |
17 | xquery version "1.0-ml";
18 |
19 | import module namespace template="http://marklogic.com/corona/template" at "/corona/htools/template.xqy";
20 |
21 | template:apply(
22 |
23 |
Environment Variables
24 |
25 |
,
26 | "Environment Variables - Corona",
27 | (
28 | ,
29 | ,
30 | ,
31 |
32 | ),
33 | 4,
34 | (
35 | ,
36 | ,
37 | ,
38 | ,
39 |
40 | ),
41 | (
42 | ,
43 |
44 | )
45 | )
46 |
--------------------------------------------------------------------------------
/config/site/index.xqy:
--------------------------------------------------------------------------------
1 | (:
2 | Copyright 2012 MarkLogic Corporation
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | :)
16 |
17 | xquery version "1.0-ml";
18 |
19 | import module namespace template="http://marklogic.com/corona/template" at "/corona/htools/template.xqy";
20 |
21 | template:apply(
22 |
23 |
Corona Configuration
24 | ,
25 | "Configuration - Corona",
26 | (
27 | ,
28 | ,
29 | ,
30 |
31 | ),
32 | 0,
33 | ()
34 | )
35 |
--------------------------------------------------------------------------------
/config/site/namespaces.xqy:
--------------------------------------------------------------------------------
1 | (:
2 | Copyright 2012 MarkLogic Corporation
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | :)
16 |
17 | xquery version "1.0-ml";
18 |
19 | import module namespace template="http://marklogic.com/corona/template" at "/corona/htools/template.xqy";
20 |
21 | template:apply(
22 |
23 |
XML Namespaces
24 |
25 |
,
26 | "XML Namespaces - Corona",
27 | (
28 | ,
29 | ,
30 | ,
31 |
32 | ),
33 | 2,
34 | (
35 | ,
36 | ,
37 | ,
38 | ,
39 |
40 | ),
41 | (
42 | ,
43 |
44 | )
45 | )
46 |
--------------------------------------------------------------------------------
/config/site/search.xqy:
--------------------------------------------------------------------------------
1 | (:
2 | Copyright 2012 MarkLogic Corporation
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | :)
16 |
17 | xquery version "1.0-ml";
18 |
19 | import module namespace template="http://marklogic.com/corona/template" at "/corona/htools/template.xqy";
20 |
21 | template:apply(
22 | ,
26 | "Search - Corona",
27 | (
28 | ,
29 | ,
30 | ,
31 |
32 | ),
33 | 1,
34 | (
35 | ,
36 | ,
37 | ,
38 | ,
39 |
40 | ),
41 | (
42 | ,
43 |
44 | )
45 | )
46 |
--------------------------------------------------------------------------------
/config/site/transformers.xqy:
--------------------------------------------------------------------------------
1 | (:
2 | Copyright 2012 MarkLogic Corporation
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | :)
16 |
17 | xquery version "1.0-ml";
18 |
19 | import module namespace template="http://marklogic.com/corona/template" at "/corona/htools/template.xqy";
20 |
21 | template:apply(
22 |
23 |
Transformers
24 |
25 |
26 |
31 |
32 |
33 |
34 | Name
35 |
36 |
37 |
38 |
39 |
,
40 | "Transformers - Corona",
41 | (
42 | ,
43 | ,
44 | ,
45 |
46 | ),
47 | 3,
48 | (
49 | ,
50 | ,
51 | ,
52 | ,
53 |
54 | ),
55 | (
56 | ,
57 |
58 | )
59 | )
60 |
--------------------------------------------------------------------------------
/corona/facet.xqy:
--------------------------------------------------------------------------------
1 | (:
2 | Copyright 2011 MarkLogic Corporation
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | :)
16 |
17 | xquery version "1.0-ml";
18 |
19 | import module namespace const="http://marklogic.com/corona/constants" at "lib/constants.xqy";
20 | import module namespace config="http://marklogic.com/corona/index-config" at "lib/index-config.xqy";
21 | import module namespace common="http://marklogic.com/corona/common" at "lib/common.xqy";
22 | import module namespace manage="http://marklogic.com/corona/manage" at "lib/manage.xqy";
23 | import module namespace search="http://marklogic.com/corona/search" at "lib/search.xqy";
24 | import module namespace json="http://marklogic.com/json" at "lib/json.xqy";
25 | import module namespace structquery="http://marklogic.com/corona/structured-query" at "lib/structured-query.xqy";
26 | import module namespace stringquery="http://marklogic.com/corona/string-query" at "lib/string-query.xqy";
27 |
28 | import module namespace rest="http://marklogic.com/appservices/rest" at "lib/rest/rest.xqy";
29 | import module namespace endpoints="http://marklogic.com/corona/endpoints" at "/config/endpoints.xqy";
30 |
31 | declare namespace corona="http://marklogic.com/corona";
32 |
33 | declare option xdmp:mapping "false";
34 |
35 | let $params := rest:process-request(endpoints:request("/corona/facet.xqy"))
36 | let $facets := tokenize(map:get($params, "facets"), ",")
37 | let $stringQuery := map:get($params, "stringQuery")
38 | let $structuredQuery := map:get($params, "structuredQuery")
39 |
40 | let $outputFormat := common:getOutputFormat((), map:get($params, "outputFormat"))
41 |
42 | let $limit := map:get($params, "limit")
43 | let $order := map:get($params, "order")
44 | let $frequency := map:get($params, "frequency")
45 | let $includeAllValues := map:get($params, "includeAllValues")
46 | let $txid := map:get($params, "txid")
47 |
48 | let $errors := ()
49 |
50 | let $query :=
51 | if(exists($stringQuery))
52 | then stringquery:parse($stringQuery, map:get($params, "language"))
53 | else if(exists($structuredQuery))
54 | then try {
55 | structquery:getCTS(structquery:getParseTree($structuredQuery), ())
56 | }
57 | catch ($e) {
58 | xdmp:set($errors, common:error("corona:INVALID-PARAMETER", concat("The structured query JSON isn't valid: ", $e/*:message), $outputFormat))
59 | }
60 | else ()
61 |
62 |
63 | let $options := (
64 | if($order = "frequency")
65 | then "frequency-order"
66 | else $order,
67 | if($frequency = "document")
68 | then "fragment-frequency"
69 | else "item-frequency"
70 | )
71 |
72 | let $values :=
73 | if(exists($errors))
74 | then ()
75 | else if(not(common:transactionsMatch($txid)))
76 | then xdmp:invoke("/corona/facet.xqy", (), { map:get(common:processTXID($txid, true()), "id") } )
77 | else
78 |
79 | for $facet in $facets
80 |
81 | let $rawQuery :=
82 | if(exists($stringQuery))
83 | then stringquery:getParseTree($stringQuery)
84 | else if(exists($structuredQuery))
85 | then structquery:getParseTree($structuredQuery)
86 | else ()
87 |
88 | let $valuesInQuery :=
89 | if(exists($stringQuery))
90 | then stringquery:valuesForFacet($rawQuery, $facet)
91 | else if(exists($structuredQuery))
92 | then structquery:valuesForFacet($rawQuery, $facet)
93 | else ()
94 |
95 | let $ignoreFacet :=
96 | if($includeAllValues = "yes")
97 | then $facet
98 | else ()
99 |
100 | let $query :=
101 | if(exists($stringQuery))
102 | then stringquery:getCTSFromParseTree($rawQuery, map:get($params, "language"), $ignoreFacet)
103 | else if(exists($structuredQuery))
104 | then structquery:getCTSFromParseTree($rawQuery, $ignoreFacet)
105 | else $query
106 |
107 | let $query := cts:and-query((
108 | $query,
109 | for $collection in map:get($params, "collection")
110 | return cts:collection-query($collection),
111 | for $directory in map:get($params, "underDirectory")
112 | let $directory :=
113 | if(ends-with($directory, "/"))
114 | then $directory
115 | else concat($directory, "/")
116 | return cts:directory-query($directory, "infinity"),
117 | for $directory in map:get($params, "inDirectory")
118 | let $directory :=
119 | if(ends-with($directory, "/"))
120 | then $directory
121 | else concat($directory, "/")
122 | return cts:directory-query($directory)
123 | ))
124 |
125 | let $index := config:get($facet)
126 | let $options :=
127 | if($includeAllValues = "yes" and $index/@type = ("bucketedrange", "autobucketedrange"))
128 | then ("empties", $options)
129 | else $options
130 |
131 | let $values :=
132 | if($index/@type = "range")
133 | then search:rangeIndexValues($index, $query, $options, $limit, $valuesInQuery, $outputFormat)
134 | else if($index/@type = ("bucketedrange", "autobucketedrange"))
135 | then search:bucketIndexValues($index, $query, $options, $limit, $valuesInQuery, $outputFormat)
136 | else ()
137 |
138 | where exists($index)
139 | return
140 | if($outputFormat = "json")
141 | then ($facet, $values)
142 | else if($outputFormat = "xml")
143 | then { $values }
144 | else ()
145 | return common:output(
146 | if(exists($errors))
147 | then $errors
148 | else if($outputFormat = "json")
149 | then json:object($values)
150 | else if($outputFormat = "xml")
151 | then { $values }
152 | else ()
153 | )
154 |
--------------------------------------------------------------------------------
/corona/htools/css/ie.css:
--------------------------------------------------------------------------------
1 | /* ie.css */
2 | body {text-align:center;}
3 | .container {text-align:left;}
4 | * html .column, * html .span-1, * html .span-2, * html .span-3, * html .span-4, * html .span-5, * html .span-6, * html .span-7, * html .span-8, * html .span-9, * html .span-10, * html .span-11, * html .span-12, * html .span-13, * html .span-14, * html .span-15, * html .span-16, * html .span-17, * html .span-18, * html .span-19, * html .span-20, * html .span-21, * html .span-22, * html .span-23, * html .span-24 {display:inline;overflow-x:hidden;}
5 | * html legend {margin:0px -8px 16px 0;padding:0;}
6 | sup {vertical-align:text-top;}
7 | sub {vertical-align:text-bottom;}
8 | html>body p code {*white-space:normal;}
9 | hr {margin:-8px auto 11px;}
10 | img {-ms-interpolation-mode:bicubic;}
11 | .clearfix, .container {display:inline-block;}
12 | * html .clearfix, * html .container {height:1%;}
13 | fieldset {padding-top:0;}
14 | legend {margin-top:-0.2em;margin-bottom:1em;margin-left:-0.5em;}
15 | textarea {overflow:auto;}
16 | label {vertical-align:middle;position:relative;top:-0.25em;}
17 | input.text, input.title, textarea {background-color:#fff;border:1px solid #bbb;}
18 | input.text:focus, input.title:focus {border-color:#666;}
19 | input.text, input.title, textarea, select {margin:0.5em 0;}
20 | input.checkbox, input.radio {position:relative;top:.25em;}
21 | form.inline div, form.inline p {vertical-align:middle;}
22 | form.inline input.checkbox, form.inline input.radio, form.inline input.button, form.inline button {margin:0.5em 0;}
23 | button, input.button {position:relative;top:0.25em;}
--------------------------------------------------------------------------------
/corona/htools/css/print.css:
--------------------------------------------------------------------------------
1 | /* print.css */
2 | body {line-height:1.5;font-family:"Helvetica Neue", Arial, Helvetica, sans-serif;color:#000;background:none;font-size:10pt;}
3 | .container {background:none;}
4 | hr {background:#ccc;color:#ccc;width:100%;height:2px;margin:2em 0;padding:0;border:none;}
5 | hr.space {background:#fff;color:#fff;visibility:hidden;}
6 | h1, h2, h3, h4, h5, h6 {font-family:"Helvetica Neue", Arial, "Lucida Grande", sans-serif;}
7 | code {font:.9em "Courier New", Monaco, Courier, monospace;}
8 | a img {border:none;}
9 | p img.top {margin-top:0;}
10 | blockquote {margin:1.5em;padding:1em;font-style:italic;font-size:.9em;}
11 | .small {font-size:.9em;}
12 | .large {font-size:1.1em;}
13 | .quiet {color:#999;}
14 | .hide {display:none;}
15 | a:link, a:visited {background:transparent;font-weight:700;text-decoration:underline;}
16 | a:link:after, a:visited:after {content:" (" attr(href) ")";font-size:90%;}
--------------------------------------------------------------------------------
/corona/htools/img/loader.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marklogic-community/Corona/a5178fccc91a5e68e98e9dfb56587329a6f7dd10/corona/htools/img/loader.gif
--------------------------------------------------------------------------------
/corona/htools/img/ml_btn_bg_blue.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marklogic-community/Corona/a5178fccc91a5e68e98e9dfb56587329a6f7dd10/corona/htools/img/ml_btn_bg_blue.png
--------------------------------------------------------------------------------
/corona/htools/img/ml_btn_bg_blue_hover.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marklogic-community/Corona/a5178fccc91a5e68e98e9dfb56587329a6f7dd10/corona/htools/img/ml_btn_bg_blue_hover.png
--------------------------------------------------------------------------------
/corona/htools/img/ml_btn_bg_disabled.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marklogic-community/Corona/a5178fccc91a5e68e98e9dfb56587329a6f7dd10/corona/htools/img/ml_btn_bg_disabled.png
--------------------------------------------------------------------------------
/corona/htools/img/ml_icon-note.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marklogic-community/Corona/a5178fccc91a5e68e98e9dfb56587329a6f7dd10/corona/htools/img/ml_icon-note.png
--------------------------------------------------------------------------------
/corona/htools/img/ml_icons_note.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marklogic-community/Corona/a5178fccc91a5e68e98e9dfb56587329a6f7dd10/corona/htools/img/ml_icons_note.png
--------------------------------------------------------------------------------
/corona/htools/img/ml_icons_warning.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marklogic-community/Corona/a5178fccc91a5e68e98e9dfb56587329a6f7dd10/corona/htools/img/ml_icons_warning.png
--------------------------------------------------------------------------------
/corona/htools/img/ml_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marklogic-community/Corona/a5178fccc91a5e68e98e9dfb56587329a6f7dd10/corona/htools/img/ml_logo.png
--------------------------------------------------------------------------------
/corona/htools/img/ml_sep_line.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marklogic-community/Corona/a5178fccc91a5e68e98e9dfb56587329a6f7dd10/corona/htools/img/ml_sep_line.png
--------------------------------------------------------------------------------
/corona/htools/img/ml_sep_line_vert.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marklogic-community/Corona/a5178fccc91a5e68e98e9dfb56587329a6f7dd10/corona/htools/img/ml_sep_line_vert.png
--------------------------------------------------------------------------------
/corona/htools/img/ml_subnav_bullet.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marklogic-community/Corona/a5178fccc91a5e68e98e9dfb56587329a6f7dd10/corona/htools/img/ml_subnav_bullet.png
--------------------------------------------------------------------------------
/corona/htools/js/DataTables-1.8.2/.gitignore:
--------------------------------------------------------------------------------
1 | extras
2 |
--------------------------------------------------------------------------------
/corona/htools/js/DataTables-1.8.2/images/back_disabled.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marklogic-community/Corona/a5178fccc91a5e68e98e9dfb56587329a6f7dd10/corona/htools/js/DataTables-1.8.2/images/back_disabled.jpg
--------------------------------------------------------------------------------
/corona/htools/js/DataTables-1.8.2/images/back_enabled.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marklogic-community/Corona/a5178fccc91a5e68e98e9dfb56587329a6f7dd10/corona/htools/js/DataTables-1.8.2/images/back_enabled.jpg
--------------------------------------------------------------------------------
/corona/htools/js/DataTables-1.8.2/images/forward_disabled.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marklogic-community/Corona/a5178fccc91a5e68e98e9dfb56587329a6f7dd10/corona/htools/js/DataTables-1.8.2/images/forward_disabled.jpg
--------------------------------------------------------------------------------
/corona/htools/js/DataTables-1.8.2/images/forward_enabled.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marklogic-community/Corona/a5178fccc91a5e68e98e9dfb56587329a6f7dd10/corona/htools/js/DataTables-1.8.2/images/forward_enabled.jpg
--------------------------------------------------------------------------------
/corona/htools/js/DataTables-1.8.2/images/sort_asc.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marklogic-community/Corona/a5178fccc91a5e68e98e9dfb56587329a6f7dd10/corona/htools/js/DataTables-1.8.2/images/sort_asc.png
--------------------------------------------------------------------------------
/corona/htools/js/DataTables-1.8.2/images/sort_asc_disabled.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marklogic-community/Corona/a5178fccc91a5e68e98e9dfb56587329a6f7dd10/corona/htools/js/DataTables-1.8.2/images/sort_asc_disabled.png
--------------------------------------------------------------------------------
/corona/htools/js/DataTables-1.8.2/images/sort_both.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marklogic-community/Corona/a5178fccc91a5e68e98e9dfb56587329a6f7dd10/corona/htools/js/DataTables-1.8.2/images/sort_both.png
--------------------------------------------------------------------------------
/corona/htools/js/DataTables-1.8.2/images/sort_desc.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marklogic-community/Corona/a5178fccc91a5e68e98e9dfb56587329a6f7dd10/corona/htools/js/DataTables-1.8.2/images/sort_desc.png
--------------------------------------------------------------------------------
/corona/htools/js/DataTables-1.8.2/images/sort_desc_disabled.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marklogic-community/Corona/a5178fccc91a5e68e98e9dfb56587329a6f7dd10/corona/htools/js/DataTables-1.8.2/images/sort_desc_disabled.png
--------------------------------------------------------------------------------
/corona/htools/js/env.js:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2012 MarkLogic Corporation
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | if(typeof corona == "undefined" || !corona) {
18 | corona = {};
19 | }
20 |
21 | corona.envvars = {};
22 |
23 | corona.envvars.fetch = function() {
24 | $.ajax("/manage/env", {
25 | success: function(data) {
26 | var addButton = $("Add Variable ");
27 | addButton.button().click(function() {
28 | dataTable.fnAddTr(corona.envvars.createRow("", "").get(0));
29 | corona.envvars.makeTableEditable(dataTable);
30 | });
31 |
32 | $("#jscontent").append(addButton);
33 | $("#jscontent").append($(''));
34 | var table = $("#envvars");
35 | table.append("Variable Value ");
36 | var body = $("");
37 | table.append(body);
38 |
39 | $.each(data, function(key, value) {
40 | body.append(corona.envvars.createRow(key, value));
41 | });
42 |
43 | var dataTable = table.dataTable({
44 | "bJQueryUI": true,
45 | "sPaginationType": "full_numbers",
46 | "aoColumns": [
47 | null,
48 | null,
49 | { "bSortable": false }
50 | ]
51 | });
52 | corona.envvars.makeTableEditable(dataTable);
53 | },
54 | error: function(jqXHR, textStatus, error) {
55 | alert("Could not fetch environment variables: " + error);
56 | }
57 | });
58 | };
59 |
60 | corona.envvars.createRow = function(name, value) {
61 | var tr = $('');
62 | tr.append("" + name + " ");
63 | tr.append("" + value + " ");
64 | tr.append("Delete ");
65 | return tr;
66 | };
67 |
68 | corona.envvars.deleteRow = function() {
69 | var row = this.parentNode;
70 | var name = row.id.replace(/^envvar-/, "");
71 |
72 | if(name !== "") {
73 | $.ajax("/manage/env/" + name, {
74 | type: "DELETE",
75 | success: function() {
76 | var dataTable = $("#envvars").dataTable();
77 | dataTable.fnDeleteRow(row);
78 | },
79 | error: function() {
80 | alert("Could not delete environment variable");
81 | }
82 | });
83 | }
84 | else {
85 | var dataTable = $("#envvars").dataTable();
86 | dataTable.fnDeleteRow(row);
87 | }
88 | }
89 |
90 | corona.envvars.makeTableEditable = function(table) {
91 | table.makeEditable({
92 | sUpdateURL: function(newValue, settings) {
93 | var row = this.parentNode;
94 | var currentName = row.id.replace(/^envvar-/, "");
95 | var nameCell = $(row).find("td.name");
96 | var valueCell = $(row).find("td.value");
97 | var name = undefined;
98 | var value = undefined;
99 |
100 | if(nameCell.get(0) === this) {
101 | name = newValue;
102 | }
103 | else {
104 | name = nameCell.text();
105 | }
106 | if(valueCell.get(0) === this) {
107 | value = newValue;
108 | }
109 | else {
110 | value = valueCell.text();
111 | }
112 |
113 | if(currentName !== "" && currentName !== name && row.id !== "envvar-") {
114 | $.ajax("/manage/env/" + currentName, {
115 | type: "DELETE",
116 | success: function() {
117 | corona.envvars.setVariable(row, name, value);
118 | },
119 | error: function() {
120 | alert("Could not update the variable name");
121 | }
122 | });
123 | }
124 | else {
125 | corona.envvars.setVariable(row, name, value);
126 | }
127 |
128 | return newValue;
129 | },
130 | sDeleteURL: function() { return true; },
131 | aoColumns: [{}, {}, null]
132 | });
133 |
134 | table.find("td.delete").click(corona.envvars.deleteRow);
135 | };
136 |
137 | corona.envvars.setVariable = function(row, name, value) {
138 | $.ajax("/manage/env/" + name, {
139 | type: "POST",
140 | data: {"value": value},
141 | success: function() {
142 | row.id = "envvar-" + name;
143 | },
144 | error: function() {
145 | alert("Could not update environment variable");
146 | }
147 | });
148 | };
149 |
150 | $(document).ready(function() {
151 | corona.envvars.fetch();
152 | });
153 |
154 |
--------------------------------------------------------------------------------
/corona/htools/js/namespaces.js:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2012 MarkLogic Corporation
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | if(typeof corona == "undefined" || !corona) {
18 | corona = {};
19 | }
20 |
21 | corona.namespaces = {};
22 |
23 | corona.namespaces.fetch = function() {
24 | $.ajax("/manage/namespaces", {
25 | success: function(data) {
26 | var addButton = $("Add Namespace ");
27 | addButton.button().click(function() {
28 | dataTable.fnAddTr(corona.namespaces.createRow("", "").get(0));
29 | corona.namespaces.makeTableEditable(dataTable);
30 | });
31 |
32 | $("#jscontent").append(addButton);
33 | $("#jscontent").append($(''));
34 | var table = $("#namespaces");
35 | table.append("Prefix URI ");
36 | var body = $("");
37 | table.append(body);
38 |
39 | $(data).each(function(index, def) {
40 | body.append(corona.namespaces.createRow(def.prefix, def.uri));
41 | });
42 |
43 | var dataTable = table.dataTable({
44 | "bJQueryUI": true,
45 | "sPaginationType": "full_numbers",
46 | "aoColumns": [
47 | null,
48 | null,
49 | { "bSortable": false }
50 | ]
51 | });
52 | corona.namespaces.makeTableEditable(dataTable);
53 | },
54 | error: function(jqXHR, textStatus, error) {
55 | alert("Could not fetch namespaces: " + error);
56 | }
57 | });
58 | };
59 |
60 | corona.namespaces.createRow = function(prefix, uri) {
61 | var tr = $('');
62 | tr.append("" + prefix + " ");
63 | tr.append("" + uri + " ");
64 | tr.append("Delete ");
65 | return tr;
66 | };
67 |
68 | corona.namespaces.deleteRow = function() {
69 | var row = this.parentNode;
70 | var prefix = row.id.replace(/^namespace-/, "");
71 |
72 | if(prefix !== "") {
73 | $.ajax("/manage/namespace/" + prefix, {
74 | type: "DELETE",
75 | success: function() {
76 | var dataTable = $("#namespaces").dataTable();
77 | dataTable.fnDeleteRow(row);
78 | },
79 | error: function() {
80 | alert("Could not delete namespace");
81 | }
82 | });
83 | }
84 | else {
85 | var dataTable = $("#namespaces").dataTable();
86 | dataTable.fnDeleteRow(row);
87 | }
88 | }
89 |
90 | corona.namespaces.makeTableEditable = function(table) {
91 | table.makeEditable({
92 | sUpdateURL: function(value, settings) {
93 | var row = this.parentNode;
94 | var currentPrefix = row.id.replace(/^namespace-/, "");
95 | var prefixCell = $(row).find("td.prefix");
96 | var uriCell = $(row).find("td.uri");
97 | var prefix = undefined;
98 | var uri = undefined;
99 |
100 | if(prefixCell.get(0) === this) {
101 | prefix = value;
102 | }
103 | else {
104 | prefix = prefixCell.text();
105 | }
106 | if(uriCell.get(0) === this) {
107 | uri = value;
108 | }
109 | else {
110 | uri = uriCell.text();
111 | }
112 |
113 | if(currentPrefix !== "") {
114 | $.ajax("/manage/namespace/" + currentPrefix, {
115 | type: "DELETE",
116 | success: function() {
117 | corona.namespaces.createNamespace(row, prefix, uri);
118 | },
119 | error: function() {
120 | corona.namespaces.createNamespace(row, prefix, uri);
121 | }
122 | });
123 | }
124 | else {
125 | corona.namespaces.createNamespace(row, prefix, uri);
126 | }
127 |
128 | return value;
129 | },
130 | sDeleteURL: function() { return true; },
131 | aoColumns: [{}, {}, null]
132 | });
133 |
134 | table.find("td.delete").click(corona.namespaces.deleteRow);
135 | };
136 |
137 | corona.namespaces.createNamespace = function(row, prefix, uri) {
138 | $.ajax("/manage/namespace/" + prefix, {
139 | type: "POST",
140 | data: {"uri": uri},
141 | success: function() {
142 | row.id = "namespace-" + prefix;
143 | },
144 | error: function() {
145 | alert("Could not update namespace");
146 | }
147 | });
148 | };
149 |
150 | $(document).ready(function() {
151 | corona.namespaces.fetch();
152 | });
153 |
--------------------------------------------------------------------------------
/corona/htools/js/search.js:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2012 MarkLogic Corporation
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | if(typeof corona == "undefined" || !corona) {
18 | corona = {};
19 | }
20 |
21 | corona.search = {};
22 |
23 | corona.search.fetch = function() {
24 | $.ajax("/manage", {
25 | success: function(data) {
26 | var addButton = $("Add Constraint ");
27 | addButton.button().click(function() {
28 | });
29 |
30 | $("#jscontent").append(addButton);
31 | $("#jscontent").append($(''));
32 | var table = $("#search");
33 | table.append("Name Type Summary   ");
34 | var body = $("");
35 | table.append(body);
36 |
37 | $.each(data.indexes.ranges, function(index, def) {
38 | var type = "key";
39 | if(def.attribute !== undefined) {
40 | type = "attribute";
41 | }
42 | else if(def.element !== undefined) {
43 | type = "element";
44 | }
45 |
46 | var summary = "";
47 | if(def.key !== undefined) {
48 | summary = def.key + " (" + def.type + ")";
49 | }
50 | else if(def.attribute !== undefined) {
51 | summary = def.element + "/@" + def.attribute + " (" + def.type + ")";
52 | }
53 | else if(def.element !== undefined) {
54 | summary = def.element + " (" + def.type + ")";
55 | }
56 |
57 | body.append(corona.search.createRow("range", def.name, "Range (" + type + ")", summary));
58 | });
59 |
60 | $.each(data.indexes.bucketedRanges, function(index, def) {
61 | var type = "key";
62 | if(def.attribute !== undefined) {
63 | type = "attribute";
64 | }
65 | else if(def.element !== undefined) {
66 | type = "element";
67 | }
68 |
69 | var summary = "";
70 | if(def.key !== undefined) {
71 | summary = def.key + " (" + def.type + ")";
72 | }
73 | else if(def.attribute !== undefined) {
74 | summary = def.element + "/@" + def.attribute + " (" + def.type + ")";
75 | }
76 | else if(def.element !== undefined) {
77 | summary = def.element + " (" + def.type + ")";
78 | }
79 |
80 | body.append(corona.search.createRow("bucketedRange", def.name, "Bucketed range (" + type + ")", summary));
81 | });
82 |
83 | $.each(data.indexes.places, function(index, def) {
84 | var numIncludes = 0;
85 | var numExcludes = 0;
86 | $.each(def.places, function(index, place) {
87 | if(place.type = "include") {
88 | numIncludes += 1;
89 | }
90 | else {
91 | numExcludes += 1;
92 | }
93 | });
94 |
95 | body.append(corona.search.createRow("place", def.name, "Place", numIncludes + " includes, " + numExcludes + " excludes"));
96 | });
97 |
98 | $.each(data.indexes.geo, function(index, def) {
99 | var summary = "";
100 | if(def.parentKey !== undefined) {
101 | if(def.latKey !== undefined) {
102 | summary = def.parentKey + "." + def.latKey + ", " + def.parentKey + "." + def.longKey;
103 | }
104 | else {
105 | summary = def.parentKey + "." + def.key;
106 | }
107 | }
108 | else if(def.parentElement !== undefined) {
109 | if(def.latElement !== undefined) {
110 | summary = def.parentElement + "/" + def.latElement + ", " + def.parentElement + "/" + def.longElement;
111 | }
112 | else if(def.element !== undefined) {
113 | summary = def.parentElement + "/" + def.element;
114 | }
115 | else {
116 | summary = def.parentElement + "/@" + def.latAttribute + ", " + def.parentElement + "/@" + def.longAttribute;
117 | }
118 | }
119 | else if(def.key !== undefined) {
120 | summary = def.key;
121 | }
122 | else if(def.element !== undefined) {
123 | summary = def.element;
124 | }
125 |
126 | body.append(corona.search.createRow("geo", def.name, "Geospatial", summary));
127 | });
128 |
129 | var dataTable = table.dataTable({
130 | "bDestroy": true,
131 | "bJQueryUI": true,
132 | "sPaginationType": "full_numbers",
133 | "aoColumns": [
134 | null,
135 | null,
136 | { "bSortable": false },
137 | { "bSortable": false }
138 | ]
139 | });
140 | corona.search.makeTableEditable(dataTable);
141 | },
142 | error: function(jqXHR, textStatus, error) {
143 | alert("Could not fetch search configuration: " + error);
144 | }
145 | });
146 | };
147 |
148 | corona.search.createRow = function(type, name, dataType, summary) {
149 | var tr = $('');
150 | tr.append("" + name + " ");
151 | tr.append("" + dataType + " ");
152 | tr.append("" + summary + " ");
153 | tr.append("Delete ");
154 | return tr;
155 | };
156 |
157 | corona.search.deleteRow = function() {
158 | var row = this.parentNode;
159 | corona.search.deleteByTableRow(row, function() {
160 | var dataTable = $("#search").dataTable();
161 | dataTable.fnDeleteRow(row);
162 | corona.search.makeTableEditable(dataTable);
163 | });
164 | }
165 |
166 | corona.search.deleteByTableRow = function(row, callback) {
167 | var name = row.id.replace(/^search-/, "");
168 |
169 | if(name !== "") {
170 | var url = "";
171 |
172 | if($(row).hasClass("searchtype-range")) {
173 | url = "/manage/range/" + name;
174 | }
175 | else if($(row).hasClass("searchtype-bucketedRange")) {
176 | url = "/manage/bucketedrange/" + name;
177 | }
178 | else if($(row).hasClass("searchtype-place")) {
179 | url = "/manage/place/" + name;
180 | }
181 | else if($(row).hasClass("searchtype-geo")) {
182 | url = "/manage/geospatial/" + name;
183 | }
184 | else if($(row).hasClass("searchtype-nqp")) {
185 | url = "/manage/namedqueryprefix/" + name;
186 | }
187 |
188 | $.ajax(url, {
189 | type: "DELETE",
190 | success: function() {
191 | callback.call();
192 | },
193 | error: function() {
194 | alert("Could not delete search configuration item");
195 | }
196 | });
197 | }
198 | else {
199 | if(callback !== undefined) {
200 | callback.call();
201 | }
202 | }
203 | };
204 |
205 | corona.search.makeTableEditable = function(table) {
206 | table.find("td.delete").click(corona.search.deleteRow);
207 | };
208 |
209 | $(document).ready(function() {
210 | corona.search.fetch();
211 | });
212 |
--------------------------------------------------------------------------------
/corona/htools/js/setup.js:
--------------------------------------------------------------------------------
1 | if(typeof corona == "undefined" || !corona) {
2 | corona = {};
3 | }
4 |
5 |
6 | $(document).ready(function() {
7 | $("form.createUsers").submit(function() {
8 | var adminName = $("input.an");
9 | var adminPass1 = $("input.ap1");
10 | var adminPass2 = $("input.ap2");
11 |
12 | var devName = $("input.dn");
13 | var devPass1 = $("input.dp1");
14 | var devPass2 = $("input.dp2");
15 |
16 | var hasError = false;
17 | if(adminName.val().length === 0) {
18 | adminName.addClass("error");
19 | hasError = true;
20 | }
21 | else {
22 | adminName.removeClass("error");
23 | }
24 | if(adminPass1.val() !== adminPass2.val() || adminPass1.val().length === 0) {
25 | adminPass1.addClass("error");
26 | adminPass2.addClass("error");
27 | hasError = true;
28 | }
29 | else {
30 | adminPass1.removeClass("error");
31 | adminPass2.removeClass("error");
32 | }
33 |
34 | if(devName.val().length === 0) {
35 | devName.addClass("error");
36 | hasError = true;
37 | }
38 | else {
39 | devName.removeClass("error");
40 | }
41 | if(devPass1.val() !== devPass2.val() || adminPass1.val().length === 0) {
42 | devPass1.addClass("error");
43 | devPass2.addClass("error");
44 | hasError = true;
45 | }
46 | else {
47 | devPass1.removeClass("error");
48 | devPass2.removeClass("error");
49 | }
50 |
51 | if(hasError) {
52 | return false;
53 | }
54 | });
55 | });
56 |
--------------------------------------------------------------------------------
/corona/htools/template.xqy:
--------------------------------------------------------------------------------
1 | (:
2 | Copyright 2011 MarkLogic Corporation
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | :)
16 |
17 | xquery version "1.0-ml";
18 |
19 | module namespace template="http://marklogic.com/corona/template";
20 |
21 | declare default function namespace "http://www.w3.org/2005/xpath-functions";
22 |
23 | declare function template:apply(
24 | $content as element()*,
25 | $title as xs:string,
26 | $nav as element(li)*,
27 | $page as xs:integer,
28 | $scripts as element(script)*
29 | ) as item()+
30 | {
31 | template:apply($content, $title, $nav, $page, $scripts, ())
32 | };
33 |
34 | declare function template:apply(
35 | $content as element()*,
36 | $title as xs:string,
37 | $nav as element(li)*,
38 | $page as xs:integer,
39 | $scripts as element(script)*,
40 | $links as element(link)*
41 | ) as item()+
42 | {
43 | let $set := xdmp:set-response-content-type("text/html; charset=utf-8")
44 | (:
45 | let $nav := (
46 | ,
47 | ,
48 | ,
49 | ,
50 | ,
51 | ,
52 | ,
53 | ,
54 | ,
55 | ,
56 | ,
57 | ,
58 | ,
59 |
60 | )
61 | :)
62 | return (
63 | "",
64 |
65 |
66 |
67 | { $title } - Corona
68 |
69 |
72 |
73 |
74 |
75 |
76 | { $links }
77 |
78 |
79 |
86 |
87 |
88 |
89 | {
90 | if(exists($nav))
91 | then
92 |
93 |
{
94 | for $navItem at $pos in $nav
95 | return {(
96 | if($pos = $page)
97 | then attribute class {"subnav_item_active"}
98 | else (),
99 | $navItem/*
100 | )}
101 | }
102 |
103 | else ()
104 | }
105 |
{ $content }
106 |
107 |
108 |
109 |
114 |
115 |
116 | { $scripts }
117 |
118 | )
119 | };
120 |
--------------------------------------------------------------------------------
/corona/kvquery.xqy:
--------------------------------------------------------------------------------
1 | (:
2 | Copyright 2011 MarkLogic Corporation
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | :)
16 |
17 |
18 | xquery version "1.0-ml";
19 |
20 | import module namespace common="http://marklogic.com/corona/common" at "lib/common.xqy";
21 | import module namespace json="http://marklogic.com/json" at "lib/json.xqy";
22 | import module namespace const="http://marklogic.com/corona/constants" at "lib/constants.xqy";
23 | import module namespace manage="http://marklogic.com/corona/manage" at "lib/manage.xqy";
24 | import module namespace store="http://marklogic.com/corona/store" at "lib/store.xqy";
25 | import module namespace dateparser="http://marklogic.com/dateparser" at "lib/date-parser.xqy";
26 |
27 | import module namespace rest="http://marklogic.com/appservices/rest" at "lib/rest/rest.xqy";
28 | import module namespace endpoints="http://marklogic.com/corona/endpoints" at "/config/endpoints.xqy";
29 |
30 | declare option xdmp:mapping "false";
31 |
32 | let $params := rest:process-request(endpoints:request("/corona/kvquery.xqy"))
33 |
34 |
35 | let $key := map:get($params, "key")
36 | let $element := map:get($params, "element")
37 | let $attribute := map:get($params, "attribute")
38 | let $property := map:get($params, "property")
39 | let $value := map:get($params, "value")
40 |
41 | let $start := map:get($params, "start")
42 | let $length := map:get($params, "length")
43 | let $include := map:get($params, "include")
44 | let $extractPath := map:get($params, "extractPath")
45 | let $applyTransform := map:get($params, "applyTransform")
46 |
47 | let $txid := map:get($params, "txid")
48 | let $outputFormat := common:getOutputFormat((), map:get($params, "outputFormat"))
49 |
50 | let $errors := (
51 | if(exists($attribute) and empty($element))
52 | then common:error("corona:MISSING-PARAMETER", "Must supply the parent element name when searching for an attribute value", $outputFormat)
53 | else if((exists($key) or exists($element) or exists($property)) and empty($value))
54 | then common:error("corona:MISSING-PARAMETER", "Must supply a value along with the key, element, element/attribute or property", $outputFormat)
55 | else if(exists($value) and empty($key) and empty($element) and empty($property))
56 | then common:error("corona:MISSING-PARAMETER", "Must supply a key, element, element/attribute or property along with the value", $outputFormat)
57 | else ()
58 | )
59 | return
60 | if(exists($errors))
61 | then $errors
62 | else if(not(common:transactionsMatch($txid)))
63 | then xdmp:invoke("/corona/kvquery.xqy", (), { map:get(common:processTXID($txid, true()), "id") } )
64 | else
65 |
66 |
67 | let $query :=
68 | if(exists($key))
69 | then
70 | if(json:castAs($key, true()) = "date")
71 | then
72 | let $date := dateparser:parse($value)
73 | return
74 | if(empty($date))
75 | then cts:element-value-query(common:keyToQName($key), $value, "exact")
76 | else cts:element-attribute-value-query(common:keyToQName($key), xs:QName("normalized-date"), $date, "exact")
77 |
78 | else if($value = ("true", "false"))
79 | then cts:or-query((
80 | cts:element-value-query(common:keyToQName($key), $value, "exact"),
81 | cts:element-attribute-value-query(common:keyToQName($key), xs:QName("boolean"), $value, "exact")
82 | ))
83 |
84 | else cts:element-value-query(common:keyToQName($key), $value, "exact")
85 | else if(exists($element) and exists($attribute))
86 | then cts:element-attribute-value-query(xs:QName($element), xs:QName($attribute), $value, "exact")
87 | else if(exists($element))
88 | then cts:element-value-query(xs:QName($element), $value, "exact")
89 | else if(exists($property))
90 | then cts:properties-query(cts:element-value-query(QName("http://marklogic.com/corona", $property), $value, "exact"))
91 | else ()
92 |
93 | let $query := cts:and-query((
94 | $query,
95 | for $collection in map:get($params, "collection")
96 | return cts:collection-query($collection),
97 | for $directory in map:get($params, "underDirectory")
98 | let $directory :=
99 | if(ends-with($directory, "/"))
100 | then $directory
101 | else concat($directory, "/")
102 | return cts:directory-query($directory, "infinity"),
103 | for $directory in map:get($params, "inDirectory")
104 | let $directory :=
105 | if(ends-with($directory, "/"))
106 | then $directory
107 | else concat($directory, "/")
108 | return cts:directory-query($directory)
109 | ))
110 |
111 | let $log := common:log("Key/Value Query", "Generated query", $query)
112 |
113 | let $end := $start + $length - 1
114 |
115 | let $results := cts:search(doc(), $query)[$start to $end]
116 |
117 | let $total :=
118 | if(exists($results[1]))
119 | then cts:remainder($results[1]) + $start - 1
120 | else 0
121 |
122 | let $end :=
123 | if($end > $total)
124 | then $total
125 | else $end
126 |
127 | let $results :=
128 | try {
129 | store:outputMultipleDocuments($results, $start, $end, $total, $include, $query, $extractPath, $applyTransform, $params, $outputFormat)
130 | }
131 | catch ($e) {
132 | xdmp:set($errors, common:errorFromException($e, $outputFormat))
133 | }
134 |
135 | return common:output(($errors, $results)[1])
136 |
--------------------------------------------------------------------------------
/corona/lib/analyze-string.xqy:
--------------------------------------------------------------------------------
1 | (:
2 | Copyright 2011 MarkLogic Corporation
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | :)
16 |
17 | xquery version "1.0-ml";
18 |
19 | module namespace as="http://marklogic.com/corona/analyze-string";
20 |
21 | declare default function namespace "http://www.w3.org/2005/xpath-functions";
22 |
23 |
24 | declare function as:analyzeString(
25 | $input as xs:string,
26 | $tokens as xs:string+
27 | ) as element()
28 | {
29 | try {
30 | xdmp:apply(xdmp:function(xs:QName("fn:analyze-string")), $input, as:generateRegex($tokens))
31 | }
32 | catch ($e ) {
33 | as:manualMatch($input, $tokens)
34 | }
35 | };
36 |
37 | declare private function as:generateRegex(
38 | $tokens as xs:string+
39 | ) as xs:string
40 | {
41 | string-join($tokens, "|")
42 | };
43 |
44 | declare private function as:manualMatch(
45 | $input as xs:string,
46 | $tokens as xs:string+
47 | ) as element()
48 | {
49 | let $regex := as:generateRegex($tokens)
50 | let $replacement := string-join(for $i in 1 to count($tokens) return concat("[", $i, ":$", $i, "]"), "")
51 | let $temp := replace($input, $regex, $replacement)
52 | let $temp := replace($temp, "\[\d\d?:\]", "")
53 | let $resultXML := xdmp:unquote(concat("", replace($temp, "\[(\d\d?):([^\[]*)\]", "$2 "), " "))/*
54 | return {
55 | for $node in $resultXML/node()
56 | return
57 | if($node instance of element())
58 | then $node
59 | else { $node }
60 | }
61 | };
62 |
--------------------------------------------------------------------------------
/corona/lib/constants.xqy:
--------------------------------------------------------------------------------
1 | (:
2 | Copyright 2011 MarkLogic Corporation
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | :)
16 |
17 | xquery version "1.0-ml";
18 |
19 | module namespace const="http://marklogic.com/corona/constants";
20 |
21 |
22 | declare variable $const:version as xs:string := "1.0";
23 | declare variable $const:TransformersCollection as xs:string := "corona-transformers";
24 | declare variable $const:TransformerReadRole as xs:string := "corona-dev";
25 | declare variable $const:StoredQueriesCollection as xs:string := "corona-stored-queries";
26 |
--------------------------------------------------------------------------------
/corona/lib/error-handler.xqy:
--------------------------------------------------------------------------------
1 | (:
2 | Copyright 2011 MarkLogic Corporation
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | :)
16 |
17 | xquery version "1.0-ml";
18 |
19 | import module namespace common="http://marklogic.com/corona/common" at "../lib/common.xqy";
20 |
21 | declare variable $error:errors as node()* external;
22 |
23 | common:output(common:errorFromException($error:errors[1], xdmp:get-request-field("outputFormat")))
24 |
--------------------------------------------------------------------------------
/corona/lib/rest/rest.xqy:
--------------------------------------------------------------------------------
1 | xquery version "1.0-ml";
2 |
3 | module namespace rest="http://marklogic.com/appservices/rest";
4 |
5 | import module namespace rest-impl="http://marklogic.com/appservices/rest-impl"
6 | at "rest-impl.xqy";
7 |
8 | declare default function namespace "http://www.w3.org/2005/xpath-functions";
9 |
10 | declare option xdmp:mapping "false";
11 |
12 | declare variable $rest:UNACCEPTABLETYPE := xs:QName("rest:UNACCEPTABLETYPE");
13 | declare variable $rest:UNSUPPORTEDPARAM := xs:QName("rest:UNSUPPORTEDPARAM");
14 | declare variable $rest:INVALIDTYPE := xs:QName("rest:INVALIDTYPE");
15 | declare variable $rest:INCORRECTURI := xs:QName("rest:INCORRECTURI");
16 | declare variable $rest:UNSUPPORTEDMETHOD := xs:QName("rest:UNSUPPORTEDMETHOD");
17 | declare variable $rest:INVALIDPARAM := xs:QName("rest:INVALIDPARAM");
18 | declare variable $rest:REPEATEDPARAM := xs:QName("rest:REPEATEDPARAM");
19 | declare variable $rest:REQUIREDPARAM := xs:QName("rest:REQUIREDPARAM");
20 | declare variable $rest:INVALIDCONDITION := xs:QName("rest:INVALIDCONDITION");
21 | declare variable $rest:FAILEDCONDITION := xs:QName("rest:FAILEDCONDITION");
22 |
23 | (: ====================================================================== :)
24 |
25 | declare function rest:rewrite(
26 | $options as element(rest:options)
27 | ) as xs:string?
28 | {
29 | let $reqenv := rest-impl:request-environment()
30 | return
31 | rest-impl:rewrite($options/rest:request, rest-impl:request-environment())
32 | };
33 |
34 | declare function rest:rewrite(
35 | $options as element(rest:options),
36 | $uri as xs:string)
37 | as xs:string?
38 | {
39 | let $reqenv := rest-impl:request-environment()
40 | let $_ := map:put($reqenv, "uri", $uri)
41 | return
42 | rest-impl:rewrite($options/rest:request, $reqenv)
43 | };
44 |
45 | declare function rest:rewrite(
46 | $requests as element(rest:request)*,
47 | $uri as xs:string,
48 | $method as xs:string,
49 | $accept-headers as xs:string*,
50 | $user-params as map:map)
51 | as xs:string?
52 | {
53 | let $reqenv := rest-impl:request-environment()
54 | let $_ := map:put($reqenv, "uri", $uri)
55 | let $_ := map:put($reqenv, "method", $method)
56 | let $_ := map:put($reqenv, "accept", $accept-headers)
57 | let $_ := map:put($reqenv, "params", $user-params)
58 | return
59 | rest-impl:rewrite($requests, $reqenv)
60 | };
61 |
62 | (: ====================================================================== :)
63 |
64 | declare function rest:matching-request(
65 | $options as element(rest:options))
66 | as element(rest:request)?
67 | {
68 | let $reqenv := rest-impl:request-environment()
69 | return
70 | rest-impl:matching-request($options/rest:request, $reqenv)
71 | };
72 |
73 | declare function rest:matching-request(
74 | $options as element(rest:options),
75 | $uri as xs:string,
76 | $method as xs:string,
77 | $accept-headers as xs:string*,
78 | $user-params as map:map)
79 | as element(rest:request)?
80 | {
81 | let $reqenv := rest-impl:request-environment()
82 | let $_ := map:put($reqenv, "uri", $uri)
83 | let $_ := map:put($reqenv, "method", $method)
84 | let $_ := map:put($reqenv, "accept", $accept-headers)
85 | let $_ := map:put($reqenv, "params", $user-params)
86 | return
87 | rest-impl:matching-request($options/rest:request, $reqenv)
88 | };
89 |
90 | declare function rest:process-request(
91 | $request as element(rest:request))
92 | as map:map
93 | {
94 | let $reqenv := rest-impl:request-environment()
95 | return
96 | rest-impl:process-request($request, $reqenv)
97 | };
98 |
99 | declare function rest:check-options(
100 | $options as element(rest:options))
101 | as element(rest:report)?
102 | {
103 | rest-impl:check-options($options)
104 | };
105 |
106 | declare function rest:check-request(
107 | $options as element(rest:request))
108 | as element(rest:report)?
109 | {
110 | rest-impl:check-request($options)
111 | };
112 |
113 | declare function rest:test-request-method(
114 | $request as element(rest:request))
115 | as empty-sequence()
116 | {
117 | let $method := xdmp:get-request-method()
118 | let $test := rest-impl:method-matches($request, $method, true())
119 | return
120 | ()
121 | };
122 |
123 | declare function rest:test-conditions(
124 | $request as element(rest:request))
125 | as empty-sequence()
126 | {
127 | let $reqenv := rest-impl:request-environment()
128 | let $test := rest-impl:conditions-match($request, $reqenv, true())
129 | return
130 | ()
131 | };
132 |
133 | declare function rest:get-acceptable-types(
134 | $types as xs:string*)
135 | as xs:string*
136 | {
137 | rest-impl:get-return-types($types, xdmp:get-request-header("Accept"))
138 | };
139 |
140 | declare function rest:get-raw-query-params()
141 | as map:map
142 | {
143 | let $params := map:map()
144 | let $_ := for $name in xdmp:get-request-field-names()
145 | let $values := xdmp:get-request-field($name)
146 | return
147 | map:put($params, $name, $values)
148 | return
149 | $params
150 | };
151 |
152 | declare function rest:report-error(
153 | $error as element())
154 | as element()
155 | {
156 | rest-impl:report-error($error)
157 | };
158 |
159 |
160 |
--------------------------------------------------------------------------------
/corona/lib/rewriter.xqy:
--------------------------------------------------------------------------------
1 | (:
2 | Copyright 2011 MarkLogic Corporation
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | :)
16 |
17 | xquery version "1.0-ml";
18 |
19 | import module namespace manage="http://marklogic.com/corona/manage" at "manage.xqy";
20 | import module namespace common="http://marklogic.com/corona/common" at "common.xqy";
21 | import module namespace rest="http://marklogic.com/appservices/rest" at "rest/rest.xqy";
22 | import module namespace endpoints="http://marklogic.com/corona/endpoints" at "/config/endpoints.xqy";
23 |
24 | declare default function namespace "http://www.w3.org/2005/xpath-functions";
25 |
26 | declare option xdmp:mapping "false";
27 |
28 | let $url := xdmp:get-request-url()
29 | let $result := rest:rewrite(endpoints:options())
30 | let $log :=
31 | if(manage:getDebugLogging())
32 | then (
33 | common:log("Request", concat(xdmp:get-request-method(), " ", $url)),
34 |
35 | for $header in xdmp:get-request-header-names()
36 | for $value in xdmp:get-request-header($header)
37 | return common:log("Header", concat(" ", $header, ": ", $value)),
38 |
39 | for $param in xdmp:get-request-field-names()
40 | for $value in xdmp:get-request-field($param)
41 | return common:log("Parameter", concat(" ", $param, ": ", $value))
42 | )
43 | else ()
44 | return
45 | if(exists($result))
46 | then $result
47 | else if(starts-with($url, "/test") or starts-with($url, "/corona/htools/"))
48 | then $url
49 | else concat("/corona/misc/404.xqy?", substring-after(xdmp:get-request-url(), "?"))
50 |
--------------------------------------------------------------------------------
/corona/lib/structured-query-translator.xqy:
--------------------------------------------------------------------------------
1 | (:
2 | Copyright 2011 MarkLogic Corporation
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | :)
16 |
17 | module namespace sqt="http://marklogic.com/corona/structured-query-translator";
18 | import module namespace json="http://marklogic.com/json" at "json.xqy";
19 |
20 | declare namespace corona="http://marklogic.com/corona";
21 |
22 | declare default function namespace "http://www.w3.org/2005/xpath-functions";
23 |
24 |
25 | declare function sqt:translate(
26 | $query as element()
27 | ) as element(json:json)
28 | {
29 | json:document(sqt:process($query))
30 | };
31 |
32 | declare private function sqt:process(
33 | $step as element()
34 | ) as item()*
35 | {
36 | typeswitch($step)
37 | case element(constraint) return sqt:createObjectOutputKeyProcessValue($step)
38 | case element(and) return json:object(("and", sqt:outputChildrenAsArray($step)))
39 | case element(or) return json:object(("or", sqt:outputChildrenAsArray($step)))
40 | case element(near) return json:array(for $item in $step/constraint return sqt:createObjectOutputKeyProcessValue($item))
41 | case element(not) return json:object(("not", sqt:process(($step/*)[1])))
42 | case element(andNot) return sqt:handleObjectValue($step)
43 | case element(query) return
44 | if(exists($step/*))
45 | then sqt:process(($step/*)[1])
46 | else sqt:handleValue($step)
47 |
48 | case element(positive) return sqt:process(($step/*)[1])
49 | case element(negative) return sqt:process(($step/*)[1])
50 |
51 | case element(boolean) return sqt:handleSimpleKeyValue($step, "boolean")
52 | case element(isNULL) return sqt:handleSimpleKeyValue($step, ())
53 | case element(keyExists) return sqt:handleSimpleKeyValue($step, ())
54 | case element(elementExists) return sqt:handleSimpleKeyValue($step, ())
55 | case element(collection) return sqt:handleSimpleKeyValue($step, ())
56 | case element(namedQuery) return sqt:handleSimpleKeyValue($step, ())
57 |
58 | case element(equals) return sqt:handleMixedValue($step)
59 | case element(contains) return sqt:handleMixedValue($step)
60 | case element(value) return sqt:handleMixedValue($step)
61 | case element(wordAnywhere) return sqt:handleMixedValue($step)
62 | case element(wordInBinary) return sqt:handleMixedValue($step)
63 | case element(inTextDocument) return sqt:handleMixedValue($step)
64 |
65 | case element(weight) return xs:decimal($step)
66 | case element(distance) return xs:decimal($step)
67 | case element(minimumOccurances) return xs:integer($step)
68 | case element(maximumOccurances) return xs:integer($step)
69 | case element(caseSensitive) return xs:boolean($step)
70 | case element(diacriticSensitive) return xs:boolean($step)
71 | case element(punctuationSensitve) return xs:boolean($step)
72 | case element(whitespaceSensitive) return xs:boolean($step)
73 | case element(stemmed) return xs:boolean($step)
74 | case element(wildcarded) return xs:boolean($step)
75 | case element(descendants) return xs:boolean($step)
76 | case element(ordered) return xs:boolean($step)
77 |
78 | (: Geo :)
79 | case element(geo) return sqt:handleValue($step)
80 | case element(region) return sqt:handleValue($step)
81 | case element(point) return sqt:handleValue($step)
82 | case element(circle) return sqt:handleValue($step)
83 | case element(box) return sqt:handleValue($step)
84 | case element(polygon) return sqt:outputChildrenAsArray($step)
85 | case element(latitude) return xs:decimal($step)
86 | case element(longitude) return xs:decimal($step)
87 | case element(radius) return xs:decimal($step)
88 | case element(north) return xs:decimal($step)
89 | case element(south) return xs:decimal($step)
90 | case element(east) return xs:decimal($step)
91 | case element(west) return xs:decimal($step)
92 |
93 | default return string($step)
94 | };
95 |
96 | declare private function sqt:createObjectOutputKeyProcessValue(
97 | $step as element()
98 | ) as element(json:item)
99 | {
100 | json:object(
101 | for $item in $step/*
102 | return (local-name($item), sqt:process($item))
103 | )
104 | };
105 |
106 | declare private function sqt:outputChildrenAsArray(
107 | $step as element()
108 | ) as element(json:item)
109 | {
110 | json:array(for $item in $step/* return sqt:process($item))
111 | };
112 |
113 | declare private function sqt:handleObjectValue(
114 | $step as element()
115 | ) as element(json:item)
116 | {
117 | json:object((local-name($step), sqt:createObjectOutputKeyProcessValue($step)))
118 | };
119 |
120 | declare private function sqt:handleMixedValue(
121 | $step as element()
122 | )
123 | {
124 | if(exists($step/*))
125 | then json:array(for $i in $step/value return sqt:handleValue($i))
126 | else sqt:handleValue($step)
127 | };
128 |
129 | declare private function sqt:handleSimpleKeyValue(
130 | $step as element(),
131 | $castAs as xs:string?
132 | ) as element()
133 | {
134 | if($castAs = "boolean")
135 | then json:object((local-name($step), xs:boolean($step)))
136 | else if($castAs = "number")
137 | then json:object((local-name($step), xs:decimal($step)))
138 | else if($castAs = "string")
139 | then json:object((local-name($step), xs:string($step)))
140 | else json:object((local-name($step), sqt:handleMixedValue($step)))
141 | };
142 |
143 | declare private function sqt:handleValue(
144 | $value as element()
145 | )
146 | {
147 | if(exists($value/*))
148 | then sqt:createObjectOutputKeyProcessValue($value)
149 | else if(empty($value/@type) or $value/@type = "string")
150 | then string($value)
151 | else if($value/@type = "boolean")
152 | then xs:boolean($value)
153 | else if($value/@type = "number")
154 | then xs:decimal($value)
155 | else string($value)
156 | };
157 |
158 |
--------------------------------------------------------------------------------
/corona/manage/bucketedrange.xqy:
--------------------------------------------------------------------------------
1 | (:
2 | Copyright 2011 MarkLogic Corporation
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | :)
16 |
17 | xquery version "1.0-ml";
18 |
19 | import module namespace manage="http://marklogic.com/corona/manage" at "../lib/manage.xqy";
20 | import module namespace common="http://marklogic.com/corona/common" at "../lib/common.xqy";
21 | import module namespace json="http://marklogic.com/json" at "../lib/json.xqy";
22 |
23 | import module namespace rest="http://marklogic.com/appservices/rest" at "../lib/rest/rest.xqy";
24 | import module namespace endpoints="http://marklogic.com/corona/endpoints" at "/config/endpoints.xqy";
25 | import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy";
26 |
27 | declare option xdmp:mapping "false";
28 |
29 |
30 | let $params := rest:process-request(endpoints:request("/corona/manage/bucketedrange.xqy"))
31 | let $name := map:get($params, "name")
32 | let $requestMethod := xdmp:get-request-method()
33 |
34 | let $config := admin:get-configuration()
35 | let $existing := manage:getBucketedRange($name)
36 |
37 | return common:output(
38 | if($requestMethod = "GET")
39 | then
40 | if(string-length($name))
41 | then
42 | if(exists($existing))
43 | then $existing
44 | else common:error("corona:RANGE-INDEX-NOT-FOUND", "Bucketed range index not found", "json")
45 | else json:array(manage:getAllBucketedRanges())
46 |
47 | else if($requestMethod = "POST")
48 | then
49 | if(string-length($name))
50 | then
51 | let $key := map:get($params, "key")
52 | let $element := map:get($params, "element")
53 | let $attribute := map:get($params, "attribute")
54 | let $type := map:get($params, "type")
55 | let $bucketString := map:get($params, "buckets")
56 | let $buckets :=
57 | (: doesn't look like the server supports negative lookbehind, hence this sad hack :)
58 | let $bucketString := replace($bucketString, "\\\|", "____________PIPE____________")
59 | let $bucketString := replace($bucketString, "\\\\", "\\")
60 |
61 | for $bit at $pos in tokenize($bucketString, "\|")
62 | let $bit := replace($bit, "____________PIPE____________", "|")
63 | return
64 | if($pos mod 2)
65 | then { $bit }
66 | else { $bit }
67 |
68 | let $mode :=
69 | if(exists($key))
70 | then "json"
71 | else if(exists($element) and exists($attribute))
72 | then "xmlattribute"
73 | else "xmlelement"
74 |
75 | let $format := map:get($params, "format")
76 | let $firstFormat := map:get($params, "firstFormat")
77 | let $lastFormat := map:get($params, "lastFormat")
78 |
79 | let $bucketInterval := map:get($params, "bucketInterval")
80 | let $startingAt := map:get($params, "startingAt")
81 | let $stoppingAt := map:get($params, "stoppingAt")
82 | return
83 |
84 | if((empty($key) and empty($element)) or (exists($key) and exists($element)))
85 | then common:error("corona:MISSING-PARAMETER", "Must supply either a JSON key or XML element name", "json")
86 | else if(exists($attribute) and empty($element))
87 | then common:error("corona:MISSING-PARAMETER", "Must supply an XML element along with an XML attribute", "json")
88 | else if(exists($bucketInterval) and exists($startingAt) and $type = ("date", "dateTime"))
89 | then
90 | if(empty($firstFormat))
91 | then common:error("corona:MISSING-PARAMETER", "Must supply a firstFormat when creating a auto-bucketed range index", "json")
92 | else if(empty($format))
93 | then common:error("corona:MISSING-PARAMETER", "Must supply a format when creating a auto-bucketed range index", "json")
94 | else if(empty($lastFormat))
95 | then common:error("corona:MISSING-PARAMETER", "Must supply a lastFormat when creating a auto-bucketed range index", "json")
96 | else
97 |
98 | if($mode = "json")
99 | then manage:createJSONAutoBucketedRange($name, $key, $type, map:get($params, "collation"), $bucketInterval, $startingAt, $stoppingAt, $firstFormat, $format, $lastFormat, $config)
100 | else if($mode = "xmlattribute")
101 | then manage:createXMLAttributeAutoBucketedRange($name, $element, $attribute, $type, map:get($params, "collation"), $bucketInterval, $startingAt, $stoppingAt, $firstFormat, $format, $lastFormat, $config)
102 | else if($mode = "xmlelement")
103 | then manage:createXMLElementAutoBucketedRange($name, $element, $type, map:get($params, "collation"), $bucketInterval, $startingAt, $stoppingAt, $firstFormat, $format, $lastFormat, $config)
104 | else ()
105 | else if(exists($buckets))
106 | then
107 | if($mode = "json")
108 | then manage:createJSONBucketedRange($name, $key, $type, map:get($params, "collation"), $buckets, $config)
109 | else if($mode = "xmlattribute")
110 | then manage:createXMLAttributeBucketedRange($name, $element, $attribute, $type, map:get($params, "collation"), $buckets, $config)
111 | else if($mode = "xmlelement")
112 | then manage:createXMLElementBucketedRange($name, $element, $type, map:get($params, "collation"), $buckets, $config)
113 | else ()
114 | else common:error("corona:MISSING-PARAMETER", "Must supply either the bucket definitions or a bucket interval with a starting date", "json")
115 | else common:error("corona:MISSING-PARAMETER", "Must supply a name for the bucketed range", "json")
116 |
117 | else if($requestMethod = "DELETE")
118 | then
119 | if(string-length($name))
120 | then
121 | if(exists($existing))
122 | then manage:deleteBucketedRange($name, $config)
123 | else common:error("corona:RANGE-INDEX-NOT-FOUND", "Bucketed range index not found", "json")
124 | else manage:deleteAllBucketedRanges()
125 | else common:error("corona:UNSUPPORTED-METHOD", concat("Unsupported method: ", $requestMethod), "json")
126 | )
127 |
--------------------------------------------------------------------------------
/corona/manage/env.xqy:
--------------------------------------------------------------------------------
1 | (:
2 | Copyright 2011 Swell Lines LLC
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | :)
16 |
17 | xquery version "1.0-ml";
18 |
19 | import module namespace manage="http://marklogic.com/corona/manage" at "../lib/manage.xqy";
20 | import module namespace common="http://marklogic.com/corona/common" at "../lib/common.xqy";
21 | import module namespace json="http://marklogic.com/json" at "../lib/json.xqy";
22 |
23 | import module namespace rest="http://marklogic.com/appservices/rest" at "../lib/rest/rest.xqy";
24 | import module namespace endpoints="http://marklogic.com/corona/endpoints" at "/config/endpoints.xqy";
25 |
26 | declare option xdmp:mapping "false";
27 |
28 |
29 | let $params := rest:process-request(endpoints:request("/corona/manage/env.xqy"))
30 | let $requestMethod := xdmp:get-request-method()
31 | let $name := map:get($params, "name")
32 |
33 | return common:output(
34 | try {
35 | if($requestMethod = ("POST", "DELETE") and string-length($name) = 0)
36 | then common:error("corona:INVALID-PARAMETER", "Must specify an environment variable name")
37 |
38 | else if($requestMethod = "GET")
39 | then
40 | if(string-length($name))
41 | then json:object(($name, manage:getEnvVar($name)))
42 | else manage:getEnvVars()
43 | else if($requestMethod = "POST")
44 | then (
45 | xdmp:set-response-code(204, "Variable saved"),
46 | manage:setEnvVar($name, map:get($params, "value"))
47 | )
48 | else if($requestMethod = "DELETE")
49 | then manage:deleteEnvVar($name)
50 | else ()
51 | }
52 | catch ($e) {
53 | common:errorFromException($e, "json")
54 | }
55 | )
56 |
57 |
--------------------------------------------------------------------------------
/corona/manage/geo.xqy:
--------------------------------------------------------------------------------
1 | (:
2 | Copyright 2011 MarkLogic Corporation
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | :)
16 |
17 | xquery version "1.0-ml";
18 |
19 | import module namespace manage="http://marklogic.com/corona/manage" at "../lib/manage.xqy";
20 | import module namespace common="http://marklogic.com/corona/common" at "../lib/common.xqy";
21 | import module namespace json="http://marklogic.com/json" at "../lib/json.xqy";
22 |
23 | import module namespace rest="http://marklogic.com/appservices/rest" at "../lib/rest/rest.xqy";
24 | import module namespace endpoints="http://marklogic.com/corona/endpoints" at "/config/endpoints.xqy";
25 | import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy";
26 |
27 | declare option xdmp:mapping "false";
28 |
29 |
30 | let $params := rest:process-request(endpoints:request("/corona/manage/geo.xqy"))
31 | let $name := map:get($params, "name")
32 | let $requestMethod := xdmp:get-request-method()
33 |
34 | let $config := admin:get-configuration()
35 | let $existing := manage:getGeo($name)
36 |
37 | return common:output(
38 | if($requestMethod = "GET")
39 | then
40 | if(string-length($name))
41 | then
42 | if(exists($existing))
43 | then $existing
44 | else common:error("corona:GEO-INDEX-NOT-FOUND", "Geospatial index not found", "json")
45 | else json:array(manage:getAllGeos())
46 |
47 | else if($requestMethod = "POST")
48 | then
49 | if(string-length($name))
50 | then
51 | let $key := map:get($params, "key")
52 | let $element := map:get($params, "element")
53 | let $parentKey := map:get($params, "parentKey")
54 | let $parentElement := map:get($params, "parentElement")
55 | let $latKey := map:get($params, "latKey")
56 | let $longKey := map:get($params, "longKey")
57 | let $latElement := map:get($params, "latElement")
58 | let $longElement := map:get($params, "longElement")
59 | let $latAttribute := map:get($params, "latAttribute")
60 | let $longAttribute := map:get($params, "longAttribute")
61 | let $coordinateSystem := map:get($params, "coordinateSystem")
62 | let $comesFirst := map:get($params, "comesFirst")
63 | return
64 | try {
65 | if(exists($parentElement) and exists($latAttribute) and exists($longAttribute))
66 | then manage:createGeoWithAttributes($name, $parentElement, $latAttribute, $longAttribute, $coordinateSystem)
67 | else if(exists($parentElement) and exists($latElement) and exists($longElement))
68 | then manage:createGeoWithElementChildren($name, $parentElement, $latElement, $longElement, $coordinateSystem)
69 | else if(exists($parentKey) and exists($latKey) and exists($longKey))
70 | then manage:createGeoWithKeyChildren($name, $parentKey, $latKey, $longKey, $coordinateSystem)
71 | else if(exists($element) and exists($parentElement))
72 | then manage:createGeoWithElementChild($name, $parentElement, $element, $coordinateSystem, $comesFirst)
73 | else if(exists($key) and exists($parentKey))
74 | then manage:createGeoWithKeyChild($name, $parentKey, $key, $coordinateSystem, $comesFirst)
75 | else if(exists($element))
76 | then manage:createGeoWithElement($name, $element, $coordinateSystem, $comesFirst)
77 | else if(exists($key))
78 | then manage:createGeoWithKey($name, $key, $coordinateSystem, $comesFirst)
79 | else common:error("corona:INVALID-REQUEST", "Invalid geospatial index creation. Check documentaion for proper configuration.", "json")
80 | }
81 | catch ($e) {
82 | common:errorFromException($e, "json")
83 | }
84 | else common:error("corona:INVALID-PARAMETER", "Must specify a name for the geospatial index", "json")
85 |
86 | else if($requestMethod = "DELETE")
87 | then
88 | if(string-length($name))
89 | then
90 | if(exists($existing))
91 | then manage:deleteGeo($name, $config)
92 | else common:error("corona:GEO-INDEX-NOT-FOUND", "Geospatial index not found", "json")
93 | else manage:deleteAllGeos()
94 | else common:error("corona:UNSUPPORTED-METHOD", concat("Unsupported method: ", $requestMethod), "json")
95 | )
96 |
--------------------------------------------------------------------------------
/corona/manage/namedqueryprefix.xqy:
--------------------------------------------------------------------------------
1 | (:
2 | Copyright 2011 MarkLogic Corporation
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | :)
16 |
17 | xquery version "1.0-ml";
18 |
19 | import module namespace manage="http://marklogic.com/corona/manage" at "../lib/manage.xqy";
20 | import module namespace common="http://marklogic.com/corona/common" at "../lib/common.xqy";
21 | import module namespace json="http://marklogic.com/json" at "../lib/json.xqy";
22 |
23 | import module namespace rest="http://marklogic.com/appservices/rest" at "../lib/rest/rest.xqy";
24 | import module namespace endpoints="http://marklogic.com/corona/endpoints" at "/config/endpoints.xqy";
25 |
26 | declare option xdmp:mapping "false";
27 |
28 |
29 | let $params := rest:process-request(endpoints:request("/corona/manage/namedqueryprefix.xqy"))
30 | let $prefix := map:get($params, "prefix")
31 | let $requestMethod := xdmp:get-request-method()
32 | let $set := xdmp:set-response-code(if($requestMethod = "GET") then 200 else 204, "Named query prefix")
33 |
34 | return common:output(
35 | if($requestMethod = "GET")
36 | then
37 | if(string-length($prefix))
38 | then
39 | if(manage:namedQueryPrefixExists($prefix))
40 | then json:object(("exists", true()))
41 | else common:error("corona:NAMED-QUERY-PREFIX-NOT-FOUND", "Named query prefix not found", "json")
42 | else json:array(manage:getNamedQueryPrefixes())
43 |
44 | else if($requestMethod = "POST")
45 | then
46 | if(string-length($prefix))
47 | then
48 | if(not(matches($prefix, "^[A-Za-z_][A-Za-z0-9]*$")))
49 | then common:error("corona:INVALID-PARAMETER", "Invalid named query prefix", "json")
50 | else manage:addNamedQueryPrefix($prefix)
51 | else common:error("corona:INVALID-PARAMETER", "Must specify a named query prefix", "json")
52 |
53 | else if($requestMethod = "DELETE")
54 | then
55 | if(string-length($prefix))
56 | then
57 | if(manage:namedQueryPrefixExists($prefix))
58 | then manage:removeNamedQueryPrefix($prefix)
59 | else common:error("corona:NAMED-QUERY-PREFIX-NOT-FOUND", "Named query prefix not found", "json")
60 | else common:error("corona:INVALID-PARAMETER", "Must specify a named query prefix", "json")
61 | else common:error("corona:UNSUPPORTED-METHOD", concat("Unsupported method: ", $requestMethod), "json")
62 | )
63 |
--------------------------------------------------------------------------------
/corona/manage/namespace.xqy:
--------------------------------------------------------------------------------
1 | (:
2 | Copyright 2011 MarkLogic Corporation
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | :)
16 |
17 | xquery version "1.0-ml";
18 |
19 | import module namespace manage="http://marklogic.com/corona/manage" at "../lib/manage.xqy";
20 | import module namespace common="http://marklogic.com/corona/common" at "../lib/common.xqy";
21 | import module namespace json="http://marklogic.com/json" at "../lib/json.xqy";
22 |
23 | import module namespace rest="http://marklogic.com/appservices/rest" at "../lib/rest/rest.xqy";
24 | import module namespace endpoints="http://marklogic.com/corona/endpoints" at "/config/endpoints.xqy";
25 |
26 | declare option xdmp:mapping "false";
27 |
28 |
29 | let $params := rest:process-request(endpoints:request("/corona/manage/namespace.xqy"))
30 | let $prefix := map:get($params, "prefix")
31 | let $uri := map:get($params, "uri")
32 | let $requestMethod := xdmp:get-request-method()
33 |
34 | let $existing := manage:getNamespaceURI($prefix)
35 |
36 | return common:output(
37 | if($requestMethod = "GET")
38 | then
39 | if(string-length($prefix))
40 | then
41 | if(exists($existing))
42 | then $existing
43 | else common:error("corona:NAMESPACE-NOT-FOUND", "Namespace not found", "json")
44 | else json:array(manage:getAllNamespaces())
45 |
46 | else if($requestMethod = "POST")
47 | then
48 | if(string-length($prefix))
49 | then
50 | if(not(matches($prefix, "^[A-Za-z_][A-Za-z0-9_\.]*$")))
51 | then common:error("corona:INVALID-PARAMETER", "Invalid namespace prefix", "json")
52 | else manage:setNamespaceURI($prefix, $uri)
53 | else common:error("corona:INVALID-PARAMETER", "Must specify a prefix for the namespace", "json")
54 |
55 | else if($requestMethod = "DELETE")
56 | then
57 | if(string-length($prefix))
58 | then
59 | if(exists($existing))
60 | then manage:deleteNamespace($prefix)
61 | else common:error("common:NAMESPACE-NOT-FOUND", "Namespace not found", "json")
62 | else manage:deleteAllNamespaces()
63 | else common:error("corona:UNSUPPORTED-METHOD", concat("Unsupported method: ", $requestMethod), "json")
64 | )
65 |
--------------------------------------------------------------------------------
/corona/manage/places.xqy:
--------------------------------------------------------------------------------
1 | (:
2 | Copyright 2011 MarkLogic Corporation
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | :)
16 |
17 | xquery version "1.0-ml";
18 |
19 | import module namespace manage="http://marklogic.com/corona/manage" at "../lib/manage.xqy";
20 | import module namespace common="http://marklogic.com/corona/common" at "../lib/common.xqy";
21 | import module namespace json="http://marklogic.com/json" at "../lib/json.xqy";
22 |
23 | import module namespace rest="http://marklogic.com/appservices/rest" at "../lib/rest/rest.xqy";
24 | import module namespace endpoints="http://marklogic.com/corona/endpoints" at "/config/endpoints.xqy";
25 |
26 | declare namespace corona="http://marklogic.com/corona";
27 |
28 | declare option xdmp:mapping "false";
29 |
30 |
31 | let $params := rest:process-request(endpoints:request("/corona/manage/places.xqy"))
32 | let $requestMethod := xdmp:get-request-method()
33 | let $scope := map:get($params, "scope")
34 | let $name := map:get($params, "name")
35 | let $mode := map:get($params, "mode")
36 |
37 | let $key := map:get($params, "key")
38 | let $element := map:get($params, "element")
39 | let $attribute := map:get($params, "attribute")
40 | let $subPlace := map:get($params, "place")
41 | let $type := map:get($params, "type")
42 | let $weight := map:get($params, "weight")
43 |
44 | let $name := if(string-length($name)) then $name else ()
45 | let $scope := if(starts-with($scope, "places")) then "places" else "place"
46 |
47 | let $output :=
48 | try {
49 | if($requestMethod = "GET")
50 | then
51 | if($scope = "place" and empty($name))
52 | then manage:getPlace(())
53 | else if($scope = "places" and empty($name))
54 | then json:array(manage:getAllPlaces())
55 | else if(exists($name))
56 | then manage:getPlace($name)
57 | else common:error("corona:INVALID-REQUEST", "Must supply a place name, request all the places or the anonymous place", "json")
58 |
59 | else if($requestMethod = "PUT")
60 | then
61 | if($scope = "place" and exists($name))
62 | then manage:createPlace($name, $mode, map:get($params, "option"))
63 | else if($scope = "places")
64 | then common:error("corona:INVALID-REQUEST", "Can not create a new place under /manage/places, use /manage/place instead", "json")
65 | else ()
66 |
67 | else if($requestMethod = "POST")
68 | then
69 | if(exists($key))
70 | then manage:addKeyToPlace($name, $key, $type, $weight)
71 | else if(exists($element) and exists($attribute))
72 | then manage:addAttributeToPlace($name, $element, $attribute, $weight)
73 | else if(exists($element))
74 | then manage:addElementToPlace($name, $element, $type, $weight)
75 | else if(exists($subPlace))
76 | then manage:addPlaceToPlace($name, $subPlace)
77 | else common:error("corona:INVALID-REQUEST", "Must specify a key, element, element/attribute pair, or a sub-place to add to the place", "json")
78 |
79 | else if($requestMethod = "DELETE")
80 | then
81 | if(exists($key))
82 | then manage:removeKeyFromPlace($name, $key, $type)
83 | else if(exists($element) and exists($attribute))
84 | then manage:removeAttributeFromPlace($name, $element, $attribute)
85 | else if(exists($element))
86 | then manage:removeElementFromPlace($name, $element, $type)
87 | else if(exists($subPlace))
88 | then manage:removePlaceFromPlace($name, $subPlace)
89 | else if(empty(($key, $element, $attribute, $subPlace)) and $scope = "place" and exists($name))
90 | then manage:deletePlace($name)
91 | else if(empty(($key, $element, $attribute, $subPlace, $name)) and $scope = "places")
92 | then manage:deleteAllPlaces()
93 | else common:error("corona:INVALID-REQUEST", "Must specify a key, element, element/attribute pair or a sub-place to remove from the place. Or simply specify the place to delete it's entire configuration.", "json")
94 | else common:error("corona:UNSUPPORTED-METHOD", concat("Unsupported method: ", $requestMethod), "json")
95 | }
96 | catch ($e) {
97 | common:errorFromException($e, "json")
98 | }
99 | return
100 | if(empty($output))
101 | then xdmp:set-response-code(204, "Request successful")
102 | else common:output($output)
103 |
--------------------------------------------------------------------------------
/corona/manage/range.xqy:
--------------------------------------------------------------------------------
1 | (:
2 | Copyright 2011 MarkLogic Corporation
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | :)
16 |
17 | xquery version "1.0-ml";
18 |
19 | import module namespace manage="http://marklogic.com/corona/manage" at "../lib/manage.xqy";
20 | import module namespace common="http://marklogic.com/corona/common" at "../lib/common.xqy";
21 | import module namespace json="http://marklogic.com/json" at "../lib/json.xqy";
22 |
23 | import module namespace rest="http://marklogic.com/appservices/rest" at "../lib/rest/rest.xqy";
24 | import module namespace endpoints="http://marklogic.com/corona/endpoints" at "/config/endpoints.xqy";
25 | import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy";
26 |
27 | declare option xdmp:mapping "false";
28 |
29 |
30 | let $params := rest:process-request(endpoints:request("/corona/manage/range.xqy"))
31 | let $name := map:get($params, "name")
32 | let $requestMethod := xdmp:get-request-method()
33 |
34 | let $config := admin:get-configuration()
35 | let $existing := manage:getRange($name)
36 |
37 | return common:output(
38 | if($requestMethod = "GET")
39 | then
40 | if(string-length($name))
41 | then
42 | if(exists($existing))
43 | then $existing
44 | else common:error("corona:RANGE-INDEX-NOT-FOUND", "Range index not found", "json")
45 | else json:array(manage:getAllRanges())
46 |
47 | else if($requestMethod = "POST")
48 | then
49 | if(string-length($name))
50 | then
51 | let $key := map:get($params, "key")
52 | let $element := map:get($params, "element")
53 | let $attribute := map:get($params, "attribute")
54 | let $type := map:get($params, "type")
55 | return
56 |
57 | if((empty($key) and empty($element)) or (exists($key) and exists($element)))
58 | then common:error("corona:MISSING-PARAMETER", "Must supply either a JSON key, an XML element name or XML element and attribute names", "json")
59 | else if(exists($attribute) and empty($element))
60 | then common:error("corona:MISSING-PARAMETER", "Must supply an XML element along with an XML attribute", "json")
61 | else
62 | try {
63 | if(exists($key))
64 | then manage:createJSONRange($name, $key, $type, map:get($params, "collation"), $config)
65 | else if(exists($element) and exists($attribute))
66 | then manage:createXMLAttributeRange($name, $element, $attribute, $type, map:get($params, "collation"), $config)
67 | else if(exists($element) and empty($attribute))
68 | then manage:createXMLElementRange($name, $element, $type, map:get($params, "collation"), $config)
69 | else ()
70 | }
71 | catch ($e) {
72 | common:errorFromException($e, "json")
73 | }
74 | else common:error("corona:INVALID-PARAMETER", "Must specify a name for the range", "json")
75 |
76 | else if($requestMethod = "DELETE")
77 | then
78 | if(string-length($name))
79 | then
80 | if(exists($existing))
81 | then manage:deleteRange($name, $config)
82 | else common:error("corona:RANGE-INDEX-NOT-FOUND", "Range index not found", "json")
83 | else manage:deleteAllRanges()
84 | else common:error("corona:UNSUPPORTED-METHOD", concat("Unsupported method: ", $requestMethod), "json")
85 | )
86 |
--------------------------------------------------------------------------------
/corona/manage/schemas.xqy:
--------------------------------------------------------------------------------
1 | (:
2 | Copyright 2011 MarkLogic Corporation
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | :)
16 |
17 | xquery version "1.0-ml";
18 |
19 | import module namespace manage="http://marklogic.com/corona/manage" at "../lib/manage.xqy";
20 | import module namespace common="http://marklogic.com/corona/common" at "../lib/common.xqy";
21 | import module namespace json="http://marklogic.com/json" at "../lib/json.xqy";
22 |
23 | import module namespace rest="http://marklogic.com/appservices/rest" at "../lib/rest/rest.xqy";
24 | import module namespace endpoints="http://marklogic.com/corona/endpoints" at "/config/endpoints.xqy";
25 |
26 | declare option xdmp:mapping "false";
27 |
28 |
29 | let $params := rest:process-request(endpoints:request("/corona/manage/schemas.xqy"))
30 | let $requestMethod := xdmp:get-request-method()
31 | let $uri := map:get($params, "uri")
32 | let $schemaContent := xdmp:get-request-body("xml")/xs:schema
33 |
34 | return common:output(
35 | if($requestMethod = "GET")
36 | then
37 | if(string-length($uri))
38 | then
39 | let $existing := manage:getSchema($uri)
40 | return
41 | if(exists($existing))
42 | then $existing
43 | else common:error("corona:SCHEMA-NOT-FOUND", "Schema not found", "json")
44 | else json:array(manage:getAllSchemaURIs())
45 |
46 | else if($requestMethod = "PUT")
47 | then
48 | if(string-length($uri))
49 | then
50 | try {
51 | manage:setSchema($uri, $schemaContent)
52 | }
53 | catch ($e) {
54 | common:errorFromException($e, "xml")
55 | }
56 | else common:error("corona:INVALID-PARAMETER", "Must specify a URI for the schema", "json")
57 |
58 | else if($requestMethod = "DELETE")
59 | then
60 | if(string-length($uri))
61 | then
62 | let $existing := manage:getSchema($uri)
63 | return
64 | if(exists($existing))
65 | then manage:deleteSchema($uri)
66 | else common:error("corona:SCHEMA-NOT-FOUND", "Schema not found", "json")
67 | else manage:deleteAllSchemas()
68 | else common:error("corona:UNSUPPORTED-METHOD", concat("Unsupported method: ", $requestMethod), "json")
69 | )
70 |
--------------------------------------------------------------------------------
/corona/manage/summary.xqy:
--------------------------------------------------------------------------------
1 | (:
2 | Copyright 2011 MarkLogic Corporation
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | :)
16 |
17 | xquery version "1.0-ml";
18 |
19 | import module namespace json="http://marklogic.com/json" at "../lib/json.xqy";
20 | import module namespace pathparser="http://marklogic.com/mljson/path-parser" at "../lib/path-parser.xqy";
21 | import module namespace dateparser="http://marklogic.com/dateparser" at "../lib/date-parser.xqy";
22 | import module namespace common="http://marklogic.com/corona/common" at "../lib/common.xqy";
23 | import module namespace manage="http://marklogic.com/corona/manage" at "../lib/manage.xqy";
24 | import module namespace const="http://marklogic.com/corona/constants" at "../lib/constants.xqy";
25 | import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy";
26 |
27 | declare option xdmp:mapping "false";
28 |
29 | let $config := admin:get-configuration()
30 | let $database := xdmp:database()
31 |
32 | let $requestMethod := xdmp:get-request-method()
33 | let $numJSONDocs := xdmp:estimate(/json:json)
34 | let $numTextDocs := xdmp:estimate(doc()/text())
35 | let $numBinaryDocs := xdmp:estimate(doc()/binary())
36 | let $numXMLDocs := xdmp:estimate(/*) - $numJSONDocs
37 |
38 | return common:output(
39 | if($requestMethod = "GET")
40 | then json:document(
41 | json:object((
42 | "isManaged", manage:isManaged(),
43 | "defaultOutputFormat", manage:defaultOutputFormat(),
44 | "insertTransformsEnabled", manage:insertTransformsEnabled(),
45 | "fetchTransformsEnabled", manage:fetchTransformsEnabled(),
46 | "debugLogging", manage:getDebugLogging(),
47 | "features", json:object((
48 | "JSONDocs", json:isSupported(),
49 | "JSONPath", pathparser:supportedFormats() = "json",
50 | "dateParsing", dateparser:isSupported(),
51 | "simplifiedXPath", pathparser:supportedFormats() = "xpath"
52 | )),
53 | "libraryVersion", $const:version,
54 | "serverVersion", xdmp:version(),
55 | "architecture", xdmp:architecture(),
56 | "platform", xdmp:platform(),
57 | "hosts", json:array((
58 | for $host in xdmp:hosts()
59 | return json:object((
60 | "id", $host,
61 | "name", xdmp:host-name($host)
62 | ))
63 | )),
64 | "env", manage:getEnvVars(),
65 | "indexes", json:object((
66 | "stemming", admin:database-get-stemmed-searches($config, $database),
67 | "uris", admin:database-get-uri-lexicon($config, $database),
68 | "collectionLexicon", admin:database-get-collection-lexicon($config, $database),
69 | "caseSensitive", admin:database-get-fast-case-sensitive-searches($config, $database),
70 | "diacriticSensitive", admin:database-get-fast-diacritic-sensitive-searches($config, $database),
71 | "keyValueCharacters", admin:database-get-fast-element-character-searches($config, $database),
72 | "keyValueWords", admin:database-get-fast-element-word-searches($config, $database),
73 | "keyValuePhrases", admin:database-get-fast-element-phrase-searches($config, $database),
74 | "keyValueTrailingWildcards", admin:database-get-fast-element-trailing-wildcard-searches($config, $database),
75 | "ranges", json:array(manage:getAllRanges()),
76 | "bucketedRanges", json:array(manage:getAllBucketedRanges()),
77 | "places", json:array(manage:getAllPlaces()),
78 | "geo", json:array(manage:getAllGeos()),
79 | "anonymousPlace", manage:getPlace(())
80 | )),
81 | "transformers", json:array(manage:getAllTransformerNames()),
82 | "namedQueryPrefixes", json:array(manage:getNamedQueryPrefixes()),
83 | "statistics", json:object((
84 | "XMLDocumentCount", $numXMLDocs,
85 | "JSONDocumentCount", $numJSONDocs,
86 | "TextDocumentCount", $numTextDocs,
87 | "BinaryDocumentCount", $numBinaryDocs
88 | )),
89 | "xmlNamespaces", json:array(manage:getAllNamespaces()),
90 | "xmlSchemas", json:array(manage:getAllSchemaURIs())
91 | ))
92 | )
93 | else if($requestMethod = "DELETE")
94 | then (
95 | manage:deleteAllRanges(),
96 | manage:deleteAllBucketedRanges(),
97 | manage:deleteAllPlaces(),
98 | manage:deleteAllGeos(),
99 | manage:deleteAllTransformers(),
100 | manage:deleteAllNamespaces(),
101 | manage:deleteAllSchemas()
102 | )
103 | else ()
104 | )
105 |
--------------------------------------------------------------------------------
/corona/manage/transformer.xqy:
--------------------------------------------------------------------------------
1 | (:
2 | Copyright 2011 MarkLogic Corporation
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | :)
16 |
17 | xquery version "1.0-ml";
18 |
19 | import module namespace manage="http://marklogic.com/corona/manage" at "../lib/manage.xqy";
20 | import module namespace common="http://marklogic.com/corona/common" at "../lib/common.xqy";
21 | import module namespace json="http://marklogic.com/json" at "../lib/json.xqy";
22 |
23 | import module namespace rest="http://marklogic.com/appservices/rest" at "../lib/rest/rest.xqy";
24 | import module namespace endpoints="http://marklogic.com/corona/endpoints" at "/config/endpoints.xqy";
25 |
26 | declare option xdmp:mapping "false";
27 |
28 |
29 | let $params := rest:process-request(endpoints:request("/corona/manage/transformer.xqy"))
30 | let $requestMethod := xdmp:get-request-method()
31 | let $name := map:get($params, "name")
32 | let $bodyContent := xdmp:get-request-body("text")/text()
33 |
34 | let $existing := manage:getTransformer($name)
35 |
36 | return common:output(
37 | if($requestMethod = "GET")
38 | then
39 | if(string-length($name))
40 | then
41 | if(exists($existing))
42 | then $existing
43 | else common:error("corona:TRANSFORMER-NOT-FOUND", "Transformer not found", "json")
44 | else json:array(manage:getAllTransformerNames())
45 |
46 | else if($requestMethod = "PUT")
47 | then
48 | if(string-length($name))
49 | then
50 | try {
51 | manage:setTransformer($name, $bodyContent)
52 | }
53 | catch ($e) {
54 | common:errorFromException($e, "xml")
55 | }
56 | else common:error("corona:INVALID-PARAMETER", "Must specify a name for the transformer", "json")
57 |
58 | else if($requestMethod = "DELETE")
59 | then
60 | if(string-length($name))
61 | then
62 | if(exists($existing))
63 | then manage:deleteTransformer($name)
64 | else common:error("corona:TRANSFORMER-NOT-FOUND", "Transformer not found", "json")
65 | else manage:deleteAllTransformers()
66 | else common:error("corona:UNSUPPORTED-METHOD", concat("Unsupported method: ", $requestMethod), "json")
67 | )
68 |
--------------------------------------------------------------------------------
/corona/misc/404.xqy:
--------------------------------------------------------------------------------
1 | (:
2 | Copyright 2011 MarkLogic Corporation
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | :)
16 |
17 | xquery version "1.0-ml";
18 |
19 | import module namespace common="http://marklogic.com/corona/common" at "../lib/common.xqy";
20 |
21 | common:output(common:error("corona:ENDPOINT-NOT-FOUND", "Invalid endpoint. Check path and parameters for errors.", xdmp:get-request-field("outputFormat")))
22 |
--------------------------------------------------------------------------------
/corona/named-query.xqy:
--------------------------------------------------------------------------------
1 | (:
2 | Copyright 2011 MarkLogic Corporation
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | :)
16 |
17 | xquery version "1.0-ml";
18 |
19 | import module namespace common="http://marklogic.com/corona/common" at "lib/common.xqy";
20 | import module namespace search="http://marklogic.com/corona/search" at "lib/search.xqy";
21 | import module namespace const="http://marklogic.com/corona/constants" at "lib/constants.xqy";
22 | import module namespace json="http://marklogic.com/json" at "lib/json.xqy";
23 |
24 | import module namespace rest="http://marklogic.com/appservices/rest" at "lib/rest/rest.xqy";
25 | import module namespace endpoints="http://marklogic.com/corona/endpoints" at "/config/endpoints.xqy";
26 |
27 | declare namespace corona="http://marklogic.com/corona";
28 | declare namespace hs="http://marklogic.com/xdmp/status/host";
29 |
30 | declare option xdmp:mapping "false";
31 |
32 |
33 | let $params := rest:process-request(endpoints:request("/corona/named-query.xqy"))
34 |
35 | let $requestMethod := xdmp:get-request-method()
36 | let $name := map:get($params, "name")
37 | let $collections := map:get($params, "collection")
38 | let $properties := map:get($params, "property")
39 | let $matchingDocs := map:get($params, "matchingDoc")
40 | let $stringQuery := map:get($params, "stringQuery")
41 | let $structuredQuery := map:get($params, "structuredQuery")
42 | let $outputFormat := common:getOutputFormat((), map:get($params, "outputFormat"))
43 |
44 | let $errors := (
45 | if($requestMethod = "GET" and exists($matchingDocs) and exists(($name, $properties, $collections)))
46 | then common:error("corona:INVALID-PARAMETER", "When supplying a matching document, requests can not contain name, property or collection parameters", $outputFormat)
47 | else (),
48 | if($requestMethod = "POST" and empty(($stringQuery, $structuredQuery)))
49 | then common:error("corona:MISSING-PARAMETER", "Must supply a string or structured query when creating a stored query", $outputFormat)
50 | else (),
51 | if($requestMethod = "POST" and empty($name))
52 | then common:error("corona:MISSING-PARAMETER", "Must supply a name when creating a stored query", $outputFormat)
53 | else (),
54 | if($requestMethod = "DELETE" and empty($name))
55 | then common:error("corona:MISSING-PARAMETER", "Must supply a name when deleting a stored query", $outputFormat)
56 | else ()
57 | )
58 |
59 |
60 | return common:output(
61 | if(exists($errors))
62 | then $errors
63 | else
64 |
65 | if($requestMethod = "POST")
66 | then try {(
67 | xdmp:set-response-code(204, "Query inserted"),
68 | if(exists($stringQuery))
69 | then search:saveStringQuery($name, map:get($params, "description"), $stringQuery, $collections, common:processPropertiesParameter($properties), common:processPermissionParameter(map:get($params, "permission")))
70 | else if(exists($structuredQuery))
71 | then search:saveStructuredQuery($name, map:get($params, "description"), $structuredQuery, $collections, common:processPropertiesParameter($properties), common:processPermissionParameter(map:get($params, "permission")))
72 | else ()
73 | )}
74 | catch ($e) {
75 | common:errorFromException($e, $outputFormat)
76 | }
77 |
78 | else if($requestMethod = "GET")
79 | then try {
80 | let $start := map:get($params, "start")
81 | let $length := map:get($params, "length")
82 | let $value := map:get($params, "value")
83 |
84 | let $query := cts:and-query((
85 | cts:collection-query($const:StoredQueriesCollection),
86 |
87 | if(exists(map:get($params, "prefix")))
88 | then cts:element-attribute-value-query(xs:QName("corona:storedQuery"), xs:QName("prefix"), map:get($params, "prefix"), "exact")
89 | else (),
90 |
91 | if(string-length($name) > 0)
92 | then cts:element-attribute-value-query(xs:QName("corona:storedQuery"), xs:QName("name"), $name, "exact")
93 | else (),
94 |
95 | if(exists($properties))
96 | then cts:properties-query(cts:element-value-query(QName("http://marklogic.com/corona", $properties), $value, "exact"))
97 | else (),
98 |
99 | for $collection in $collections
100 | return cts:collection-query($collection),
101 |
102 | for $matchingDoc in $matchingDocs
103 | return cts:reverse-query(doc($matchingDoc))
104 | ))
105 |
106 | let $log := common:log("Named Query", "Fetching with", $query)
107 |
108 | let $end := $start + $length - 1
109 | let $results := cts:search(/corona:storedQuery, $query)[$start to $end]
110 |
111 | let $total :=
112 | if(exists($results[1]))
113 | then cts:remainder($results[1]) + $start - 1
114 | else 0
115 |
116 | let $start :=
117 | if($total = 0)
118 | then 0
119 | else $start
120 | let $end :=
121 | if($end > $total)
122 | then $total
123 | else $end
124 |
125 | let $executionTime := substring(string(xdmp:query-meters()/*:elapsed-time), 3, 4)
126 | return
127 | if($outputFormat = "json")
128 | then json:object((
129 | "meta", json:object((
130 | "start", $start,
131 | "end", $end,
132 | "total", $total,
133 | "executionTime", $executionTime
134 | )),
135 | "results", json:array((
136 | for $result in $results
137 | return json:object((
138 | if(exists($result/@prefix)) then ("prefix", string($result/@prefix)) else (),
139 | "name", string($result/@name),
140 | "description", string($result/@description),
141 | "queryType", string($result/@type),
142 | "query", $result/corona:original/node()
143 | ))
144 | ))
145 | ))
146 | else if($outputFormat = "xml")
147 | then
148 |
149 | { $start }
150 | { $end }
151 | { $total }
152 | { $executionTime }
153 |
154 | {
155 | for $result in $results
156 | return
157 | { if(exists($result/@prefix)) then { string($result/@prefix) } else () }
158 | { string($result/@name) }
159 | { string($result/@description) }
160 | { string($result/@type) }
161 | { $result/corona:original/node() }
162 |
163 | }
164 |
165 | else ()
166 | }
167 | catch ($e) {
168 | common:errorFromException($e, $outputFormat)
169 | }
170 |
171 | else if($requestMethod = "DELETE")
172 | then try {
173 | search:deleteStoredQuery($name)
174 | }
175 | catch ($e) {
176 | common:errorFromException($e, $outputFormat)
177 | }
178 |
179 | else common:error("corona:UNSUPPORTED-METHOD", concat("Unsupported method: ", $requestMethod), $outputFormat)
180 | )
181 |
--------------------------------------------------------------------------------
/corona/search.xqy:
--------------------------------------------------------------------------------
1 | (:
2 | Copyright 2011 MarkLogic Corporation
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | :)
16 |
17 | xquery version "1.0-ml";
18 |
19 | import module namespace common="http://marklogic.com/corona/common" at "lib/common.xqy";
20 | import module namespace manage="http://marklogic.com/corona/manage" at "lib/manage.xqy";
21 | import module namespace const="http://marklogic.com/corona/constants" at "lib/constants.xqy";
22 | import module namespace stringquery="http://marklogic.com/corona/string-query" at "lib/string-query.xqy";
23 | import module namespace structquery="http://marklogic.com/corona/structured-query" at "lib/structured-query.xqy";
24 | import module namespace store="http://marklogic.com/corona/store" at "lib/store.xqy";
25 | import module namespace config="http://marklogic.com/corona/index-config" at "lib/index-config.xqy";
26 |
27 | import module namespace rest="http://marklogic.com/appservices/rest" at "lib/rest/rest.xqy";
28 | import module namespace endpoints="http://marklogic.com/corona/endpoints" at "/config/endpoints.xqy";
29 |
30 | declare option xdmp:mapping "false";
31 |
32 | let $params := rest:process-request(endpoints:request("/corona/search.xqy"))
33 |
34 | let $stringQuery := map:get($params, "stringQuery")
35 | let $structuredQuery := map:get($params, "structuredQuery")
36 | let $include := map:get($params, "include")
37 | let $filtered := map:get($params, "filtered")
38 | let $extractPath := map:get($params, "extractPath")
39 | let $applyTransform := map:get($params, "applyTransform")
40 | let $start := map:get($params, "start")
41 | let $length := map:get($params, "length")
42 | let $txid := map:get($params, "txid")
43 |
44 | let $outputFormat := common:getOutputFormat((), map:get($params, "outputFormat"))
45 |
46 | let $errors := (
47 | if(empty(($stringQuery, $structuredQuery)) or (exists($structuredQuery) and string-length(normalize-space($structuredQuery)) = 0))
48 | then common:error("corona:MISSING-PARAMETER", "Must supply a string query or a structured query", $outputFormat)
49 | else ()
50 | )
51 |
52 | let $structuredQueryJSON :=
53 | if(exists($structuredQuery))
54 | then
55 | try {
56 | structquery:getParseTree($structuredQuery)
57 | }
58 | catch ($e) {
59 | xdmp:set($errors, common:error("corona:INVALID-PARAMETER", concat("The structured query JSON isn't valid: ", $e/*:message), $outputFormat))
60 | }
61 | else ()
62 | return
63 | if(exists($errors))
64 | then $errors
65 | else if(not(common:transactionsMatch($txid)))
66 | then xdmp:invoke("/corona/search.xqy", (), { map:get(common:processTXID($txid, true()), "id") } )
67 | else
68 |
69 | let $query :=
70 | if(exists($stringQuery))
71 | then stringquery:parse($stringQuery, map:get($params, "language"))
72 | else if(exists($structuredQuery))
73 | then structquery:getCTS($structuredQueryJSON)
74 | else ()
75 |
76 | let $query := cts:and-query((
77 | $query,
78 | for $collection in map:get($params, "collection")
79 | return cts:collection-query($collection),
80 | for $directory in map:get($params, "underDirectory")
81 | let $directory :=
82 | if(ends-with($directory, "/"))
83 | then $directory
84 | else concat($directory, "/")
85 | return cts:directory-query($directory, "infinity"),
86 | for $directory in map:get($params, "inDirectory")
87 | let $directory :=
88 | if(ends-with($directory, "/"))
89 | then $directory
90 | else concat($directory, "/")
91 | return cts:directory-query($directory)
92 | ))
93 |
94 | let $log := common:log("Search", "Generated query", $query)
95 |
96 | let $options :=
97 | if($filtered)
98 | then "filtered"
99 | else "unfiltered"
100 |
101 | let $log := common:log("Search", "Search options", $options)
102 |
103 | let $end := $start + $length - 1
104 |
105 | let $orderBy := map:get($params, "orderBy")
106 | let $orderDirection := map:get($params, "orderDirection")
107 | let $orderPath :=
108 | if(empty($orderBy))
109 | then ()
110 | else config:rangePath($orderBy)
111 | let $results :=
112 | if(empty($orderBy) or empty($orderPath))
113 | then cts:search(doc(), $query, $options, map:get($params, "qualityWeight"))[$start to $end]
114 | else
115 | if($orderDirection = "ascending")
116 | then (
117 | for $result in cts:search(doc(), $query, $options, map:get($params, "qualityWeight"))
118 | order by $result//xdmp:unpath($orderPath) ascending
119 | return $result
120 | )[$start to $end]
121 | else (
122 | for $result in cts:search(doc(), $query, $options, map:get($params, "qualityWeight"))
123 | order by $result//xdmp:unpath($orderPath) descending
124 | return $result
125 | )[$start to $end]
126 |
127 | let $total :=
128 | if(exists($results[1]))
129 | then cts:remainder($results[1]) + $start - 1
130 | else 0
131 |
132 | let $end :=
133 | if($end > $total)
134 | then $total
135 | else $end
136 |
137 | let $highlightQuery :=
138 | if(exists($structuredQueryJSON) and structquery:containsNamedQuery($structuredQueryJSON))
139 | then structquery:getCTS($structuredQueryJSON, (), false())
140 | else if(exists($stringQuery) and stringquery:containsNamedQuery($stringQuery))
141 | then stringquery:parse($stringQuery, map:get($params, "language"), (), false())
142 | else $query
143 |
144 | let $results :=
145 | try {
146 | store:outputMultipleDocuments($results, $start, $end, $total, $include, $query, $extractPath, $applyTransform, $params, $outputFormat)
147 | }
148 | catch ($e) {
149 | xdmp:set($errors, common:errorFromException($e, $outputFormat))
150 | }
151 |
152 | return common:output(($errors, $results)[1])
153 |
--------------------------------------------------------------------------------
/corona/store-get.xqy:
--------------------------------------------------------------------------------
1 | (:
2 | Copyright 2011 MarkLogic Corporation
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | :)
16 |
17 | xquery version "1.0-ml";
18 |
19 | import module namespace common="http://marklogic.com/corona/common" at "lib/common.xqy";
20 | import module namespace json="http://marklogic.com/json" at "lib/json.xqy";
21 | import module namespace stringquery="http://marklogic.com/corona/string-query" at "lib/string-query.xqy";
22 | import module namespace structquery="http://marklogic.com/corona/structured-query" at "lib/structured-query.xqy";
23 | import module namespace store="http://marklogic.com/corona/store" at "lib/store.xqy";
24 | import module namespace rest="http://marklogic.com/appservices/rest" at "lib/rest/rest.xqy";
25 |
26 | import module namespace endpoints="http://marklogic.com/corona/endpoints" at "/config/endpoints.xqy";
27 |
28 | declare namespace corona="http://marklogic.com/corona";
29 |
30 | declare option xdmp:mapping "false";
31 |
32 |
33 | declare function local:queryFromRequest(
34 | $params as map:map
35 | ) as cts:query?
36 | {
37 | let $structuredQuery :=
38 | try {
39 | structquery:getParseTree(map:get($params, "structuredQuery"))
40 | }
41 | catch ($e) {
42 | error(xs:QName("corona:INVALID-PARAMETER"), concat("The structured query JSON isn't valid: ", $e/*:message))
43 | }
44 | let $stringQuery :=
45 | try {
46 | stringquery:parse(map:get($params, "stringQuery"), (), (), false())
47 | }
48 | catch ($e) {
49 | error(xs:QName("corona:INVALID-PARAMETER"), concat("The string query isn't valid: ", $e/*:message))
50 | }
51 | return ($stringQuery, structquery:getCTS($structuredQuery, (), false()))[1]
52 | };
53 |
54 | let $requestMethod := xdmp:get-request-method()
55 | let $params := rest:process-request(endpoints:request("/corona/store-get.xqy"))
56 | let $uri := map:get($params, "uri")
57 | let $outputFormat := common:getOutputFormat((), map:get($params, "outputFormat"))
58 |
59 | let $doc := doc($uri)
60 | let $errors :=
61 | if($requestMethod = ("GET") and string-length($uri) = 0)
62 | then common:error("corona:MISSING-PARAMETER", "Must supply a URI when inserting, updating or fetching a document", $outputFormat)
63 | else if(empty($doc))
64 | then common:error("corona:DOCUMENT-NOT-FOUND", concat("There is no document at '", $uri, "'"), $outputFormat)
65 | else if(not(common:validateOutputFormat($outputFormat)))
66 | then common:error("corona:INVALID-OUTPUT-FORMAT", concat("The output format '", $outputFormat, "' isn't valid"))
67 | else ()
68 |
69 | let $include := map:get($params, "include")
70 | let $content :=
71 | if($requestMethod = "GET" and string-length($uri))
72 | then try {
73 | let $extractPath := map:get($params, "extractPath")
74 | let $applyTransform := map:get($params, "applyTransform")
75 | where empty($errors)
76 | return
77 | if($include = "content" and count($include) = 1)
78 | then store:outputRawDocument($doc, $extractPath, $applyTransform, $params, $outputFormat)
79 | else if($outputFormat = "json")
80 | then store:outputDocument($doc, $include, $extractPath, $applyTransform, local:queryFromRequest($params), $params, $outputFormat)
81 | else { store:outputDocument($doc, $include, $extractPath, $applyTransform, local:queryFromRequest($params), $params, $outputFormat)/* }
82 | }
83 | catch ($e) {
84 | xdmp:set($errors, common:errorFromException($e, $outputFormat))
85 | }
86 | else xdmp:set($errors, common:error("corona:INVALID-PARAMETER", "Unknown request", $outputFormat))
87 |
88 | let $output := ($errors, $content)[1]
89 | return
90 | if($output instance of binary())
91 | then common:output($output, store:getBinaryContentType($output))
92 | else common:output($output)
93 |
--------------------------------------------------------------------------------
/corona/transaction.xqy:
--------------------------------------------------------------------------------
1 | (:
2 | Copyright 2011 MarkLogic Corporation
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | :)
16 |
17 | xquery version "1.0-ml";
18 |
19 | import module namespace common="http://marklogic.com/corona/common" at "lib/common.xqy";
20 | import module namespace json="http://marklogic.com/json" at "lib/json.xqy";
21 |
22 | import module namespace rest="http://marklogic.com/appservices/rest" at "lib/rest/rest.xqy";
23 | import module namespace endpoints="http://marklogic.com/corona/endpoints" at "/config/endpoints.xqy";
24 |
25 | declare namespace corona="http://marklogic.com/corona";
26 | declare namespace hs="http://marklogic.com/xdmp/status/host";
27 |
28 | declare option xdmp:mapping "false";
29 |
30 | declare function local:generateTransactionStatus(
31 | $id as xs:unsignedLong,
32 | $outputFormat as xs:string
33 | )
34 | {
35 | let $txid := concat(xdmp:host(), ":", $id)
36 | let $status := xdmp:host-status(xdmp:host())/hs:transactions/hs:transaction[hs:transaction-id = $id]
37 | return
38 | if($outputFormat = "json")
39 | then json:document(json:object((
40 | "txid", $txid,
41 | "host", xdmp:host-name($status/hs:host-id),
42 | "createdOn", string($status/hs:start-time),
43 | "expiresOn", xs:dateTime($status/hs:start-time) + xs:dayTimeDuration(concat("PT", string($status/hs:time-limit), "S")),
44 | "canBeExtendedTo", xs:dateTime($status/hs:start-time) + xs:dayTimeDuration(concat("PT", string($status/hs:max-time-limit), "S"))
45 | )))
46 | else
47 | { $txid }
48 | { xdmp:host-name($status/hs:host-id) }
49 | { string($status/hs:start-time) }
50 | { xs:dateTime($status/hs:start-time) + xs:dayTimeDuration(concat("PT", string($status/hs:time-limit), "S")) }
51 | { xs:dateTime($status/hs:start-time) + xs:dayTimeDuration(concat("PT", string($status/hs:max-time-limit), "S")) }
52 |
53 | };
54 |
55 |
56 | let $params := rest:process-request(endpoints:request("/corona/transaction.xqy"))
57 |
58 | let $requestMethod := xdmp:get-request-method()
59 | let $action := map:get($params, "action")
60 | let $txid := map:get($params, "txid")
61 | let $outputFormat := common:getOutputFormat((), map:get($params, "outputFormat"))
62 |
63 | let $errors :=
64 | if($action = "create" and exists($txid))
65 | then common:error("corona:INVALID-PARAMETER", "Don't supply a transaction ID when creating a transaction", $outputFormat)
66 | else if($action = ("status", "commit", "rollback") and empty($txid))
67 | then common:error("corona:INVALID-PARAMETER", "Must supply a transaction ID when getting the status, committing or rolling backing a transaction", $outputFormat)
68 | else ()
69 |
70 | return common:output(
71 | if(exists($errors))
72 | then $errors
73 | else
74 |
75 | if($requestMethod = "POST")
76 | then
77 | if($action = "create")
78 | then try {
79 | let $createFN := xdmp:function(xs:QName("xdmp:transaction-create"))
80 | let $setNameFN := xdmp:function(xs:QName("xdmp:set-transaction-name"))
81 | let $setTimeLimitFN := xdmp:function(xs:QName("xdmp:set-transaction-time-limit"))
82 | let $id := xdmp:apply($createFN, update )
83 | let $set := xdmp:apply($setNameFN, "corona-transaction", xdmp:host(), $id)
84 | let $timeLimit := map:get($params, "timeLimit")
85 | let $set :=
86 | if(exists($timeLimit))
87 | then xdmp:apply($setTimeLimitFN, $timeLimit, xdmp:host(), $id)
88 | else ()
89 | return local:generateTransactionStatus($id, $outputFormat)
90 | }
91 | catch ($e) {
92 | if($e/*:code = "XDMP-UNDFUN" and $e/*:data/*:datum = ("xdmp:transaction-create()", "xdmp:set-transaction-name()"))
93 | then common:error("corona:INVALID-REQUEST", "This version of MarkLogic Server does not support transactions. Upgrade to 5.0 or greater.", $outputFormat)
94 | else if($e/*:code = "XDMP-TIMELIMIT")
95 | then common:error("corona:INVALID-TIME-LIMIT", "The time limit specified is too large.", $outputFormat)
96 | else common:errorFromException($e, $outputFormat)
97 | }
98 |
99 | else if($action = "rollback")
100 | then try {
101 | let $rollbackFN := xdmp:function(xs:QName("xdmp:transaction-rollback"))
102 | let $idMap := common:processTXID($txid, false())
103 | let $rollback := xdmp:apply($rollbackFN, map:get($idMap, "hostID"), map:get($idMap, "id"))
104 | return xdmp:set-response-code(204, "Transaction rolled back")
105 | }
106 | catch ($e) {
107 | if($e/*:code = "XDMP-UNDFUN" and $e/*:data/*:datum = "xdmp:transaction-rollback()")
108 | then common:error("corona:INVALID-REQUEST", "This version of MarkLogic Server does not support transactions. Upgrade to 5.0 or greater.", $outputFormat)
109 | else common:errorFromException($e, $outputFormat)
110 | }
111 |
112 | else if($action = "commit")
113 | then try {
114 | let $commitFN := xdmp:function(xs:QName("xdmp:transaction-commit"))
115 | let $idMap := common:processTXID($txid, false())
116 | let $commit := xdmp:apply($commitFN, map:get($idMap, "hostID"), map:get($idMap, "id"))
117 | return xdmp:set-response-code(204, "Transaction committed")
118 | }
119 | catch ($e) {
120 | if($e/*:code = "XDMP-UNDFUN" and $e/*:data/*:datum = "xdmp:transaction-commit()")
121 | then common:error("corona:INVALID-REQUEST", "This version of MarkLogic Server does not support transactions. Upgrade to 5.0 or greater.", $outputFormat)
122 | else common:errorFromException($e, $outputFormat)
123 | }
124 |
125 | else common:error("corona:INVALID-REQUEST", "Must spcify an action of create, rollback or commit", $outputFormat)
126 |
127 | else if($requestMethod = "GET")
128 | then
129 | if($action = "status")
130 | then try {
131 | let $transactionFN := xdmp:function(xs:QName("xdmp:transaction"))
132 | let $idMap := common:processTXID($txid, false())
133 | let $currentTransactions := xdmp:apply($transactionFN, "corona-transaction", map:get($idMap, "hostID"))
134 | return local:generateTransactionStatus(map:get($idMap, "id"), $outputFormat)
135 | }
136 | catch ($e) {
137 | if($e/*:code = "XDMP-UNDFUN" and $e/*:data/*:datum = "xdmp:transaction()")
138 | then common:error("corona:INVALID-REQUEST", "This version of MarkLogic Server does not support transactions. Upgrade to 5.0 or greater.", $outputFormat)
139 | else common:errorFromException($e, $outputFormat)
140 | }
141 | else common:error("corona:INVALID-PARAMETER", concat("Invalid action '", $action, "', GET requests only support returning transaction status."), $outputFormat)
142 |
143 | else common:error("corona:UNSUPPORTED-METHOD", concat("Unsupported method: ", $requestMethod), $outputFormat)
144 | )
145 |
--------------------------------------------------------------------------------
/test/bulk-store.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | mjson qunit tests
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | test markup, will be hidden
17 |
18 |
19 |
--------------------------------------------------------------------------------
/test/css/qunit.css:
--------------------------------------------------------------------------------
1 | /**
2 | * QUnit - A JavaScript Unit Testing Framework
3 | *
4 | * http://docs.jquery.com/QUnit
5 | *
6 | * Copyright (c) 2011 John Resig, Jörn Zaefferer
7 | * Dual licensed under the MIT (MIT-LICENSE.txt)
8 | * or GPL (GPL-LICENSE.txt) licenses.
9 | * Pulled Live from Git Mon Jun 13 13:15:01 UTC 2011
10 | * Last Commit: d4f23f8a882d13b71768503e2db9fa33ef169ba0
11 | */
12 |
13 | /** Font Family and Sizes */
14 |
15 | #qunit-tests, #qunit-header, #qunit-banner, #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult {
16 | font-family: "Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial, sans-serif;
17 | }
18 |
19 | #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult, #qunit-tests li { font-size: small; }
20 | #qunit-tests { font-size: smaller; }
21 |
22 |
23 | /** Resets */
24 |
25 | #qunit-tests, #qunit-tests ol, #qunit-header, #qunit-banner, #qunit-userAgent, #qunit-testresult {
26 | margin: 0;
27 | padding: 0;
28 | }
29 |
30 |
31 | /** Header */
32 |
33 | #qunit-header {
34 | padding: 0.5em 0 0.5em 1em;
35 |
36 | color: #8699a4;
37 | background-color: #0d3349;
38 |
39 | font-size: 1.5em;
40 | line-height: 1em;
41 | font-weight: normal;
42 |
43 | border-radius: 15px 15px 0 0;
44 | -moz-border-radius: 15px 15px 0 0;
45 | -webkit-border-top-right-radius: 15px;
46 | -webkit-border-top-left-radius: 15px;
47 | }
48 |
49 | #qunit-header a {
50 | text-decoration: none;
51 | color: #c2ccd1;
52 | }
53 |
54 | #qunit-header a:hover,
55 | #qunit-header a:focus {
56 | color: #fff;
57 | }
58 |
59 | #qunit-banner {
60 | height: 5px;
61 | }
62 |
63 | #qunit-testrunner-toolbar {
64 | padding: 0.5em 0 0.5em 2em;
65 | color: #5E740B;
66 | background-color: #eee;
67 | }
68 |
69 | #qunit-userAgent {
70 | padding: 0.5em 0 0.5em 2.5em;
71 | background-color: #2b81af;
72 | color: #fff;
73 | text-shadow: rgba(0, 0, 0, 0.5) 2px 2px 1px;
74 | }
75 |
76 |
77 | /** Tests: Pass/Fail */
78 |
79 | #qunit-tests {
80 | list-style-position: inside;
81 | }
82 |
83 | #qunit-tests li {
84 | padding: 0.4em 0.5em 0.4em 2.5em;
85 | border-bottom: 1px solid #fff;
86 | list-style-position: inside;
87 | }
88 |
89 | #qunit-tests.hidepass li.pass, #qunit-tests.hidepass li.running {
90 | display: none;
91 | }
92 |
93 | #qunit-tests li strong {
94 | cursor: pointer;
95 | }
96 |
97 | #qunit-tests li a {
98 | padding: 0.5em;
99 | color: #c2ccd1;
100 | text-decoration: none;
101 | }
102 | #qunit-tests li a:hover,
103 | #qunit-tests li a:focus {
104 | color: #000;
105 | }
106 |
107 | #qunit-tests ol {
108 | margin-top: 0.5em;
109 | padding: 0.5em;
110 |
111 | background-color: #fff;
112 |
113 | border-radius: 15px;
114 | -moz-border-radius: 15px;
115 | -webkit-border-radius: 15px;
116 |
117 | box-shadow: inset 0px 2px 13px #999;
118 | -moz-box-shadow: inset 0px 2px 13px #999;
119 | -webkit-box-shadow: inset 0px 2px 13px #999;
120 | }
121 |
122 | #qunit-tests table {
123 | border-collapse: collapse;
124 | margin-top: .2em;
125 | }
126 |
127 | #qunit-tests th {
128 | text-align: right;
129 | vertical-align: top;
130 | padding: 0 .5em 0 0;
131 | }
132 |
133 | #qunit-tests td {
134 | vertical-align: top;
135 | }
136 |
137 | #qunit-tests pre {
138 | margin: 0;
139 | white-space: pre-wrap;
140 | word-wrap: break-word;
141 | }
142 |
143 | #qunit-tests del {
144 | background-color: #e0f2be;
145 | color: #374e0c;
146 | text-decoration: none;
147 | }
148 |
149 | #qunit-tests ins {
150 | background-color: #ffcaca;
151 | color: #500;
152 | text-decoration: none;
153 | }
154 |
155 | /*** Test Counts */
156 |
157 | #qunit-tests b.counts { color: black; }
158 | #qunit-tests b.passed { color: #5E740B; }
159 | #qunit-tests b.failed { color: #710909; }
160 |
161 | #qunit-tests li li {
162 | margin: 0.5em;
163 | padding: 0.4em 0.5em 0.4em 0.5em;
164 | background-color: #fff;
165 | border-bottom: none;
166 | list-style-position: inside;
167 | }
168 |
169 | /*** Passing Styles */
170 |
171 | #qunit-tests li li.pass {
172 | color: #5E740B;
173 | background-color: #fff;
174 | border-left: 26px solid #C6E746;
175 | }
176 |
177 | #qunit-tests .pass { color: #528CE0; background-color: #D2E0E6; }
178 | #qunit-tests .pass .test-name { color: #366097; }
179 |
180 | #qunit-tests .pass .test-actual,
181 | #qunit-tests .pass .test-expected { color: #999999; }
182 |
183 | #qunit-banner.qunit-pass { background-color: #C6E746; }
184 |
185 | /*** Failing Styles */
186 |
187 | #qunit-tests li li.fail {
188 | color: #710909;
189 | background-color: #fff;
190 | border-left: 26px solid #EE5757;
191 | }
192 |
193 | #qunit-tests > li:last-child {
194 | border-radius: 0 0 15px 15px;
195 | -moz-border-radius: 0 0 15px 15px;
196 | -webkit-border-bottom-right-radius: 15px;
197 | -webkit-border-bottom-left-radius: 15px;
198 | }
199 |
200 | #qunit-tests .fail { color: #000000; background-color: #EE5757; }
201 | #qunit-tests .fail .test-name,
202 | #qunit-tests .fail .module-name { color: #000000; }
203 |
204 | #qunit-tests .fail .test-actual { color: #EE5757; }
205 | #qunit-tests .fail .test-expected { color: green; }
206 |
207 | #qunit-banner.qunit-fail { background-color: #EE5757; }
208 |
209 |
210 | /** Result */
211 |
212 | #qunit-testresult {
213 | padding: 0.5em 0.5em 0.5em 2.5em;
214 |
215 | color: #2b81af;
216 | background-color: #D2E0E6;
217 |
218 | border-bottom: 1px solid white;
219 | }
220 |
221 | /** Fixture */
222 |
223 | #qunit-fixture {
224 | position: absolute;
225 | top: -10000px;
226 | left: -10000px;
227 | }
--------------------------------------------------------------------------------
/test/data/json.tar.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marklogic-community/Corona/a5178fccc91a5e68e98e9dfb56587329a6f7dd10/test/data/json.tar.gz
--------------------------------------------------------------------------------
/test/data/xml.tar.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marklogic-community/Corona/a5178fccc91a5e68e98e9dfb56587329a6f7dd10/test/data/xml.tar.gz
--------------------------------------------------------------------------------
/test/dateparser.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | date parsing qunit tests
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | test markup, will be hidden
17 |
18 |
19 |
--------------------------------------------------------------------------------
/test/env.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | env tests
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | test markup, will be hidden
17 |
18 |
19 |
--------------------------------------------------------------------------------
/test/index.html:
--------------------------------------------------------------------------------
1 |
2 | Varoius test suites
3 | Warning: Tests do not clean up after themselves, will modify your database and your index settings. Yes, this should be fixed :).
4 |
21 |
22 |
--------------------------------------------------------------------------------
/test/indexmgmt.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | mjson qunit tests
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | test markup, will be hidden
17 |
18 |
19 |
--------------------------------------------------------------------------------
/test/js/bulk-store-tests.js:
--------------------------------------------------------------------------------
1 | if(typeof corona == "undefined" || !corona) {
2 | corona = {};
3 | corona.stash = {};
4 | }
5 |
6 | corona.documents = [
7 | {
8 | "type": "json",
9 | "uri": "/doc-store-test-1.json",
10 | "content": { "foo": "bar" }
11 | },
12 | {
13 | "type": "json",
14 | "uri": "/doc-store-test-2.json",
15 | "content": { "foo": "bar" }
16 | },
17 | {
18 | "type": "json",
19 | "uri": "/doc-store-test-3.json",
20 | "content": { "foo": "bar" }
21 | },
22 | {
23 | "type": "json",
24 | "uri": "/doc-store-test-4.json",
25 | "content": { "foo": "bar" }
26 | },
27 | {
28 | "type": "json",
29 | "uri": "/doc-store-test-5.json",
30 | "content": { "foo": "bar" }
31 | },
32 |
33 | {
34 | "type": "xml",
35 | "uri": "/doc-store-test-1.xml",
36 | "content": "bar "
37 | },
38 | {
39 | "type": "xml",
40 | "uri": "/doc-store-test-2.xml",
41 | "content": "bar "
42 | },
43 | {
44 | "type": "xml",
45 | "uri": "/doc-store-test-3.xml",
46 | "content": "bar "
47 | },
48 | {
49 | "type": "xml",
50 | "uri": "/doc-store-test-4.xml",
51 | "content": "bar "
52 | },
53 | {
54 | "type": "xml",
55 | "uri": "/doc-store-test-5.xml",
56 | "content": "bar "
57 | }
58 | ];
59 |
60 | corona.constructURL = function(doc, prefix, processExtras) {
61 | return "/store?uri=" + encodeURIComponent(prefix + doc.uri) + "&contentType=" + doc.type;
62 | };
63 |
64 | corona.insertDocuments = function(prefix, callback) {
65 | var i = 0;
66 | for(i = 0; i < corona.documents.length; i += 1) {
67 | if(corona.documents[i].type === "json" && corona.stash.status.features.JSONDocs === false) {
68 | continue;
69 | }
70 |
71 | var wrapper = function(index) {
72 | var doc = corona.documents[index];
73 | asyncTest("Inserting document: " + prefix + doc.uri, function() {
74 | var docContent = doc.content;
75 | if(doc.type === "json") {
76 | docContent = JSON.stringify(docContent);
77 | }
78 |
79 | $.ajax({
80 | url: corona.constructURL(doc, prefix),
81 | type: 'PUT',
82 | data: docContent,
83 | context: doc,
84 | success: function() {
85 | ok(true, "Inserted document");
86 | if(index === corona.documents.length - 1) {
87 | corona.deleteDocuments();
88 | }
89 | },
90 | error: function(j, t, error) {
91 | ok(false, "Could not insert document");
92 | },
93 | complete: function() {
94 | start();
95 | }
96 | });
97 | });
98 | }.call(this, i);
99 | }
100 | };
101 |
102 | corona.deleteDocuments = function() {
103 | asyncTest("Bulk delete check", function() {
104 | $.ajax({
105 | url: '/store?structuredQuery={"keyExists": "foo"}',
106 | type: 'DELETE',
107 | success: function() {
108 | ok(false, "Deleted documents");
109 | },
110 | error: function(j, t, error) {
111 | ok(true, "Could not delete documents");
112 | },
113 | complete: function() {
114 | start();
115 | }
116 | });
117 | });
118 | asyncTest("No documents check", function() {
119 | $.ajax({
120 | url: '/store?structuredQuery={"keyExists": "bar"}',
121 | type: 'DELETE',
122 | success: function() {
123 | ok(false, "Deleted documents");
124 | },
125 | error: function(j, t, error) {
126 | ok(true, "No documents to to deelete");
127 | },
128 | complete: function() {
129 | start();
130 | }
131 | });
132 | });
133 |
134 | asyncTest("Deleting JSON documents", function() {
135 | $.ajax({
136 | url: '/store?structuredQuery={"keyExists": "foo"}&bulkDelete=true',
137 | type: 'DELETE',
138 | success: function() {
139 | ok(true, "Deleted documents");
140 | },
141 | error: function(j, t, error) {
142 | ok(false, "Could not delete documents: " + error);
143 | },
144 | complete: function() {
145 | start();
146 | }
147 | });
148 | });
149 |
150 | asyncTest("Deleting XML documents", function() {
151 | $.ajax({
152 | url: '/store?structuredQuery={"element": "foo", "equals": "bar"}&bulkDelete=true&limit=2',
153 | type: 'DELETE',
154 | success: function() {
155 | ok(true, "Deleted documents (with limit)");
156 |
157 | asyncTest("Deleting XML documents", function() {
158 | $.ajax({
159 | url: '/store?structuredQuery={"element": "foo", "equals": "bar"}&bulkDelete=true',
160 | type: 'DELETE',
161 | success: function() {
162 | ok(true, "Deleted documents");
163 | },
164 | error: function(j, t, error) {
165 | ok(false, "Could not delete documents: " + error);
166 | },
167 | complete: function() {
168 | start();
169 | }
170 | });
171 | });
172 | },
173 | error: function(j, t, error) {
174 | ok(false, "Could not delete documents: " + error);
175 | },
176 | complete: function() {
177 | start();
178 | }
179 | });
180 | });
181 | };
182 |
183 | corona.deleteDocument = function(prefix, doc) {
184 | asyncTest("Deleting document: " + prefix + doc.uri, function() {
185 | $.ajax({
186 | url: corona.constructURL(doc, prefix, "remove"),
187 | type: 'DELETE',
188 | context: doc,
189 | success: function() {
190 | ok(true, "Deleted document");
191 | $.ajax({
192 | url: corona.constructURL(doc, prefix, "ignore") + "include=all",
193 | type: 'GET',
194 | context: this,
195 | success: function(data) {
196 | ok(false, "Document not truly deleted");
197 | },
198 | error: function(j, t, error) {
199 | ok(true, "Document truly deleted");
200 | },
201 | complete: function() {
202 | start();
203 | }
204 | });
205 | },
206 | error: function(j, t, error) {
207 | ok(false, "Could not delete document");
208 | }
209 | });
210 | });
211 | };
212 |
213 | $(document).ready(function() {
214 | module("Bulk Store");
215 | corona.fetchInfo(function(info) {
216 | corona.stash.status = info;
217 | corona.insertDocuments("/bulk", function() {
218 | });
219 | });
220 | });
221 |
--------------------------------------------------------------------------------
/test/js/common.js:
--------------------------------------------------------------------------------
1 | if(typeof corona == "undefined" || !corona) {
2 | corona = {};
3 | corona.stash = {};
4 | }
5 |
6 | corona.fetchInfo = function(callback) {
7 | asyncTest("Fetching Corona state", function() {
8 | $.ajax({
9 | url: "/manage",
10 | success: function(data) {
11 | ok(true, "Fetched Corona state");
12 | callback.call(this, data);
13 | },
14 | error: function(j, t, error) {
15 | ok(false, "Fetched Corona state");
16 | console.log("Could not fetch /manage: " + error);
17 | },
18 | complete: function() { start(); }
19 | });
20 | });
21 | };
22 |
--------------------------------------------------------------------------------
/test/js/dateparser-tests.js:
--------------------------------------------------------------------------------
1 | if(typeof corona == "undefined" || !corona) {
2 | corona = {};
3 | corona.stash = {};
4 | }
5 |
6 | corona.dates = [
7 | {
8 | "string": "2011-07-07T11:05:42-07:00",
9 | "value": "2011-07-07T11:05:42-07:00"
10 | },
11 | {
12 | "string": "Thu Jul 07 2011 11:05:42 GMT-0700 (PDT)",
13 | "value": "2011-07-07T11:05:42-07:00"
14 | },
15 | {
16 | "string": "30 Jun 2006 09:39:08 -0500",
17 | "value": "2006-06-30T09:39:08-05:00"
18 | },
19 | {
20 | "string": "Apr 16 13:49:06 2003 +0200",
21 | "value": "2003-04-16T13:49:06+02:00"
22 | },
23 | {
24 | "string": "Aug 04 11:44:58 EDT 2003",
25 | "value": "2003-08-04T11:44:58-04:00"
26 | },
27 | {
28 | "string": "4 Jan 98 0:41 EDT",
29 | "value": "1998-01-04T00:41:00-04:00"
30 | },
31 | {
32 | "string": "25-Oct-2004 17:06:46 -0500",
33 | "value": "2004-10-25T17:06:46-05:00"
34 | },
35 | {
36 | "string": "Mon, 23 Sep 0102 23:14:26 +0900",
37 | "value": "2002-09-23T23:14:26+09:00"
38 | },
39 | {
40 | "string": "08/20/2007 5:58:20 AM",
41 | "value": "2007-08-20T05:58:20-07:00"
42 | },
43 | {
44 | "string": "08/20/2007 5:58:20 pm",
45 | "value": "2007-08-20T17:58:20-07:00"
46 | },
47 | {
48 | "string": "08/20/2007 5:58:20 Pm",
49 | "value": "2007-08-20T17:58:20-07:00"
50 | },
51 | {
52 | "string": "08/20/2007 5:58:20 P.m.",
53 | "value": "2007-08-20T17:58:20-07:00"
54 | },
55 | {
56 | "string": "2011-07-07",
57 | "value": "2011-07-07T00:00:00-07:00"
58 | },
59 | {
60 | "string": "08-20-2007",
61 | "value": "2007-08-20T00:00:00-07:00"
62 | },
63 | {
64 | "string": "08-20-07",
65 | "value": "2007-08-20T00:00:00-07:00"
66 | },
67 | {
68 | "string": "2007/08/20",
69 | "value": "2007-08-20T00:00:00-07:00"
70 | },
71 | {
72 | "string": "08/20/2007",
73 | "value": "2007-08-20T00:00:00-07:00"
74 | },
75 | {
76 | "string": "08/20/07",
77 | "value": "2007-08-20T00:00:00-07:00"
78 | },
79 | {
80 | "string": "20070820",
81 | "value": "2007-08-20T00:00:00-07:00"
82 | },
83 | {
84 | "string": "December 20, 2005",
85 | "value": "2005-12-20T00:00:00-07:00"
86 | },
87 | {
88 | "string": "Dec 20th, 2005",
89 | "value": "2005-12-20T00:00:00-07:00"
90 | },
91 | {
92 | "string": "September 1st, 2007",
93 | "value": "2007-09-01T00:00:00-07:00"
94 | }
95 | ];
96 |
97 | $(document).ready(function() {
98 | module("Dates");
99 | corona.fetchInfo(function(info) {
100 | if(info.features.dateParsing === false) {
101 | return;
102 | }
103 |
104 | for (var i = 0; i < corona.dates.length; i += 1) {
105 | corona.jsonFromServerTest(corona.dates[i]);
106 | }
107 | });
108 | });
109 |
110 |
111 | corona.jsonFromServer = function(test, success, error) {
112 | asyncTest("Parsing: " + test.string, function() {
113 | $.ajax({
114 | url: '/test/xq/parsedate.xqy',
115 | data: {"date": test.string},
116 | method: 'GET',
117 | success: success,
118 | error: error,
119 | complete: function() { start(); }
120 | });
121 | });
122 | };
123 |
124 | corona.jsonFromServerTest = function(test) {
125 | corona.jsonFromServer(test,
126 | function(data, t, j) {
127 | equals(data, test.value, "Parsed date doesn't match");
128 | },
129 | function(j, t, e) { ok(false, e); console.log(e); }
130 | );
131 | };
132 |
--------------------------------------------------------------------------------
/test/js/env-tests.js:
--------------------------------------------------------------------------------
1 | if(typeof corona == "undefined" || !corona) {
2 | corona = {};
3 | corona.stash = {};
4 | }
5 |
6 | corona.deleteEnvVar = function(name, callback) {
7 | asyncTest("Deleting var: " + name, function() {
8 | $.ajax({
9 | url: "/manage/env/" + name,
10 | type: 'DELETE',
11 | success: function() {
12 | ok(true, "Deleted var: " + name);
13 | $.ajax({
14 | url: "/manage/env",
15 | type: 'GET',
16 | success: function(data) {
17 | ok(true, "Get env");
18 | equals(data[name], undefined, "Env var is gone: " + name);
19 | if(callback) {
20 | callback.call(this);
21 | }
22 | },
23 | error: function(j, t, error) {
24 | ok(false, "Get env");
25 | },
26 | complete: function() { start(); }
27 | });
28 | },
29 | error: function(j, t, error) {
30 | ok(false, "Deleted var: " + name);
31 | }
32 | });
33 | });
34 | };
35 |
36 | corona.setInsertHook = function(name, callback) {
37 | asyncTest("Setting insert env to: " + name, function() {
38 | $.ajax({
39 | url: "/manage/env/insertTransformer",
40 | data: {value: name},
41 | type: 'POST',
42 | success: function() {
43 | ok(true, "Insert env set");
44 | $.ajax({
45 | url: "/manage/env",
46 | type: 'GET',
47 | success: function(data) {
48 | ok(true, "Get env");
49 | if(name !== "") {
50 | equals(data.insertTransformer, name, "Insert transformer set to: " + name);
51 | }
52 | else {
53 | equals(data.insertTransformer, undefined, "Insert transformer removed");
54 | }
55 | if(callback) {
56 | callback.call(this);
57 | }
58 | },
59 | error: function(j, t, error) {
60 | ok(false, "Get env");
61 | },
62 | complete: function() { start(); }
63 | });
64 | },
65 | error: function(j, t, error) {
66 | ok(false, "Insert env set");
67 | }
68 | });
69 | });
70 | };
71 |
72 | corona.setFetchHook = function(name, callback) {
73 | asyncTest("Setting fetch env to: " + name, function() {
74 | $.ajax({
75 | url: "/manage/env/fetchTransformer",
76 | data: {value: name},
77 | type: 'POST',
78 | success: function() {
79 | ok(true, "Fetch env set");
80 | $.ajax({
81 | url: "/manage/env",
82 | type: 'GET',
83 | success: function(data) {
84 | ok(true, "Get env");
85 | if(name !== "") {
86 | equals(data.fetchTransformer, name, "Fetch transformer set to: " + name);
87 | }
88 | else {
89 | equals(data.fetchTransformer, undefined, "Fetch transformer removed");
90 | }
91 | if(callback) {
92 | callback.call(this);
93 | }
94 | },
95 | error: function(j, t, error) {
96 | ok(false, "Get env");
97 | },
98 | complete: function() { start(); }
99 | });
100 | },
101 | error: function(j, t, error) {
102 | ok(false, "Fetch env set");
103 | }
104 | });
105 | });
106 | };
107 |
108 | corona.testInsertHook = function(callback) {
109 | corona.setInsertHook("adddate", function() {
110 | asyncTest("Inserting document", function() {
111 | $.ajax({
112 | url: "/store?uri=/auto-transform.xml&respondWithContent=true",
113 | data: " ",
114 | type: 'PUT',
115 | success: function(response) {
116 | ok(true, "Inserted document with auto-transform");
117 | equals(response.getElementsByTagName("wrapper").length, 1, "Transformer was applied to document");
118 | corona.deleteEnvVar("insertTransformer", callback);
119 | },
120 | error: function(j, t, error) {
121 | ok(false, "Inserted document with auto-transform");
122 | },
123 | complete: function() { start(); }
124 | });
125 | });
126 | });
127 | };
128 |
129 | corona.testFetchHook = function(callback) {
130 | corona.setFetchHook("adddate", function() {
131 | asyncTest("Inserting document", function() {
132 | $.ajax({
133 | url: "/store?uri=/auto-transform-on-fetch.xml",
134 | data: " ",
135 | type: 'PUT',
136 | success: function(response) {
137 | $.ajax({
138 | url: "/store?uri=/auto-transform-on-fetch.xml",
139 | type: 'GET',
140 | success: function(response) {
141 | ok(true, "Fetching document with auto-transform");
142 | equals(response.getElementsByTagName("wrapper").length, 1, "Transformer was applied to document");
143 | corona.deleteEnvVar("fetchTransformer", callback);
144 | },
145 | error: function(j, t, error) {
146 | ok(false, "Fetching document with auto-transform");
147 | },
148 | complete: function() { start(); }
149 | });
150 | },
151 | error: function(j, t, error) {
152 | ok(false, "Inserted document");
153 | }
154 | });
155 | });
156 | });
157 | };
158 |
159 |
160 | $(document).ready(function() {
161 | module("Env Var Management");
162 | corona.testInsertHook(corona.testFetchHook);
163 |
164 | });
165 |
--------------------------------------------------------------------------------
/test/js/named-query-tests.js:
--------------------------------------------------------------------------------
1 | if(typeof corona == "undefined" || !corona) {
2 | corona = {};
3 | corona.stash = {};
4 | }
5 |
6 | corona.namedQueries = [
7 | {
8 | name: "query1",
9 | purpose: "Basic string query",
10 | storeParams: {
11 | description: "Hello world string query",
12 | stringQuery: "hello world"
13 | },
14 | getParams: {
15 | },
16 | shouldSucceed: true,
17 | assert: function(data) {
18 | equals(data.results.length, 1, "Got one document");
19 | equals(data.results[0].name, "query1", "Correct name was found");
20 | equals(data.results[0].queryType, "string", "Correct query type was found");
21 | }
22 | },
23 | {
24 | name: "query2",
25 | purpose: "Basic structured query",
26 | storeParams: {
27 | description: "Hello world structured query",
28 | structuredQuery: JSON.stringify({wordAnywhere: "hello world"})
29 | },
30 | getParams: {
31 | },
32 | shouldSucceed: true,
33 | assert: function(data) {
34 | equals(data.results.length, 1, "Got one document");
35 | equals(data.results[0].name, "query2", "Correct name was found");
36 | equals(data.results[0].queryType, "structured", "Correct query type was found");
37 | }
38 | },
39 | {
40 | name: "query3",
41 | purpose: "Query with collection",
42 | storeParams: {
43 | description: "Query in collection",
44 | structuredQuery: JSON.stringify({wordAnywhere: "hello world"}),
45 | collection: "namedQueryCollection1"
46 | },
47 | getParams: {
48 | collection: "namedQueryCollection1"
49 | },
50 | shouldSucceed: true,
51 | assert: function(data) {
52 | equals(data.results.length, 1, "Got one document");
53 | equals(data.results[0].name, "query3", "Correct name was found");
54 | equals(data.results[0].queryType, "structured", "Correct query type was found");
55 | }
56 | },
57 | {
58 | name: "query4",
59 | purpose: "Query with property",
60 | storeParams: {
61 | description: "Query with property",
62 | structuredQuery: JSON.stringify({wordAnywhere: "hello world"}),
63 | property: "querykey:foobar"
64 | },
65 | getParams: {
66 | property: "querykey",
67 | value: "foobar"
68 | },
69 | shouldSucceed: true,
70 | assert: function(data) {
71 | equals(data.results.length, 1, "Got one document");
72 | equals(data.results[0].name, "query4", "Correct name was found");
73 | equals(data.results[0].queryType, "structured", "Correct query type was found");
74 | }
75 | },
76 | ];
77 |
78 | corona.storeQuery = function(definition) {
79 | asyncTest(definition.purpose, function() {
80 | $.ajax({
81 | url: "/namedquery/" + definition.name,
82 | type: 'POST',
83 | data: definition.storeParams,
84 | success: function() {
85 | ok(definition.shouldSucceed, "Named query storage succeded");
86 | if(definition.shouldSucceed === false) {
87 | return;
88 | }
89 |
90 | url = "/namedquery";
91 | if(definition.getParams.collection === undefined && definition.getParams.property === undefined) {
92 | url += "/" + definition.name;
93 | }
94 |
95 | $.ajax({
96 | url: url,
97 | type: 'GET',
98 | data: definition.getParams,
99 | success: function(data) {
100 | ok(true, "Fetched named query");
101 | if(definition.assert !== undefined) {
102 | definition.assert.call(this, data);
103 | }
104 | $.ajax({
105 | url: "/namedquery/" + definition.name,
106 | type: 'DELETE',
107 | success: function() {
108 | ok(true, "Deleted named query");
109 | },
110 | error: function() {
111 | ok(false, "Deleted named query");
112 | }
113 | });
114 | },
115 | error: function(j, t, error) {
116 | ok(false, "Fetching named query");
117 | },
118 | complete: function() {
119 | start();
120 | }
121 | });
122 | },
123 | error: function(j, t, error) {
124 | ok(!definition.shouldSucceed, "Named query storage failed");
125 | }
126 | });
127 | });
128 | };
129 |
130 | corona.removePrefix = function(prefix, callback) {
131 | $.ajax({
132 | url: "/manage/namedqueryprefix/" + prefix,
133 | type: 'GET',
134 | success: function() {
135 | $.ajax({
136 | url: "/manage/namedqueryprefix/" + prefix,
137 | type: 'DELETE',
138 | success: function() {
139 | callback.call();
140 | }
141 | });
142 | },
143 | error: function() {
144 | callback.call();
145 | }
146 | });
147 | }
148 |
149 | $(document).ready(function() {
150 | module("Named Queries");
151 |
152 | for(i = 0; i < corona.namedQueries.length; i += 1) {
153 | corona.storeQuery(corona.namedQueries[i]);
154 | }
155 |
156 | corona.removePrefix("zip", function() {
157 | $.ajax({
158 | url: "/manage/namedqueryprefix/zip",
159 | type: 'POST',
160 | success: function() {
161 | $.ajax({
162 | url: "/namedquery/zip:94402",
163 | type: 'POST',
164 | data: {
165 | structuredQuery: JSON.stringify({
166 | "geo": "geokey",
167 | "region": {
168 | "point": {
169 | "latitude": 37.554167,
170 | "longitude": -122.31305610
171 | }
172 | }
173 | })
174 | }
175 | });
176 | }
177 | });
178 | });
179 |
180 | });
181 |
--------------------------------------------------------------------------------
/test/js/path-parser-tests.js:
--------------------------------------------------------------------------------
1 | if(typeof corona == "undefined" || !corona) {
2 | corona = {};
3 | corona.stash = {};
4 | }
5 |
6 | corona.paths = [
7 | {
8 | "path": 'foo.bar.baz[0]',
9 | "type": "json",
10 | "result": "json:foo/json:bar/json:baz/json:item[1]",
11 | "purpose": "Simple steps with array access at end"
12 | },
13 | {
14 | "path": '["foo"]["bar"]["baz"][0]',
15 | "type": "json",
16 | "result": "json:foo/json:bar/json:baz/json:item[1]",
17 | "purpose": "Quoted steps with array access at end"
18 | },
19 | {
20 | "path": 'root().foo.bar',
21 | "type": "json",
22 | "result": "ancestor-or-self::json:json/json:foo/json:bar",
23 | "purpose": "root() function"
24 | },
25 | {
26 | "path": 'foo.bar.baz.parent()',
27 | "type": "json",
28 | "result": "json:foo/json:bar/json:baz/..",
29 | "purpose": "parent() function"
30 | },
31 | {
32 | "path": 'foo.bar.baz.ancestor("foo")',
33 | "type": "json",
34 | "result": "json:foo/json:bar/json:baz/ancestor::json:foo",
35 | "purpose": "ancestor() function"
36 | },
37 | {
38 | "path": 'foo.*.bar',
39 | "type": "json",
40 | "result": "json:foo//json:bar",
41 | "purpose": "Wildstep between simple steps"
42 | },
43 | {
44 | "path": '*.foo.bar',
45 | "type": "json",
46 | "result": "//json:foo/json:bar",
47 | "purpose": "Wildstep as first steps"
48 | },
49 | {
50 | "path": 'foo.bar.*',
51 | "type": "json",
52 | "result": "json:foo/json:bar/*",
53 | "purpose": "Wildstep as last steps"
54 | },
55 | {
56 | "path": 'foo.bar.xpath("baz/yaz")',
57 | "type": "json",
58 | "result": "json:foo/json:bar/baz/yaz",
59 | "purpose": "XPath function"
60 | },
61 | {
62 | "path": 'foo..bar',
63 | "type": "json",
64 | "error": "Unexpected token '.' in path 'foo..bar', expected either a step or a function call.",
65 | "purpose": "Double dots"
66 | },
67 | {
68 | "path": 'foo*',
69 | "type": "json",
70 | "error": "Unexpected token '*' in path 'foo*', expected either a dot, a quoted step or an array index.",
71 | "purpose": "Missing dot between simple step and wildstep"
72 | },
73 | {
74 | "path": 'foo.**',
75 | "type": "json",
76 | "error": "Unexpected token '*' in path 'foo.**', expected either a dot, a quoted step or an array index.",
77 | "purpose": "Missing dot between wild steps"
78 | },
79 | {
80 | "path": 'foo.parent()bar',
81 | "type": "json",
82 | "error": "Unexpected token 'bar' in path 'foo.parent()bar', expected either a dot, a quoted step or an array index.",
83 | "purpose": "Missing dot after parent() function"
84 | },
85 | {
86 | "path": 'foo.ancestor("baz")bar',
87 | "type": "json",
88 | "error": "Unexpected token 'bar' in path 'foo.ancestor(\"baz\")bar', expected either a dot, a quoted step or an array index.",
89 | "purpose": "Missing dot after ancestor() function"
90 | },
91 |
92 | {
93 | "path": 'foo/bar/ancestor::foo/ancestor-or-self::bar/child::foo/descendant::bar//foo/descendant-or-self::bar/following::foo/following-sibling::bar/parent::foo/../preceding::bar/preceding-sibling::foo/self::bar/*/foo[30]/bar/@foo',
94 | "type": "xml",
95 | "purpose": "XPath that hits all the touch points"
96 | },
97 |
98 | {
99 | "path": 'foo//',
100 | "type": "xml",
101 | "error": "Unexpected token '/' in path 'foo//', expected either an XML element or an XPath axis.",
102 | "purpose": "Trailing double slash"
103 | },
104 | {
105 | "path": 'foo/[1]',
106 | "type": "xml",
107 | "error": "Unexpected token '[1]' in path 'foo/[1]', expected either an XML element or an XPath axis.",
108 | "purpose": "Missing element name before predicate"
109 | },
110 | {
111 | "path": 'ancestor::foodescendant::bar',
112 | "type": "xml",
113 | "error": "Invalid XML element name or undefined namespace prefix: 'foodescendant::bar'.",
114 | "purpose": "Bogus element name"
115 | },
116 | {
117 | "path": 'foo/@',
118 | "type": "xml",
119 | "error": "Unexpected token '@' in path 'foo/@'",
120 | "purpose": "Bogus element name"
121 | },
122 | {
123 | "path": 'foo/@bar/baz',
124 | "type": "xml",
125 | "error": "Unexpected token '/' in path 'foo/@bar/baz', cannot descend into attribute values.",
126 | "purpose": "Bogus element name"
127 | },
128 | {
129 | "path": 'foo[1][2]',
130 | "type": "xml",
131 | "error": "Unexpected token '[2]' in path 'foo[1][2]', expected a slash.",
132 | "purpose": "Smashed up predicates"
133 | },
134 | {
135 | "path": 'foo[1]/[2]',
136 | "type": "xml",
137 | "error": "Unexpected token '[2]' in path 'foo[1]/[2]', expected either an XML element or an XPath axis.",
138 | "purpose": "Missing element name before predicate"
139 | },
140 | {
141 | "path": 'foo///bar',
142 | "type": "xml",
143 | "error": "Unexpected token '/' in path 'foo////bar', expected either an XML element or an XPath axis.",
144 | "purpose": "Tripple slash"
145 | },
146 | {
147 | "path": 'foo/**/bar',
148 | "type": "xml",
149 | "error": "Unexpected token '*' in path 'foo/**/bar', expected either a slash or a predicate.",
150 | "purpose": "Double wild"
151 | }
152 | ];
153 |
154 | $(document).ready(function() {
155 | module("Paths");
156 | corona.fetchInfo(function(info) {
157 | corona.stash.status = info;
158 | for (var i = 0; i < corona.paths.length; i += 1) {
159 | if(corona.paths[i].type === "json" && info.features.JSONPath === false) {
160 | continue;
161 | }
162 | corona.pathFromServerTest(corona.paths[i]);
163 | }
164 | });
165 | });
166 |
167 |
168 | corona.pathFromServer = function(test, success, error) {
169 | asyncTest(test.purpose, function() {
170 | $.ajax({
171 | url: '/test/xq/parsepath.xqy',
172 | data: {"path": test.path, "type": test.type},
173 | success: success,
174 | error: error,
175 | complete: function() { start(); }
176 | });
177 | });
178 | };
179 |
180 | corona.pathFromServerTest = function(test) {
181 | corona.pathFromServer(test,
182 | function(data, t, j) {
183 | if(test.error !== undefined) {
184 | equals(data, test.error, test.purpose);
185 | }
186 | else if(test.result !== undefined) {
187 | equals(data, test.result, test.purpose);
188 | }
189 | else if(test.type === "xml") {
190 | equals(data, test.path, test.purpose);
191 | }
192 | },
193 | function(j, t, e) { ok(false, e); console.log(e); }
194 | );
195 | };
196 |
--------------------------------------------------------------------------------
/test/js/schema-tests.js:
--------------------------------------------------------------------------------
1 | if(typeof corona == "undefined" || !corona) {
2 | corona = {};
3 | corona.stash = {};
4 | }
5 |
6 | corona.removeSchemas = function(info, callback) {
7 | var i = 0;
8 | var schemas = [];
9 | for(i = 0; i < info.xmlSchemas.length; i += 1) {
10 | schemas.push(info.xmlSchemas[i]);
11 | }
12 |
13 | var processingPosition = 0;
14 | var removeNextItem = function() {
15 | removeItem(schemas[processingPosition]);
16 | processingPosition++;
17 | };
18 |
19 | var removeItem = function(schema) {
20 | if(schema === undefined) {
21 | callback.call();
22 | return;
23 | }
24 |
25 | asyncTest("Remove the schema: " + schema, function() {
26 | var url = "/manage/schema?uri=" + schema;
27 | $.ajax({
28 | url: url,
29 | type: 'DELETE',
30 | success: function() {
31 | ok(true, "Removed schema: " + schema);
32 | asyncTest("Check to make sure the schema is gone", function() {
33 | $.ajax({
34 | url: url,
35 | success: function(data) {
36 | ok(false, "Schema still exists: " + schema);
37 | },
38 | error: function() {
39 | ok(true, "Schema is gone");
40 | },
41 | complete: function() { start(); }
42 | });
43 | });
44 | removeNextItem();
45 | },
46 | error: function(j, t, error) {
47 | ok(false, "Could not delete schema: " + schema + ": " + error);
48 | },
49 | complete: function() { start(); }
50 | });
51 | });
52 | }
53 |
54 | removeNextItem();
55 | };
56 |
57 | corona.addSchemas = function(callback) {
58 | var schemas = [
59 | {
60 | "uri": "/schema/foo.xs",
61 | "schema": ' ',
62 | "shouldSucceed": true
63 | }
64 | ];
65 |
66 | var processingPosition = 0;
67 | var addNextItem = function() {
68 | addItem(schemas[processingPosition]);
69 | processingPosition++;
70 | };
71 |
72 | var addItem = function(schema) {
73 | if(schema === undefined) {
74 | callback.call();
75 | return;
76 | }
77 |
78 | asyncTest("PUT: " + schema.uri, function() {
79 | $.ajax({
80 | url: "/manage/schema?uri=" + schema.uri,
81 | data: schema.schema,
82 | type: "PUT",
83 | success: function() {
84 | addNextItem();
85 | ok(schema.shouldSucceed, "Schema added: " + schema.uri);
86 | },
87 | error: function(j, t, error) {
88 | ok(!schema.shouldSucceed, "Could not add schema: " + error);
89 | addNextItem();
90 | },
91 | complete: function() { start(); }
92 | });
93 | });
94 | };
95 |
96 | addNextItem();
97 | };
98 |
99 | $(document).ready(function() {
100 | module("Schemas");
101 | asyncTest("Schema tests", function() {
102 | $.ajax({
103 | url: '/manage',
104 | success: function(info) {
105 | corona.removeSchemas(info, function() {
106 | corona.addSchemas(function() {
107 | });
108 | });
109 | },
110 | error: function() {
111 | ok(false, "Could not fetch server info");
112 | },
113 | complete: function() { start(); }
114 | });
115 | });
116 | });
117 |
--------------------------------------------------------------------------------
/test/js/transaction-tests.js:
--------------------------------------------------------------------------------
1 | if(typeof corona == "undefined" || !corona) {
2 | corona = {};
3 | corona.stash = {};
4 | }
5 |
6 | corona.startTransaction = function(supportsTransactions, callback) {
7 | asyncTest("Starting transaction", function() {
8 | $.ajax({
9 | url: "/transaction/create",
10 | type: 'POST',
11 | data: {outputFormat: "json"},
12 | success: function(data) {
13 | ok(supportsTransactions === true, "Created transaction");
14 | callback.call(this, data.txid);
15 | },
16 | error: function(j, t, error) {
17 | ok(supportsTransactions === false, "Could not create transaction");
18 | },
19 | complete: function() { start(); }
20 | });
21 | });
22 | };
23 |
24 | corona.rollbackTransaction = function(txid, callback) {
25 | asyncTest("Rolling back transaction", function() {
26 | $.ajax({
27 | url: "/transaction/rollback",
28 | type: 'POST',
29 | data: {outputFormat: "json", txid: txid},
30 | success: function(data) {
31 | ok(true, "Rolled back transaction");
32 | callback.call(this);
33 | },
34 | error: function(j, t, error) {
35 | ok(false, "Could not roll back transaction");
36 | },
37 | complete: function() { start(); }
38 | });
39 | });
40 | };
41 |
42 | corona.commitTransaction = function(txid, callback) {
43 | asyncTest("Commit transaction", function() {
44 | $.ajax({
45 | url: "/transaction/commit",
46 | type: 'POST',
47 | data: {outputFormat: "json", txid: txid},
48 | success: function(data) {
49 | ok(true, "Committed transaction");
50 | callback.call(this);
51 | },
52 | error: function(j, t, error) {
53 | ok(false, "Could not commit transaction");
54 | },
55 | complete: function() { start(); }
56 | });
57 | });
58 | };
59 |
60 | corona.loadDocument = function(doc, uri, txid, callback) {
61 | asyncTest("Loading document", function() {
62 | var url = "/store?uri=" + encodeURIComponent(uri);
63 | if(txid) {
64 | url += "&txid=" + txid;
65 | }
66 | $.ajax({
67 | url: url,
68 | type: 'PUT',
69 | data: JSON.stringify(doc),
70 | success: function(data) {
71 | ok(true, "Loaded document in transaction");
72 | callback.call(this);
73 | },
74 | error: function(j, t, error) {
75 | ok(false, "Loaded document in transaction");
76 | },
77 | complete: function() { start(); }
78 | });
79 | });
80 | };
81 |
82 | corona.docExists = function(uri, txid, shouldExist, callback) {
83 | var desc;
84 | if(txid) {
85 | if(shouldExist) {
86 | desc = "Testing for existance in transaction";
87 | }
88 | else {
89 | desc = "Testing for non-existance in transaction";
90 | }
91 | }
92 | else {
93 | if(shouldExist) {
94 | desc = "Testing for existance outside of transaction";
95 | }
96 | else {
97 | desc = "Testing for non-existance outside of transaction";
98 | }
99 | }
100 | asyncTest(desc, function() {
101 | var url = "/store?uri=" + encodeURIComponent(uri);
102 | if(txid) {
103 | url += "&txid=" + txid;
104 | }
105 | $.ajax({
106 | url: url,
107 | type: 'GET',
108 | success: function(data) {
109 | ok(shouldExist === true, "Document exists");
110 | callback.call(this);
111 | },
112 | error: function(j, t, error) {
113 | ok(shouldExist === false, "Document exists");
114 | callback.call(this);
115 | },
116 | complete: function() { start(); }
117 | });
118 | });
119 | };
120 |
121 | corona.supportsTransactions = function(callback) {
122 | $.ajax({
123 | url: "/manage",
124 | type: 'GET',
125 | success: function(data) {
126 | var serverVersion = data.serverVersion;
127 | callback.call(this, serverVersion.substring(0, 1) === "5");
128 | }
129 | });
130 | };
131 |
132 | $(document).ready(function() {
133 | corona.supportsTransactions(function(supportsTransactions) {
134 | module("Transaction Management");
135 | // Start a new transaction
136 | corona.startTransaction(supportsTransactions, function(transactionID) {
137 | // Load a document in that transaction and see if it's visible inside the transaction
138 | var uri = "/transactions/" + transactionID + ".json";
139 | corona.loadDocument({"transactionDoc": "txtest"}, uri, transactionID, function() {
140 | corona.docExists(uri, transactionID, true, function() {
141 | // Rollback the transaction and make sure the doc doesn't exist
142 | corona.rollbackTransaction(transactionID, function() {
143 | corona.docExists(uri, undefined, false, function() {});
144 |
145 | // Start another new transaction
146 | corona.startTransaction(supportsTransactions, function(transactionID) {
147 | var uri = "/transactions/" + transactionID + ".json";
148 | // Load a document under that transaction and make sure it isn't visible outside of the transaction
149 | corona.loadDocument({"transactionDoc": "txtest"}, uri, transactionID, function() {
150 | corona.docExists(uri, undefined, false, function() {
151 | // Commit the transaction and make sure the doc is visible
152 | corona.commitTransaction(transactionID, function() {
153 | window.setTimeout(function() {
154 | corona.docExists(uri, undefined, true, function() {});
155 | }, 1000);
156 | });
157 | });
158 | });
159 | });
160 | });
161 | });
162 | });
163 | });
164 | });
165 | });
166 |
--------------------------------------------------------------------------------
/test/kvquery.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | mjson qunit tests
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | test markup, will be hidden
17 |
18 |
19 |
--------------------------------------------------------------------------------
/test/load.pl:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 |
3 | use File::Basename;
4 | use LWP::UserAgent;
5 | use File::Slurp;
6 |
7 | my $gzipFile = shift;
8 |
9 | my $extractInto = dirname($gzipFile);
10 |
11 | print "Extracting files...";
12 | `tar -zxvf $gzipFile -C $extractInto`;
13 | print "finished\n";
14 |
15 | opendir(my $extractDH, $extractInto);
16 |
17 | my $ua = LWP::UserAgent->new;
18 | $ua->agent("corona test loader");
19 |
20 | my $i = 1;
21 | while(my $file = readdir $extractDH) {
22 | if($i % 100 == 0) {
23 | print "Loaded $i documents\n";
24 | }
25 |
26 | if($file =~ /\.json$/) {
27 | my $req = HTTP::Request->new(PUT => "http://localhost:8100/json/store/$file");
28 | my $content = read_file($extractInto . "/" . $file);
29 | $req->content($content);
30 |
31 | my $res = $ua->request($req);
32 | if($res->is_success) {
33 | unlink $extractInto . "/" . $file;
34 | }
35 | else {
36 | print "Error: ", $res->status_line, "\n";
37 | }
38 | $i++;
39 | }
40 | if($file =~ /\.xml$/) {
41 | my $req = HTTP::Request->new(PUT => "http://localhost:8100/xml/store/$file");
42 | my $content = read_file($extractInto . "/" . $file);
43 | $req->content($content);
44 |
45 | my $res = $ua->request($req);
46 | if($res->is_success) {
47 | unlink $extractInto . "/" . $file;
48 | }
49 | else {
50 | print "Error: ", $res->status_line, "\n";
51 | }
52 | $i++;
53 | }
54 | }
55 |
56 | closedir($extractDH);
57 |
--------------------------------------------------------------------------------
/test/mljson.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | mjson qunit tests
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | test markup, will be hidden
17 |
18 |
19 |
--------------------------------------------------------------------------------
/test/named-query.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Named query qunit tests
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | test markup, will be hidden
17 |
18 |
19 |
--------------------------------------------------------------------------------
/test/path-parser.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | path parser qunit tests
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | test markup, will be hidden
17 |
18 |
19 |
--------------------------------------------------------------------------------
/test/schema.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Schema qunit tests
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | test markup, will be hidden
17 |
18 |
19 |
--------------------------------------------------------------------------------
/test/shapefile/loadStates.py:
--------------------------------------------------------------------------------
1 | import sys
2 | import shapefile
3 | import json
4 | import httplib
5 | import urllib
6 | import base64
7 |
8 | if (len(sys.argv) == 1):
9 | print " : "
10 | sys.exit(0)
11 |
12 | auth = 'Basic ' + base64.encodestring(sys.argv[3]).rstrip()
13 |
14 | conn = httplib.HTTPConnection("localhost", sys.argv[2])
15 | # conn.set_debuglevel(9)
16 | sf = shapefile.Reader(sys.argv[1])
17 |
18 | states = sf.records();
19 | shapes = sf.shapes();
20 |
21 | for x, state in enumerate(states):
22 | meta = {"abbreviation": state[5], "name": state[6],"center": {"latitude": float(state[12]), "longitude": float(state[13])} }
23 |
24 | polygon = []
25 | for point in shapes[x].points:
26 | polygon.append({"latitude": point[1], "longitude": point[0]})
27 |
28 | query = {"geo": sys.argv[4], "region": {"polygon":polygon}}
29 |
30 | url ="/namedquery/state:" + state[5]
31 | params = urllib.urlencode({"description": state[6], "structuredQuery": json.dumps(query)})
32 |
33 | print str(x + 1) + ": " + url
34 |
35 | conn.request("POST", url, params, {"Authorization": auth, "Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"})
36 | response = conn.getresponse()
37 |
38 | if response.status == 400:
39 | continue
40 |
41 | # print response.status, response.reason
42 |
--------------------------------------------------------------------------------
/test/shapefile/loadStatesXML.py:
--------------------------------------------------------------------------------
1 | import sys
2 | import shapefile
3 | import httplib
4 | import urllib
5 | import base64
6 |
7 | if (len(sys.argv) == 1):
8 | print " : "
9 | sys.exit(0)
10 |
11 | auth = 'Basic ' + base64.encodestring(sys.argv[3]).rstrip()
12 |
13 | conn = httplib.HTTPConnection("localhost", sys.argv[2])
14 | # conn.set_debuglevel(9)
15 | sf = shapefile.Reader(sys.argv[1])
16 |
17 | states = sf.records();
18 | shapes = sf.shapes();
19 |
20 | for x, state in enumerate(states):
21 | polygon = ""
22 | for point in shapes[x].points:
23 | polygon += "" + str(point[1]) + " " + str(point[0]) + " "
24 |
25 | query = "" + sys.argv[4] + " " + polygon + " "
26 |
27 | url ="/namedquery/state:" + state[5]
28 | params = urllib.urlencode({"description": state[6], "structuredQuery": query})
29 |
30 | print str(x + 1) + ": " + url
31 |
32 | conn.request("POST", url, params, {"Authorization": auth, "Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"})
33 | response = conn.getresponse()
34 |
35 | if response.status == 400:
36 | continue
37 |
38 | # print response.status, response.reason
39 |
--------------------------------------------------------------------------------
/test/shapefile/loadZips.py:
--------------------------------------------------------------------------------
1 | import sys
2 | import shapefile
3 | import json
4 | import httplib
5 | import urllib
6 | import base64
7 |
8 | if (len(sys.argv) == 1):
9 | print " : "
10 | sys.exit(0)
11 |
12 | auth = 'Basic ' + base64.encodestring(sys.argv[3]).rstrip()
13 |
14 | conn = httplib.HTTPConnection("localhost", sys.argv[2])
15 | # conn.set_debuglevel(9)
16 | sf = shapefile.Reader(sys.argv[1])
17 |
18 | zips = sf.records();
19 |
20 | for x, zipCode in enumerate(zips):
21 | polygon = []
22 | shape = sf.shape(x)
23 | for point in shape.points:
24 | polygon.append({"latitude": point[1], "longitude": point[0]})
25 |
26 | query = {"geo": sys.argv[4], "region": {"polygon":polygon}}
27 |
28 | url ="/namedquery/zip:" + zipCode[0]
29 | params = urllib.urlencode({"structuredQuery": json.dumps(query)})
30 |
31 | print str(x + 1) + ": " + url
32 |
33 | conn.request("POST", url, params, {"Authorization": auth, "Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"})
34 | response = conn.getresponse()
35 |
36 | if response.status == 400:
37 | continue
38 |
39 | # print response.status, response.reason
40 |
--------------------------------------------------------------------------------
/test/shapefile/loadZipsXML.py:
--------------------------------------------------------------------------------
1 | import sys
2 | import shapefile
3 | import httplib
4 | import urllib
5 | import base64
6 |
7 | if (len(sys.argv) == 1):
8 | print " : "
9 | sys.exit(0)
10 |
11 | auth = 'Basic ' + base64.encodestring(sys.argv[3]).rstrip()
12 |
13 | conn = httplib.HTTPConnection("localhost", sys.argv[2])
14 | # conn.set_debuglevel(9)
15 | sf = shapefile.Reader(sys.argv[1])
16 |
17 | zips = sf.records();
18 |
19 | for x, zipCode in enumerate(zips):
20 | polygon = ""
21 | shape = sf.shape(x)
22 | for point in shape.points:
23 | polygon += "" + str(point[1]) + " " + str(point[0]) + " "
24 |
25 | query = "" + sys.argv[4] + " " + polygon + " "
26 |
27 | url ="/namedquery/zip:" + zipCode[0]
28 | params = urllib.urlencode({"structuredQuery": query})
29 |
30 | print str(x + 1) + ": " + url
31 |
32 | conn.request("POST", url, params, {"Authorization": auth, "Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"})
33 | response = conn.getresponse()
34 |
35 | if response.status == 400:
36 | continue
37 |
38 | # print response.status, response.reason
39 |
--------------------------------------------------------------------------------
/test/shapefile/shapefile.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marklogic-community/Corona/a5178fccc91a5e68e98e9dfb56587329a6f7dd10/test/shapefile/shapefile.pyc
--------------------------------------------------------------------------------
/test/store.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | mjson qunit tests
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | test markup, will be hidden
17 |
18 |
19 |
--------------------------------------------------------------------------------
/test/string-query-parser.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | String query parser qunit tests
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | test markup, will be hidden
17 |
18 |
19 |
--------------------------------------------------------------------------------
/test/string-query.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | mjson qunit tests
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | test markup, will be hidden
17 |
18 |
19 |
--------------------------------------------------------------------------------
/test/structured-query-parser.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Structured query parser qunit tests
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | test markup, will be hidden
17 |
18 |
19 |
--------------------------------------------------------------------------------
/test/structured-query.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | mjson qunit tests
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | test markup, will be hidden
17 |
18 |
19 |
--------------------------------------------------------------------------------
/test/transactions.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Transaction tests
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | test markup, will be hidden
17 |
18 |
19 |
--------------------------------------------------------------------------------
/test/xq/array-construction.xqy:
--------------------------------------------------------------------------------
1 | (:
2 | Copyright 2011 MarkLogic Corporation
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | :)
16 |
17 | xquery version "1.0-ml";
18 |
19 | import module namespace json = "http://marklogic.com/json" at "/corona/lib/json.xqy";
20 |
21 |
22 | let $doc := json:document(
23 | json:array((
24 | 1,
25 | 1.2,
26 | true(),
27 | false(),
28 | json:null(),
29 | json:array(),
30 | json:object((
31 | "foo", "bar"
32 | ))
33 | ))
34 | )
35 |
36 | return json:serialize($doc)
37 |
--------------------------------------------------------------------------------
/test/xq/isomorphic.xqy:
--------------------------------------------------------------------------------
1 | (:
2 | Copyright 2011 MarkLogic Corporation
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | :)
16 |
17 | xquery version "1.0-ml";
18 |
19 | import module namespace json = "http://marklogic.com/json" at "/corona/lib/json.xqy";
20 |
21 |
22 | try {
23 | json:serialize(json:parse(xdmp:get-request-field("json")))
24 | }
25 | catch ($e) {
26 | xdmp:set-response-code(500, string($e//*:message))
27 | }
28 |
--------------------------------------------------------------------------------
/test/xq/object-construction-dup-keys.xqy:
--------------------------------------------------------------------------------
1 | (:
2 | Copyright 2011 MarkLogic Corporation
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | :)
16 |
17 | xquery version "1.0-ml";
18 |
19 | import module namespace json = "http://marklogic.com/json" at "/corona/lib/json.xqy";
20 |
21 |
22 | let $doc := json:document(
23 | json:object((
24 | "foo", "bar",
25 | "foo", "baz"
26 | ))
27 | )
28 |
29 | return json:serialize($doc)
30 |
--------------------------------------------------------------------------------
/test/xq/object-construction.xqy:
--------------------------------------------------------------------------------
1 | (:
2 | Copyright 2011 MarkLogic Corporation
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | :)
16 |
17 | xquery version "1.0-ml";
18 |
19 | import module namespace json = "http://marklogic.com/json" at "/corona/lib/json.xqy";
20 |
21 |
22 | let $doc := json:document(
23 | json:object((
24 | "intvalue", 1,
25 | "floatvalue", 1.2,
26 | "boolvalue", true(),
27 | "nullvalue", json:null(),
28 | "arrayvalue", json:array((1, 2, 3)),
29 | "objectvalue", json:object(("foo", "bar")),
30 | "datevalue::date", json:date("July 8th, 2011"),
31 | "xmlvalue::xml", json:xml( ),
32 | "notrailingvalue"
33 | ))
34 | )
35 |
36 | return json:serialize($doc)
37 |
--------------------------------------------------------------------------------
/test/xq/parse-string-query.xqy:
--------------------------------------------------------------------------------
1 | import module namespace stringquery="http://marklogic.com/corona/string-query" at "/corona/lib/string-query.xqy";
2 |
3 | declare option xdmp:mapping "false";
4 |
5 | try {
6 | normalize-space(replace(xdmp:quote({ stringquery:parse(xdmp:get-request-field("stringQuery"), xdmp:get-request-field("language"), (), false()) } /*), "\n", ""))
7 | }
8 | catch ($e) {
9 | xdmp:log($e),
10 | string($e/*:message)
11 | }
12 |
--------------------------------------------------------------------------------
/test/xq/parse-structured-query.xqy:
--------------------------------------------------------------------------------
1 | import module namespace structquery="http://marklogic.com/corona/structured-query" at "/corona/lib/structured-query.xqy";
2 |
3 | declare option xdmp:mapping "false";
4 |
5 | try {
6 | normalize-space(replace(xdmp:quote({ structquery:getCTS(structquery:getParseTree(xdmp:get-request-field("q")), xdmp:get-request-field("ignoreRange"), false()) } /*), "\n", ""))
7 | }
8 | catch ($e) {
9 | xdmp:log($e),
10 | string($e/*:message)
11 | }
12 |
--------------------------------------------------------------------------------
/test/xq/parsedate.xqy:
--------------------------------------------------------------------------------
1 | import module namespace dateparser="http://marklogic.com/dateparser" at "/corona/lib/date-parser.xqy";
2 |
3 | dateparser:parse(xdmp:get-request-field("date"))
4 |
--------------------------------------------------------------------------------
/test/xq/parsepath.xqy:
--------------------------------------------------------------------------------
1 | import module namespace path="http://marklogic.com/mljson/path-parser" at "/corona/lib/path-parser.xqy";
2 |
3 | declare option xdmp:mapping "false";
4 |
5 | try {
6 | path:parse(xdmp:get-request-field("path"), xdmp:get-request-field("type"))
7 | }
8 | catch ($e) {
9 | xdmp:log($e),
10 | string($e/*:message)
11 | }
12 |
--------------------------------------------------------------------------------