Use context for datasource 1/2

This commit is contained in:
Raul Ochoa 2016-05-23 19:09:57 +02:00
parent a11cc28dc7
commit e9d1951d48
5 changed files with 28 additions and 26 deletions

View File

@ -208,9 +208,10 @@ MapController.prototype.create = function(req, res, prepareConfigFn) {
}
);
},
function createLayergroup(err, requestMapConfig, datasource) {
function createLayergroup(err, requestMapConfig) {
assert.ifError(err);
mapConfig = new MapConfig(requestMapConfig, datasource || Datasource.EmptyDatasource());
var datasource = context.datasource || Datasource.EmptyDatasource();
mapConfig = new MapConfig(requestMapConfig, datasource);
self.mapBackend.createLayergroup(
mapConfig, req.params,
new CreateLayergroupMapConfigProvider(mapConfig, req.context.user, self.userLimitsApi, req.params),

View File

@ -100,8 +100,9 @@ MapConfigNamedLayersAdapter.prototype.getMapConfig = function (user, requestMapC
});
requestMapConfig.layers = layers;
context.datasource = datasourceBuilder.build();
return callback(null, requestMapConfig, datasourceBuilder.build());
return callback(null, requestMapConfig);
}
@ -119,7 +120,8 @@ MapConfigNamedLayersAdapter.prototype.getMapConfig = function (user, requestMapC
adaptLayersQueue.awaitAll(layersAdaptQueueFinish);
});
} else {
return callback(null, requestMapConfig, datasourceBuilder.build());
context.datasource = datasourceBuilder.build();
return callback(null, requestMapConfig);
}
};

View File

