Detect incompatible CartoCSS or interactivity for raster aggregation
This commit is contained in:
@@ -1,15 +1,25 @@
|
||||
const AggregationProxy = require('../../aggregation/aggregation-proxy');
|
||||
const { MapConfig } = require('windshaft').model;
|
||||
|
||||
const MISSING_AGGREGATION_COLUMNS = 'There are missing columns to perform aggregation';
|
||||
|
||||
module.exports = class AggregationMapConfigAdapter {
|
||||
getMapConfig (user, requestMapConfig, params, context, callback) {
|
||||
this.mapConfig = new MapConfig(requestMapConfig);
|
||||
const mapConfig = new MapConfig(requestMapConfig);
|
||||
|
||||
if (!this._shouldAdaptLayers(requestMapConfig, params)) {
|
||||
if (!this._shouldAdaptLayers(mapConfig, requestMapConfig, params)) {
|
||||
return callback(null, requestMapConfig);
|
||||
}
|
||||
|
||||
requestMapConfig.layers = this._adaptLayers(requestMapConfig);
|
||||
if (this._hasMissingColumns(mapConfig)) {
|
||||
const error = new Error(MISSING_AGGREGATION_COLUMNS);
|
||||
error.http_status = 400;
|
||||
error.type = 'mapconfig';
|
||||
|
||||
return callback(error);
|
||||
}
|
||||
|
||||
requestMapConfig.layers = this._adaptLayers(mapConfig, requestMapConfig);
|
||||
context.aggregation = {
|
||||
layers: this._getAggregationMetadata(requestMapConfig),
|
||||
};
|
||||
@@ -17,7 +27,48 @@ module.exports = class AggregationMapConfigAdapter {
|
||||
callback(null, requestMapConfig);
|
||||
}
|
||||
|
||||
_shouldAdaptLayers (requestMapConfig, params) {
|
||||
_hasMissingColumns (mapConfig) {
|
||||
const layers = mapConfig.getLayers();
|
||||
let missingColumns = false;
|
||||
|
||||
for (let index = 0; index < layers.length; index++) {
|
||||
const layer = layers[index];
|
||||
const { aggregation } = layer.options;
|
||||
const hasAggregationColumns = aggregation !== undefined &&
|
||||
typeof aggregation !== 'boolean' &&
|
||||
typeof aggregation.columns === 'object';
|
||||
const aggregationColumns = hasAggregationColumns ? Object.keys(aggregation.columns) : [];
|
||||
const layerColumns = mapConfig.getColumnsByLayer(index);
|
||||
|
||||
if (layerColumns.length === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (aggregationColumns.length === 0) {
|
||||
missingColumns = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!this._haveSameColumns(aggregationColumns,layerColumns)) {
|
||||
missingColumns = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return missingColumns;
|
||||
}
|
||||
|
||||
_haveSameColumns (aggregationColumns, layerColumns) {
|
||||
if (aggregationColumns.length !== layerColumns.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const diff = aggregationColumns.filter(column => !layerColumns.includes(column));
|
||||
|
||||
return !diff.length;
|
||||
}
|
||||
|
||||
_shouldAdaptLayers (mapConfig, requestMapConfig, params) {
|
||||
let shouldAdapt = false;
|
||||
|
||||
if (typeof params.aggregation === 'boolean') {
|
||||
@@ -25,7 +76,7 @@ module.exports = class AggregationMapConfigAdapter {
|
||||
}
|
||||
|
||||
if (params.aggregation === undefined) {
|
||||
if (this.mapConfig.isVectorOnlyMapConfig()) {
|
||||
if (mapConfig.isVectorOnlyMapConfig()) {
|
||||
shouldAdapt = true;
|
||||
} else if (this._hasAggregation(requestMapConfig)){
|
||||
shouldAdapt = true;
|
||||
@@ -50,10 +101,10 @@ module.exports = class AggregationMapConfigAdapter {
|
||||
return aggregation !== undefined && (typeof aggregation === 'object' || typeof aggregation === 'boolean');
|
||||
}
|
||||
|
||||
_adaptLayers (requestMapConfig) {
|
||||
_adaptLayers (mapConfig, requestMapConfig) {
|
||||
return requestMapConfig.layers.map(layer => {
|
||||
if (this._hasLayerAggregation(layer)) {
|
||||
const aggregation = new AggregationProxy(this.mapConfig, layer.options.aggregation);
|
||||
const aggregation = new AggregationProxy(mapConfig, layer.options.aggregation);
|
||||
const sqlQueryWrap = layer.options.sql_wrap;
|
||||
|
||||
let aggregationSql = aggregation.sql(layer.options);
|
||||
|
||||
Reference in New Issue
Block a user