Named maps adapter with getMapConfig interface
This commit is contained in:
parent
3e35604df0
commit
9f6ce64a31
@ -175,15 +175,12 @@ MapController.prototype.create = function(req, res, prepareConfigFn) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
analysesResults = _analysesResults;
|
||||
self.namedLayersAdapter.getLayers(req.context.user, requestMapConfig.layers, self.pgConnection,
|
||||
function(err, layers, datasource) {
|
||||
self.namedLayersAdapter.getMapConfig(req.context.user, requestMapConfig, self.pgConnection,
|
||||
function(err, requestMapConfig, datasource) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if (layers) {
|
||||
requestMapConfig.layers = layers;
|
||||
}
|
||||
return next(null, requestMapConfig, datasource);
|
||||
}
|
||||
);
|
||||
|
@ -8,11 +8,13 @@ function MapConfigNamedLayersAdapter(templateMaps) {
|
||||
|
||||
module.exports = MapConfigNamedLayersAdapter;
|
||||
|
||||
MapConfigNamedLayersAdapter.prototype.getLayers = function(username, layers, dbMetadata, callback) {
|
||||
MapConfigNamedLayersAdapter.prototype.getMapConfig = function(username, requestMapConfig, dbMetadata, callback) {
|
||||
var self = this;
|
||||
|
||||
var layers = requestMapConfig.layers;
|
||||
|
||||
if (!layers) {
|
||||
return callback(null);
|
||||
return callback(null, requestMapConfig);
|
||||
}
|
||||
|
||||
var adaptLayersQueue = queue(layers.length);
|
||||
@ -96,7 +98,9 @@ MapConfigNamedLayersAdapter.prototype.getLayers = function(username, layers, dbM
|
||||
|
||||
});
|
||||
|
||||
return callback(null, layers, datasourceBuilder.build());
|
||||
requestMapConfig.layers = layers;
|
||||
|
||||
return callback(null, requestMapConfig, datasourceBuilder.build());
|
||||
}
|
||||
|
||||
|
||||
@ -114,7 +118,7 @@ MapConfigNamedLayersAdapter.prototype.getLayers = function(username, layers, dbM
|
||||
adaptLayersQueue.awaitAll(layersAdaptQueueFinish);
|
||||
});
|
||||
} else {
|
||||
return callback(null, layers, datasourceBuilder.build());
|
||||
return callback(null, requestMapConfig, datasourceBuilder.build());
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -131,15 +131,12 @@ NamedMapMapConfigProvider.prototype.getMapConfig = function(callback) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
self.analysesResults = analysesResults || [];
|
||||
self.namedLayersAdapter.getLayers(self.owner, _mapConfig.layers, self.pgConnection,
|
||||
function(err, layers, datasource) {
|
||||
self.namedLayersAdapter.getMapConfig(self.owner, _mapConfig, self.pgConnection,
|
||||
function(err, _mapConfig, datasource) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if (layers) {
|
||||
_mapConfig.layers = layers;
|
||||
}
|
||||
return next(null, _mapConfig, datasource);
|
||||
}
|
||||
);
|
||||
|
@ -294,9 +294,9 @@ describe('named_layers datasources', function() {
|
||||
|
||||
testScenarios.forEach(function(testScenario) {
|
||||
it('should return a list of layers ' + testScenario.desc, function(done) {
|
||||
mapConfigNamedLayersAdapter.getLayers(username, testScenario.config.layers, pgConnection,
|
||||
function(err, layers, datasource) {
|
||||
testScenario.test(err, layers, datasource, done);
|
||||
mapConfigNamedLayersAdapter.getMapConfig(username, testScenario.config, pgConnection,
|
||||
function(err, mapConfig, datasource) {
|
||||
testScenario.test(err, mapConfig.layers, datasource, done);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
@ -147,10 +147,10 @@ describe('mapconfig-named-layers-adapter', function() {
|
||||
var missingNamedMapLayerConfig = makeNamedMapLayerConfig({
|
||||
config: {}
|
||||
});
|
||||
mapConfigNamedLayersAdapter.getLayers(username, missingNamedMapLayerConfig.layers, pgConnection,
|
||||
function(err, layers, datasource) {
|
||||
mapConfigNamedLayersAdapter.getMapConfig(username, missingNamedMapLayerConfig, pgConnection,
|
||||
function(err, mapConfig, datasource) {
|
||||
assert.ok(err);
|
||||
assert.ok(!layers);
|
||||
assert.ok(!mapConfig);
|
||||
assert.ok(!datasource);
|
||||
assert.equal(err.message, 'Missing Named Map `name` in layer options');
|
||||
|
||||
@ -164,10 +164,10 @@ describe('mapconfig-named-layers-adapter', function() {
|
||||
var nonExistentNamedMapLayerConfig = makeNamedMapLayerConfig({
|
||||
name: missingTemplateName
|
||||
});
|
||||
mapConfigNamedLayersAdapter.getLayers(username, nonExistentNamedMapLayerConfig.layers, pgConnection,
|
||||
function(err, layers, datasource) {
|
||||
mapConfigNamedLayersAdapter.getMapConfig(username, nonExistentNamedMapLayerConfig, pgConnection,
|
||||
function(err, mapConfig, datasource) {
|
||||
assert.ok(err);
|
||||
assert.ok(!layers);
|
||||
assert.ok(!mapConfig);
|
||||
assert.ok(!datasource);
|
||||
assert.equal(
|
||||
err.message, "Template '" + missingTemplateName + "' of user '" + username + "' not found"
|
||||
@ -187,10 +187,10 @@ describe('mapconfig-named-layers-adapter', function() {
|
||||
var nonAuthTokensNamedMapLayerConfig = makeNamedMapLayerConfig({
|
||||
name: tokenAuthTemplateName
|
||||
});
|
||||
mapConfigNamedLayersAdapter.getLayers(username, nonAuthTokensNamedMapLayerConfig.layers, pgConnection,
|
||||
function(err, layers, datasource) {
|
||||
mapConfigNamedLayersAdapter.getMapConfig(username, nonAuthTokensNamedMapLayerConfig, pgConnection,
|
||||
function(err, mapConfig, datasource) {
|
||||
assert.ok(err);
|
||||
assert.ok(!layers);
|
||||
assert.ok(!mapConfig);
|
||||
assert.ok(!datasource);
|
||||
assert.equal(err.message, "Unauthorized '" + tokenAuthTemplateName + "' template instantiation");
|
||||
|
||||
@ -209,10 +209,10 @@ describe('mapconfig-named-layers-adapter', function() {
|
||||
var nestedNamedMapLayerConfig = makeNamedMapLayerConfig({
|
||||
name: nestedNamedMapTemplateName
|
||||
});
|
||||
mapConfigNamedLayersAdapter.getLayers(username, nestedNamedMapLayerConfig.layers, pgConnection,
|
||||
function(err, layers, datasource) {
|
||||
mapConfigNamedLayersAdapter.getMapConfig(username, nestedNamedMapLayerConfig, pgConnection,
|
||||
function(err, mapConfig, datasource) {
|
||||
assert.ok(err);
|
||||
assert.ok(!layers);
|
||||
assert.ok(!mapConfig);
|
||||
assert.ok(!datasource);
|
||||
assert.equal(err.message, 'Nested named layers are not allowed');
|
||||
|
||||
@ -226,9 +226,10 @@ describe('mapconfig-named-layers-adapter', function() {
|
||||
var validNamedMapMapLayerConfig = makeNamedMapLayerConfig({
|
||||
name: templateName
|
||||
});
|
||||
mapConfigNamedLayersAdapter.getLayers(username, validNamedMapMapLayerConfig.layers, pgConnection,
|
||||
function(err, layers, datasource) {
|
||||
mapConfigNamedLayersAdapter.getMapConfig(username, validNamedMapMapLayerConfig, pgConnection,
|
||||
function(err, mapConfig, datasource) {
|
||||
assert.ok(!err);
|
||||
var layers = mapConfig.layers;
|
||||
assert.ok(layers.length, 1);
|
||||
assert.ok(layers[0].type, 'cartodb');
|
||||
assert.notEqual(datasource.getLayerDatasource(0), undefined);
|
||||
@ -248,9 +249,10 @@ describe('mapconfig-named-layers-adapter', function() {
|
||||
name: tokenAuthTemplateName,
|
||||
auth_tokens: ['valid1']
|
||||
});
|
||||
mapConfigNamedLayersAdapter.getLayers(username, validAuthTokensNamedMapLayerConfig.layers, pgConnection,
|
||||
function(err, layers, datasource) {
|
||||
mapConfigNamedLayersAdapter.getMapConfig(username, validAuthTokensNamedMapLayerConfig, pgConnection,
|
||||
function(err, mapConfig, datasource) {
|
||||
assert.ok(!err);
|
||||
var layers = mapConfig.layers;
|
||||
assert.equal(layers.length, 1);
|
||||
assert.notEqual(datasource.getLayerDatasource(0), undefined);
|
||||
|
||||
@ -270,9 +272,10 @@ describe('mapconfig-named-layers-adapter', function() {
|
||||
name: multipleLayersTemplateName,
|
||||
auth_tokens: ['valid2']
|
||||
});
|
||||
mapConfigNamedLayersAdapter.getLayers(username, multipleLayersNamedMapLayerConfig.layers, pgConnection,
|
||||
function(err, layers, datasource) {
|
||||
mapConfigNamedLayersAdapter.getMapConfig(username, multipleLayersNamedMapLayerConfig, pgConnection,
|
||||
function(err, mapConfig, datasource) {
|
||||
assert.ok(!err);
|
||||
var layers = mapConfig.layers;
|
||||
assert.equal(layers.length, 2);
|
||||
|
||||
assert.equal(layers[0].type, 'mapnik');
|
||||
@ -306,9 +309,10 @@ describe('mapconfig-named-layers-adapter', function() {
|
||||
},
|
||||
auth_tokens: ['valid2']
|
||||
});
|
||||
mapConfigNamedLayersAdapter.getLayers(username, multipleLayersNamedMapLayerConfig.layers, pgConnection,
|
||||
function(err, layers, datasource) {
|
||||
mapConfigNamedLayersAdapter.getMapConfig(username, multipleLayersNamedMapLayerConfig, pgConnection,
|
||||
function(err, mapConfig, datasource) {
|
||||
assert.ok(!err);
|
||||
var layers = mapConfig.layers;
|
||||
assert.equal(layers.length, 2);
|
||||
|
||||
assert.equal(layers[0].type, 'mapnik');
|
||||
|
Loading…
Reference in New Issue
Block a user