Commit 17d394dd authored by Hardik Juneja's avatar Hardik Juneja

add new type multiEqual for multimapping

parent 9bb5cdfc
......@@ -36,15 +36,24 @@
return new_mapping_dict;
}
if (_mapping_dict[key].multiEqual !== undefined) {
new_mapping_dict = {
multiEqualArray: _mapping_dict[key].multiEqual,
match_value: key
};
return new_mapping_dict;
}
if (key === "switch") {
//xx: assuming switch is just used in case of value
new_mapping_dict['switch'] = {};
new_mapping_dict['switch'].regexps = [];
new_mapping_dict['switch'].multiEqual = [];
for (new_key in _mapping_dict['switch']) {
if (_mapping_dict['switch'].hasOwnProperty(new_key)) {
new_kv = inverseMappingDict(_mapping_dict['switch'], new_key);
new_key = Object.keys(new_kv)[0];
if (new_key === "regexp") {
if (new_key === "regexp" || new_key === "multiEqualArray") {
new_mapping_dict['switch'].regexps.push(new_kv);
} else {
new_mapping_dict['switch'][new_key] = new_kv[new_key];
......@@ -181,10 +190,12 @@
});
}
function mapProperty(_mapping_dict, key, value, for_value) {
function mapProperty(_mapping_dict, key, value, for_value, isQuery) {
var new_prop,
i,
k,
regexp,
equalityArray,
new_mapping_dict = {},
mapped_kv = {};
......@@ -248,6 +259,30 @@
return mapped_kv;
}
if (_mapping_dict.multiEqual !== undefined) {
if (_mapping_dict.multiEqual && _mapping_dict.multiEqual.length) {
for (i = 0; i < _mapping_dict.multiEqual.length; i = i + 1) {
equalityArray = _mapping_dict.multiEqual[i].multiEqualArray;
if (equalityArray === undefined) {
break;
}
for (k = 0; k < equalityArray.length; k = k + 1) {
if (value === equalityArray[k]) {
if (isQuery === true) {
isQuery = _mapping_dict.multiEqual;
}
mapped_kv.key = key;
mapped_kv.value = _mapping_dict.multiEqual[i].match_value;
return mapped_kv;
}
}
}
}
mapped_kv.key = key;
mapped_kv.value = _mapping_dict.default_value;
return mapped_kv;
}
if (_mapping_dict["switch"] !== undefined) {
if (_mapping_dict["switch"].hasOwnProperty(key)) {
return mapProperty(_mapping_dict['switch'][key], key, value, true);
......
......@@ -474,6 +474,52 @@
});
});
test("get with prop, value mapped using multiEqual and switch", function () {
stop();
expect(2);
var jio = jIO.createJIO({
type: "mapping",
sub_storage: {
type: "mappingstorage2713"
},
mapping_dict: {
"title": {
"equal": "someTitle",
"value": {
"switch": {
"foo": {
"multiEqual": ["otherFoo", "otherbar", "otherkoo"],
"default_value": "otherFoo"
},
"bar": {
"equal": "otherBar"
}
}
}
}
}
});
Storage2713.prototype.get = function (id) {
equal(id, "42", "get 2713 called");
return {"someTitle": "otherbar", "smth": "bar"};
};
jio.get("42")
.push(function (result) {
deepEqual(result, {
"title": "foo",
"smth": "bar"
});
}).push(undefined, function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
test("get with map_all_property", function () {
stop();
expect(3);
......@@ -911,6 +957,52 @@
start();
});
});
test("get with prop, value mapped using multiEqual and switch", function () {
stop();
expect(3);
var jio = jIO.createJIO({
type: "mapping",
sub_storage: {
type: "mappingstorage2713"
},
mapping_dict: {
"title": {
"equal": "someTitle",
"value": {
"switch": {
"foo": {
"multiEqual": ["otherFoo", "otherbar", "otherkoo"],
"default_value": "otherFoo"
},
"bar": {
"equal": "otherBar"
}
}
}
}
}
});
Storage2713.prototype.put = function (id, doc) {
deepEqual(doc,
{"someTitle": "otherFoo", "smth": "bar"}, "post 2713 called");
equal(id, "42", "put 2713 called");
return id;
};
jio.put("42", {"title": "foo", "smth": "bar"})
.push(function (result) {
equal(result, "42");
})
.push(undefined, function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
/////////////////////////////////////////////////////////////////
// mappingStorage.remove
/////////////////////////////////////////////////////////////////
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment