From 52d1cd47db14b962103eca02cc505481cda32373 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Wed, 13 Dec 2017 19:24:17 +0100 Subject: [PATCH] Do not validate aggregation missing columns. It will fail afterwards in map validation --- .../aggregation/aggregation-map-config.js | 55 ------------------- .../adapter/aggregation-mapconfig-adapter.js | 11 +--- 2 files changed, 1 insertion(+), 65 deletions(-) diff --git a/lib/cartodb/models/aggregation/aggregation-map-config.js b/lib/cartodb/models/aggregation/aggregation-map-config.js index dfc52f60..e6524e3d 100644 --- a/lib/cartodb/models/aggregation/aggregation-map-config.js +++ b/lib/cartodb/models/aggregation/aggregation-map-config.js @@ -1,15 +1,8 @@ const MapConfig = require('windshaft').model.MapConfig; -const MISSING_AGGREGATION_COLUMNS = 'Missing columns in the aggregation. The map-config defines cartocss expressions,'+ -' interactivity fields or attributes that are not present in the aggregation'; - module.exports = class AggregationMapConfig extends MapConfig { constructor (config, datasource) { super(config, datasource); - - if (this._hasAggregationMissingColumns()) { - throw new Error(MISSING_AGGREGATION_COLUMNS); - } } isAggregationMapConfig () { @@ -38,52 +31,4 @@ module.exports = class AggregationMapConfig extends MapConfig { return aggregation !== undefined && (typeof aggregation === 'object' || typeof aggregation === 'boolean'); } - - validateAggregation () { - if (this._hasAggregationMissingColumns()) { - throw new Error(MISSING_AGGREGATION_COLUMNS); - } - } - - _hasAggregationMissingColumns () { - const layers = this.getLayers(); - - if (!this.isAggregationMapConfig()) { - return false; - } - - for (let index = 0; index < layers.length; index++) { - const aggregationColumns = this._getAggregationColumnsByLayer(index); - const layerColumns = this.getColumnsByLayer(index); - - if (layerColumns.length === 0) { - continue; - } - - if (aggregationColumns.length !== layerColumns.length) { - return true; - } - - const missingColumns = this._getMissingColumns(aggregationColumns, layerColumns); - - if (missingColumns.length > 0) { - return true; - } - } - - return false; - } - - _getMissingColumns (aggregationColumns, layerColumns) { - return aggregationColumns.filter(column => !layerColumns.includes(column)); - } - - _getAggregationColumnsByLayer (index) { - const { aggregation } = this.getLayer(index).options; - const hasAggregationColumns = aggregation !== undefined && - typeof aggregation !== 'boolean' && - typeof aggregation.columns === 'object'; - - return hasAggregationColumns ? Object.keys(aggregation.columns) : []; - } }; diff --git a/lib/cartodb/models/mapconfig/adapter/aggregation-mapconfig-adapter.js b/lib/cartodb/models/mapconfig/adapter/aggregation-mapconfig-adapter.js index a9a24c0e..a94ba21e 100644 --- a/lib/cartodb/models/mapconfig/adapter/aggregation-mapconfig-adapter.js +++ b/lib/cartodb/models/mapconfig/adapter/aggregation-mapconfig-adapter.js @@ -18,16 +18,7 @@ module.exports = class AggregationMapConfigAdapter { return callback(new Error(invalidAggregationParamValueErrorMessage({ value: params.aggregation }))); } - let mapConfig; - - try { - mapConfig = new AggregationMapConfig(requestMapConfig); - } catch (error) { - error.http_status = 400; - error.type = 'mapconfig'; - - return callback(error); - } + const mapConfig = new AggregationMapConfig(requestMapConfig); if (!this._shouldAdapt(mapConfig, params)) { return callback(null, requestMapConfig);