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