@ -166,15 +166,14 @@ NamedMapMapConfigProvider.prototype.getMapConfig = function(callback) {
}
);
},
function prepareContextLimits(err, _mapConfig, _datasource) {
function prepareContextLimits(err, _mapConfig) {
assert.ifError(err);
mapConfig = _mapConfig;
datasource = _datasource;
self.userLimitsApi.getRenderLimits(self.owner, this);
},
function cacheAndReturnMapConfig(err, renderLimits) {
self.err = err;
self.mapConfig = (mapConfig === null) ? null : new MapConfig(mapConfig, datasource);
self.mapConfig = (mapConfig === null) ? null : new MapConfig(mapConfig, context.datasource);
self.rendererParams = rendererParams;
self.context.limits = renderLimits || {};
return callback(self.err, self.mapConfig, self.rendererParams, self.context);

View File

@ -298,7 +298,7 @@ describe('named_layers datasources', function() {
var context = {};
mapConfigNamedLayersAdapter.getMapConfig(username, testScenario.config, params, context,
function(err, mapConfig, datasource) {
testScenario.test(err, mapConfig.layers, datasource, done);
testScenario.test(err, mapConfig.layers, context.datasource, done);
}
);
});

View File

@ -150,10 +150,10 @@ describe('mapconfig-named-layers-adapter', function() {
config: {}
});
mapConfigNamedLayersAdapter.getMapConfig(username, missingNamedMapLayerConfig, params, context,
function(err, mapConfig, datasource) {
function(err, mapConfig) {
assert.ok(err);
assert.ok(!mapConfig);
assert.ok(!datasource);
assert.ok(!context.datasource);
assert.equal(err.message, 'Missing Named Map `name` in layer options');
done();
@ -167,10 +167,10 @@ describe('mapconfig-named-layers-adapter', function() {
name: missingTemplateName
});
mapConfigNamedLayersAdapter.getMapConfig(username, nonExistentNamedMapLayerConfig, params, context,
function(err, mapConfig, datasource) {
function(err, mapConfig) {
assert.ok(err);
assert.ok(!mapConfig);
assert.ok(!datasource);
assert.ok(!context.datasource);
assert.equal(
err.message, "Template '" + missingTemplateName + "' of user '" + username + "' not found"
);
@ -190,10 +190,10 @@ describe('mapconfig-named-layers-adapter', function() {
name: tokenAuthTemplateName
});
mapConfigNamedLayersAdapter.getMapConfig(username, nonAuthTokensNamedMapLayerConfig, params, context,
function(err, mapConfig, datasource) {
function(err, mapConfig) {
assert.ok(err);
assert.ok(!mapConfig);
assert.ok(!datasource);
assert.ok(!context.datasource);
assert.equal(err.message, "Unauthorized '" + tokenAuthTemplateName + "' template instantiation");
templateMaps.delTemplate(username, tokenAuthTemplateName, done);
@ -212,10 +212,10 @@ describe('mapconfig-named-layers-adapter', function() {
name: nestedNamedMapTemplateName
});
mapConfigNamedLayersAdapter.getMapConfig(username, nestedNamedMapLayerConfig, params, context,
function(err, mapConfig, datasource) {
function(err, mapConfig) {
assert.ok(err);
assert.ok(!mapConfig);
assert.ok(!datasource);
assert.ok(!context.datasource);
assert.equal(err.message, 'Nested named layers are not allowed');
templateMaps.delTemplate(username, nestedNamedMapTemplateName, done);
@ -229,12 +229,12 @@ describe('mapconfig-named-layers-adapter', function() {
name: templateName
});
mapConfigNamedLayersAdapter.getMapConfig(username, validNamedMapMapLayerConfig, params, context,
function(err, mapConfig, datasource) {
function(err, mapConfig) {
assert.ok(!err);
var layers = mapConfig.layers;
assert.ok(layers.length, 1);
assert.ok(layers[0].type, 'cartodb');
assert.notEqual(datasource.getLayerDatasource(0), undefined);
assert.notEqual(context.datasource.getLayerDatasource(0), undefined);
done();
}
@ -252,11 +252,11 @@ describe('mapconfig-named-layers-adapter', function() {
auth_tokens: ['valid1']
});
mapConfigNamedLayersAdapter.getMapConfig(username, validAuthTokensNamedMapLayerConfig, params, context,
function(err, mapConfig, datasource) {
function(err, mapConfig) {
assert.ok(!err);
var layers = mapConfig.layers;
assert.equal(layers.length, 1);
assert.notEqual(datasource.getLayerDatasource(0), undefined);
assert.notEqual(context.datasource.getLayerDatasource(0), undefined);
templateMaps.delTemplate(username, tokenAuthTemplateName, done);
}
@ -275,18 +275,18 @@ describe('mapconfig-named-layers-adapter', function() {
auth_tokens: ['valid2']
});
mapConfigNamedLayersAdapter.getMapConfig(username, multipleLayersNamedMapLayerConfig, params, context,
function(err, mapConfig, datasource) {
function(err, mapConfig) {
assert.ok(!err);
var layers = mapConfig.layers;
assert.equal(layers.length, 2);
assert.equal(layers[0].type, 'mapnik');
assert.equal(layers[0].options.cartocss, '#layer { polygon-fill: green; }');
assert.notEqual(datasource.getLayerDatasource(0), undefined);
assert.notEqual(context.datasource.getLayerDatasource(0), undefined);
assert.equal(layers[1].type, 'cartodb');
assert.equal(layers[1].options.cartocss, '#layer { marker-fill: red; }');
assert.notEqual(datasource.getLayerDatasource(1), undefined);
assert.notEqual(context.datasource.getLayerDatasource(1), undefined);
templateMaps.delTemplate(username, multipleLayersTemplateName, done);
}
@ -312,18 +312,18 @@ describe('mapconfig-named-layers-adapter', function() {
auth_tokens: ['valid2']
});
mapConfigNamedLayersAdapter.getMapConfig(username, multipleLayersNamedMapLayerConfig, params, context,
function(err, mapConfig, datasource) {
function(err, mapConfig) {
assert.ok(!err);
var layers = mapConfig.layers;
assert.equal(layers.length, 2);
assert.equal(layers[0].type, 'mapnik');
assert.equal(layers[0].options.cartocss, '#layer { polygon-fill: ' + polygonColor + '; }');
assert.notEqual(datasource.getLayerDatasource(0), undefined);
assert.notEqual(context.datasource.getLayerDatasource(0), undefined);
assert.equal(layers[1].type, 'cartodb');
assert.equal(layers[1].options.cartocss, '#layer { marker-fill: ' + color + '; }');
assert.notEqual(datasource.getLayerDatasource(1), undefined);
assert.notEqual(context.datasource.getLayerDatasource(1), undefined);
templateMaps.delTemplate(username, multipleLayersTemplateName, done);
}