Get affected tables and add it to the layergroup

This commit is contained in:
Mario de Frutos 2017-03-10 11:40:48 +01:00
parent 4d82fd65f6
commit 5e4d1d5c1c
2 changed files with 39 additions and 0 deletions

View File

@ -115,6 +115,7 @@ AnalysisMapConfigAdapter.prototype.getMapConfig = function(user, requestMapConfi
} }
layer.options.sql = analysisSql; layer.options.sql = analysisSql;
layer.options.columns = getDataviewsColumns(getLayerDataviews(layer, dataviews)); layer.options.columns = getDataviewsColumns(getLayerDataviews(layer, dataviews));
layer.options.affected_tables = getAllAffectedTablesFromSourceNodes(layerNode);
} else { } else {
missingNodesErrors.push( missingNodesErrors.push(
new Error('Missing analysis node.id="' + layerSourceId +'" for layer='+layerIndex) new Error('Missing analysis node.id="' + layerSourceId +'" for layer='+layerIndex)
@ -330,4 +331,12 @@ function AnalysisError(message) {
this.message = message; this.message = message;
} }
function getAllAffectedTablesFromSourceNodes(node) {
var affectedTables = [];
var affectedTables = node.getAllInputNodes(function (node) {
return node.getType() === 'source';
}).reduce(function(list, node) { return list.concat(node.getAffectedTables()); },[]);
return affectedTables;
}
require('util').inherits(AnalysisError, Error); require('util').inherits(AnalysisError, Error);

View File

@ -146,6 +146,36 @@ describe('analysis-layers', function() {
}); });
}); });
it('should have empty affected tables if it has only "source" node', function(done) {
var useCase = useCases[0];
var testClient = new TestClient(useCase.mapConfig, 1234);
testClient.getLayergroup(function(err, layergroupResult) {
assert.ok(!err, err);
var affected_tables = layergroupResult.metadata.layers[0].meta.affected_tables;
assert.equal(affected_tables.length, 0);
testClient.drain(done);
});
});
it('should have empty affected tables if it has a node other than "source"', function(done) {
var useCase = useCases[1];
var testClient = new TestClient(useCase.mapConfig, 1234);
testClient.getLayergroup(function(err, layergroupResult) {
assert.ok(!err, err);
var affected_tables = layergroupResult.metadata.layers[0].meta.affected_tables;
assert.equal(affected_tables[0], 'public.populated_places_simple_reduced');
testClient.drain(done);
});
});
it('should NOT fail for non-authenticated requests when it is just source', function(done) { it('should NOT fail for non-authenticated requests when it is just source', function(done) {
var useCase = useCases[0]; var useCase = useCases[0];