Commit fd386848 authored by Aurélien Vermylen's avatar Aurélien Vermylen

Changes to Automatic Storage to be used on Specific

Automatic Message type (instead of Document) and some
bugfixes
parent 191ed5ef
...@@ -14539,8 +14539,8 @@ return new Parser; ...@@ -14539,8 +14539,8 @@ return new Parser;
'reference': '/' + user_id + path, 'reference': '/' + user_id + path,
'id': '/' + user_id + path, 'id': '/' + user_id + path,
'type': type, 'type': type,
'started_at': dat.started_at || null, 'start_date': dat.started_at || null,
'ended_at': dat.ended_at || null, 'stop_date': dat.ended_at || null,
'automatic_user': user_id 'automatic_user': user_id
}; };
result.push(temp); result.push(temp);
...@@ -14698,6 +14698,8 @@ return new Parser; ...@@ -14698,6 +14698,8 @@ return new Parser;
return self._cache.get(id); return self._cache.get(id);
}).push(function () { }).push(function () {
return self._cache.put(id, doc); return self._cache.put(id, doc);
}, function () {
return;
}); });
}; };
...@@ -14705,13 +14707,9 @@ return new Parser; ...@@ -14705,13 +14707,9 @@ return new Parser;
return; return;
}; };
AutomaticAPIStorage.prototype.remove = function (id) { AutomaticAPIStorage.prototype.remove = function () {
var self = this; // Must do nothing to be able to use with use_remote_post!
return new RSVP.Queue().push(function () { return;
return self._cache.get(id);
}).push(function () {
return self._cache.remove(id);
});
}; };
AutomaticAPIStorage.prototype.getAttachment = function (id, name, options) { AutomaticAPIStorage.prototype.getAttachment = function (id, name, options) {
...@@ -14750,6 +14748,8 @@ return new Parser; ...@@ -14750,6 +14748,8 @@ return new Parser;
return self._cache.get(id); return self._cache.get(id);
}).push(function () { }).push(function () {
return self._cache.putAttachment(id, name, blob); return self._cache.putAttachment(id, name, blob);
}, function () {
return;
}); });
}; };
...@@ -14788,11 +14788,15 @@ return new Parser; ...@@ -14788,11 +14788,15 @@ return new Parser;
}; };
AutomaticAPIStorage.prototype.buildQuery = function (options) { AutomaticAPIStorage.prototype.buildQuery = function (options) {
var parsed_query = jIO.QueryFactory.create(options.query), var parsed_query = jIO.QueryFactory.create(options.query ||
'type:="trip"'),
key_list, key_list,
automatic_filters = {}, automatic_filters = {},
simplequery_type_value, simplequery_type_value,
intercept_keys = ['started_at', 'ended_at', 'user', 'vehicle'], intercept_keys = ['start_date', 'stop_date', 'automatic_user',
'vehicle'],
intercept_keys_automatic_name = ['started_at', 'ended_at', 'user',
'vehicle'],
intercept_accepted_operators = [['>', '>=', '<', '<='], intercept_accepted_operators = [['>', '>=', '<', '<='],
['>', '>=', '<', '<='], ['='], ['=']], ['>', '>=', '<', '<='], ['='], ['=']],
temp_operator_index, temp_operator_index,
...@@ -14801,8 +14805,6 @@ return new Parser; ...@@ -14801,8 +14805,6 @@ return new Parser;
i, i,
j; j;
// remove query from the options
delete options.query;
// XXX: check if there is no built-in method to seek in queries for // XXX: check if there is no built-in method to seek in queries for
// specific keys... // specific keys...
function extractKeysFromQuery(quer) { function extractKeysFromQuery(quer) {
...@@ -14850,7 +14852,7 @@ return new Parser; ...@@ -14850,7 +14852,7 @@ return new Parser;
); );
if (temp_operator_index > -1) { if (temp_operator_index > -1) {
if (i < 2) { if (i < 2) {
temp_key = intercept_keys[i] + temp_key = intercept_keys_automatic_name[i] +
(temp_operator_index < 2 ? '__gte' : '__lte'); (temp_operator_index < 2 ? '__gte' : '__lte');
automatic_filters[temp_key] = (new Date( automatic_filters[temp_key] = (new Date(
simplequery_type_value[j][1] simplequery_type_value[j][1]
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -97,8 +97,8 @@ ...@@ -97,8 +97,8 @@
'reference': '/' + user_id + path, 'reference': '/' + user_id + path,
'id': '/' + user_id + path, 'id': '/' + user_id + path,
'type': type, 'type': type,
'started_at': dat.started_at || null, 'start_date': dat.started_at || null,
'ended_at': dat.ended_at || null, 'stop_date': dat.ended_at || null,
'automatic_user': user_id 'automatic_user': user_id
}; };
result.push(temp); result.push(temp);
...@@ -256,6 +256,8 @@ ...@@ -256,6 +256,8 @@
return self._cache.get(id); return self._cache.get(id);
}).push(function () { }).push(function () {
return self._cache.put(id, doc); return self._cache.put(id, doc);
}, function () {
return;
}); });
}; };
...@@ -263,13 +265,9 @@ ...@@ -263,13 +265,9 @@
return; return;
}; };
AutomaticAPIStorage.prototype.remove = function (id) { AutomaticAPIStorage.prototype.remove = function () {
var self = this; // Must do nothing to be able to use with use_remote_post!
return new RSVP.Queue().push(function () { return;
return self._cache.get(id);
}).push(function () {
return self._cache.remove(id);
});
}; };
AutomaticAPIStorage.prototype.getAttachment = function (id, name, options) { AutomaticAPIStorage.prototype.getAttachment = function (id, name, options) {
...@@ -308,6 +306,8 @@ ...@@ -308,6 +306,8 @@
return self._cache.get(id); return self._cache.get(id);
}).push(function () { }).push(function () {
return self._cache.putAttachment(id, name, blob); return self._cache.putAttachment(id, name, blob);
}, function () {
return;
}); });
}; };
...@@ -346,11 +346,15 @@ ...@@ -346,11 +346,15 @@
}; };
AutomaticAPIStorage.prototype.buildQuery = function (options) { AutomaticAPIStorage.prototype.buildQuery = function (options) {
var parsed_query = jIO.QueryFactory.create(options.query), var parsed_query = jIO.QueryFactory.create(options.query ||
'type:="trip"'),
key_list, key_list,
automatic_filters = {}, automatic_filters = {},
simplequery_type_value, simplequery_type_value,
intercept_keys = ['started_at', 'ended_at', 'user', 'vehicle'], intercept_keys = ['start_date', 'stop_date', 'automatic_user',
'vehicle'],
intercept_keys_automatic_name = ['started_at', 'ended_at', 'user',
'vehicle'],
intercept_accepted_operators = [['>', '>=', '<', '<='], intercept_accepted_operators = [['>', '>=', '<', '<='],
['>', '>=', '<', '<='], ['='], ['=']], ['>', '>=', '<', '<='], ['='], ['=']],
temp_operator_index, temp_operator_index,
...@@ -359,8 +363,6 @@ ...@@ -359,8 +363,6 @@
i, i,
j; j;
// remove query from the options
delete options.query;
// XXX: check if there is no built-in method to seek in queries for // XXX: check if there is no built-in method to seek in queries for
// specific keys... // specific keys...
function extractKeysFromQuery(quer) { function extractKeysFromQuery(quer) {
...@@ -408,7 +410,7 @@ ...@@ -408,7 +410,7 @@
); );
if (temp_operator_index > -1) { if (temp_operator_index > -1) {
if (i < 2) { if (i < 2) {
temp_key = intercept_keys[i] + temp_key = intercept_keys_automatic_name[i] +
(temp_operator_index < 2 ? '__gte' : '__lte'); (temp_operator_index < 2 ? '__gte' : '__lte');
automatic_filters[temp_key] = (new Date( automatic_filters[temp_key] = (new Date(
simplequery_type_value[j][1] simplequery_type_value[j][1]
......
...@@ -215,8 +215,8 @@ ...@@ -215,8 +215,8 @@
'reference': '/usertest/trip/T_randomtrip/', 'reference': '/usertest/trip/T_randomtrip/',
'id': '/usertest/trip/T_randomtrip/', 'id': '/usertest/trip/T_randomtrip/',
'type': 'trip', 'type': 'trip',
'started_at': null, 'start_date': null,
'ended_at': null, 'stop_date': null,
'automatic_user': 'usertest' 'automatic_user': 'usertest'
}, "Check single element type"); }, "Check single element type");
}) })
...@@ -469,7 +469,7 @@ ...@@ -469,7 +469,7 @@
} }
}); });
test("query started_at, ended_at taken into account", function () { test("query start_date, stop_date taken into account", function () {
var url; var url;
this.server.respond(function (xhr) { this.server.respond(function (xhr) {
if (xhr.url.indexOf('https://api.automatic.com/trip/') === -1) { if (xhr.url.indexOf('https://api.automatic.com/trip/') === -1) {
...@@ -481,7 +481,8 @@ ...@@ -481,7 +481,8 @@
'{"_metadata":{"count":1,"next":null,"previous":null},' + '{"_metadata":{"count":1,"next":null,"previous":null},' +
'"results":[{"id": "T_example", "started_at": "2017-06-17T16:45:41Z"' '"results":[{"id": "T_example", "started_at": "2017-06-17T16:45:41Z"'
+ ', "ended_at": "2017-06-17T16:46:38Z"' + + ', "ended_at": "2017-06-17T16:46:38Z"' +
', "url": "https://api.automatic.com/trip/T_example/"}]}'); ', "url": "https://api.automatic.com/trip/T_example/",' +
'"type": "trip"}]}');
return; return;
} }
xhr.respond(200, { "Content-Type": "application/json" }, xhr.respond(200, { "Content-Type": "application/json" },
...@@ -497,7 +498,7 @@ ...@@ -497,7 +498,7 @@
expect(4); expect(4);
this.jio.buildQuery({ this.jio.buildQuery({
query: 'started_at:>"2017-06-17T18:45:41Z" AND type:="trip"' query: 'start_date:>"2017-06-17T18:45:41Z" AND type:="trip"'
}) })
.then(function (result) { .then(function (result) {
deepEqual(result, [], "Check no result"); deepEqual(result, [], "Check no result");
...@@ -509,7 +510,7 @@ ...@@ -509,7 +510,7 @@
start(); start();
}); });
this.jio.buildQuery({ this.jio.buildQuery({
query: 'started_at:>"2017-06-17T14:45:41Z" AND type:="trip"' query: 'start_date:>"2017-06-17T14:45:41Z" AND type:="trip"'
}) })
.then(function (result) { .then(function (result) {
deepEqual(result, [{ deepEqual(result, [{
...@@ -517,8 +518,8 @@ ...@@ -517,8 +518,8 @@
'reference': '/0/trip/T_example/', 'reference': '/0/trip/T_example/',
'id': '/0/trip/T_example/', 'id': '/0/trip/T_example/',
'type': 'trip', 'type': 'trip',
'started_at': "2017-06-17T16:45:41Z", 'start_date': "2017-06-17T16:45:41Z",
'ended_at': "2017-06-17T16:46:38Z", 'stop_date': "2017-06-17T16:46:38Z",
'automatic_user': '0' 'automatic_user': '0'
}], "Check trip is returned in result"); }], "Check trip is returned in result");
}) })
...@@ -532,7 +533,7 @@ ...@@ -532,7 +533,7 @@
start(); start();
}); });
this.jio.buildQuery({ this.jio.buildQuery({
query: 'ended_at:>"2017-06-17T18:45:41Z" AND type:="trip"' query: 'stop_date:>"2017-06-17T18:45:41Z" AND type:="trip"'
}) })
.then(function (result) { .then(function (result) {
deepEqual(result, [], "Check no result"); deepEqual(result, [], "Check no result");
...@@ -547,7 +548,7 @@ ...@@ -547,7 +548,7 @@
start(); start();
}); });
this.jio.buildQuery({ this.jio.buildQuery({
query: 'ended_at:<"2017-06-17T18:45:41Z" AND type:="trip"' query: 'stop_date:<"2017-06-17T18:45:41Z" AND type:="trip"'
}) })
.then(function (result) { .then(function (result) {
deepEqual(result, [{ deepEqual(result, [{
...@@ -555,8 +556,8 @@ ...@@ -555,8 +556,8 @@
'reference': '/0/trip/T_example/', 'reference': '/0/trip/T_example/',
'id': '/0/trip/T_example/', 'id': '/0/trip/T_example/',
'type': 'trip', 'type': 'trip',
'started_at': "2017-06-17T16:45:41Z", 'start_date': "2017-06-17T16:45:41Z",
'ended_at': "2017-06-17T16:46:38Z", 'stop_date': "2017-06-17T16:46:38Z",
'automatic_user': '0' 'automatic_user': '0'
}], "Check trip is returned in result"); }], "Check trip is returned in result");
}) })
...@@ -606,8 +607,8 @@ ...@@ -606,8 +607,8 @@
'reference': '/0/vehicle/V_example/', 'reference': '/0/vehicle/V_example/',
'id': '/0/vehicle/V_example/', 'id': '/0/vehicle/V_example/',
'type': 'vehicle', 'type': 'vehicle',
'started_at': null, 'start_date': null,
'ended_at': null, 'stop_date': null,
'automatic_user': '0' 'automatic_user': '0'
}], "Check vehicle list is returned"); }], "Check vehicle list is returned");
}) })
...@@ -662,16 +663,16 @@ ...@@ -662,16 +663,16 @@
'reference': '/0/vehicle/V_example/', 'reference': '/0/vehicle/V_example/',
'id': '/0/vehicle/V_example/', 'id': '/0/vehicle/V_example/',
'type': 'vehicle', 'type': 'vehicle',
'started_at': null, 'start_date': null,
'ended_at': null, 'stop_date': null,
'automatic_user': '0' 'automatic_user': '0'
}, { }, {
'automatic_path': '/vehicle/V_example2/', 'automatic_path': '/vehicle/V_example2/',
'reference': '/0/vehicle/V_example2/', 'reference': '/0/vehicle/V_example2/',
'id': '/0/vehicle/V_example2/', 'id': '/0/vehicle/V_example2/',
'type': 'vehicle', 'type': 'vehicle',
'started_at': null, 'start_date': null,
'ended_at': null, 'stop_date': null,
'automatic_user': '0' 'automatic_user': '0'
}], "Check vehicle list is returned"); }], "Check vehicle list is returned");
}) })
......
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