Skip to content
This repository has been archived by the owner on Nov 10, 2022. It is now read-only.

Commit

Permalink
Can create mappings off of xml attributes.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryangrimm committed Aug 13, 2011
1 parent 6f0f235 commit 42c7f13
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 4 deletions.
1 change: 1 addition & 0 deletions config/endpoints.xqy
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ declare variable $endpoints:ENDPOINTS as element(rest:options) :=
<http method="POST">
<param name="key" required="false"/>
<param name="element" required="false"/>
<param name="attribute" required="false"/>
<param name="mode" required="true"/>
</http>
<http method="DELETE"/>
Expand Down
16 changes: 16 additions & 0 deletions data/lib/index-config.xqy
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ declare function config:setXMLMap(
prop:set(concat("index-", $name), concat("map/xmlelement/", $name, "/", $element, "/", $mode))
};

declare function config:setXMLMap(
$name as xs:string,
$element as xs:string,
$attribute as xs:string,
$mode as xs:string
) as empty-sequence()
{
prop:set(concat("index-", $name), concat("map/xmlattribute/", $name, "/", $element, "/", $attribute, "/", $mode))
};

declare function config:setJSONRange(
$name as xs:string,
$key as xs:string,
Expand Down Expand Up @@ -331,6 +341,12 @@ declare function config:get(
<element>{ $bits[4] }</element>,
<mode>{ $bits[5] }</mode>
)
else if($bits[2] = "xmlattribute")
then (
<element>{ $bits[4] }</element>,
<attribute>{ $bits[5] }</attribute>,
<mode>{ $bits[6] }</mode>
)
else ()
}
</index>
Expand Down
27 changes: 24 additions & 3 deletions data/lib/manage.xqy
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,20 @@ declare function manage:createXMLMap(
return config:setXMLMap($name, $element, $mode)
};

declare function manage:createXMLMap(
$name as xs:string,
$element as xs:string,
$attribute as xs:string,
$mode as xs:string
) as empty-sequence()
{
let $test := manage:validateIndexName($name)
let $test := manage:validateElementName($element)
let $test := manage:validateAttributeName($attribute)
let $test := manage:validateMode($mode)
return config:setXMLMap($name, $element, $attribute, $mode)
};

declare function manage:deleteMap(
$name as xs:string
) as empty-sequence()
Expand All @@ -154,16 +168,23 @@ declare function manage:getMap(
if($type = "json")
then json:object((
"name", $name,
"type", $type,
"key", string($index/key),
"mode", $mode
))
else json:object((
else if($type = "xmlelement")
then json:object((
"name", $name,
"element", string($index/element),
"mode", $mode
))
else if($type = "xmlattribute")
then json:object((
"name", $name,
"type", $type,
"element", string($index/element),
"attribute", string($index/attribute),
"mode", $mode
))
else ()
};

declare function manage:getAllMaps(
Expand Down
3 changes: 3 additions & 0 deletions data/manage/map.xqy
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ let $params := rest:process-request(endpoints:request("/data/manage/map.xqy"))
let $name := map:get($params, "name")
let $key := map:get($params, "key")
let $element := map:get($params, "element")
let $attribute := map:get($params, "attribute")
let $mode := map:get($params, "mode")
let $requestMethod := xdmp:get-request-method()

Expand All @@ -49,6 +50,8 @@ return
else try {
if(exists($key))
then manage:createJSONMap($name, $key, $mode)
else if(exists($element) and exists($attribute))
then manage:createXMLMap($name, $element, $attribute, $mode)
else if(exists($element))
then manage:createXMLMap($name, $element, $mode)
else ()
Expand Down
17 changes: 16 additions & 1 deletion test/js/indexmgmt-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,23 @@ mljson.addIndexes = function(callback) {
{
"type": "map",
"name": "map6",
"element": "testns:element1",
"attribute": "mapattr",
"mode": "equals",
"shouldSucceed": true,
"purpose": "XML contains map with valid namespace and attribute"
},
{
"type": "map",
"name": "map7",
"element": "invalidns:element1",
"mode": "equals",
"shouldSucceed": false,
"purpose": "XML contains map with invalid namespace"
},
{
"type": "map",
"name": "map7",
"name": "map8",
"key": "name1",
"mode": "invalidmode",
"shouldSucceed": false,
Expand Down Expand Up @@ -446,6 +455,9 @@ mljson.addIndexes = function(callback) {
if(config.element !== undefined) {
equals(config.element, server.element, "Index element matches");
}
if(config.attribute !== undefined) {
equals(config.attribute, server.attribute, "Index attribute matches");
}
equals(config.mode, server.mode, "Index mode matches");
}
else if(config.type === "range") {
Expand Down Expand Up @@ -631,6 +643,9 @@ mljson.addIndexes = function(callback) {
if(index.element !== undefined) {
data.element = index.element;
}
if(index.attribute !== undefined) {
data.attribute = index.attribute;
}
data.mode = index.mode;
}
else if(index.type === "field") {
Expand Down

0 comments on commit 42c7f13

Please sign in to comment.