From 57e10a8d2b13a87deb94927a5360a3dc4fc9fe9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Wed, 28 Mar 2018 19:37:31 +0200 Subject: [PATCH] Create layergroup controllers in server construction --- lib/cartodb/controllers/index.js | 1 - .../controllers/layergroup/analysis.js | 2 +- .../controllers/layergroup/attributes.js | 2 +- .../controllers/layergroup/dataview.js | 2 +- lib/cartodb/controllers/layergroup/index.js | 112 ------------------ .../layergroup/{static.js => preview.js} | 2 +- lib/cartodb/controllers/layergroup/tile.js | 2 +- lib/cartodb/server.js | 62 ++++++++-- 8 files changed, 60 insertions(+), 125 deletions(-) delete mode 100644 lib/cartodb/controllers/layergroup/index.js rename lib/cartodb/controllers/layergroup/{static.js => preview.js} (99%) diff --git a/lib/cartodb/controllers/index.js b/lib/cartodb/controllers/index.js index bb73af0f..11bf6a2f 100644 --- a/lib/cartodb/controllers/index.js +++ b/lib/cartodb/controllers/index.js @@ -1,6 +1,5 @@ module.exports = { Analyses: require('./analyses'), - Layergroup: require('./layergroup'), Map: require('./map'), ServerInfo: require('./server_info') }; diff --git a/lib/cartodb/controllers/layergroup/analysis.js b/lib/cartodb/controllers/layergroup/analysis.js index 9d58a53f..30371950 100644 --- a/lib/cartodb/controllers/layergroup/analysis.js +++ b/lib/cartodb/controllers/layergroup/analysis.js @@ -8,7 +8,7 @@ const { RATE_LIMIT_ENDPOINTS_GROUPS } = rateLimit; const sendResponse = require('../../middleware/send-response'); const dbParamsFromResLocals = require('../../utils/database-params'); -module.exports = class AnalysisController { +module.exports = class AnalysisLayergroupController { constructor ( analysisStatusBackend, pgConnection, diff --git a/lib/cartodb/controllers/layergroup/attributes.js b/lib/cartodb/controllers/layergroup/attributes.js index 4965fe44..9e1aa24f 100644 --- a/lib/cartodb/controllers/layergroup/attributes.js +++ b/lib/cartodb/controllers/layergroup/attributes.js @@ -12,7 +12,7 @@ const surrogateKeyHeader = require('../../middleware/surrogate-key-header'); const lastModifiedHeader = require('../../middleware/last-modified-header'); const sendResponse = require('../../middleware/send-response'); -module.exports = class AttributesController { +module.exports = class AttributesLayergroupController { constructor ( attributesBackend, pgConnection, diff --git a/lib/cartodb/controllers/layergroup/dataview.js b/lib/cartodb/controllers/layergroup/dataview.js index b768ee89..04390d23 100644 --- a/lib/cartodb/controllers/layergroup/dataview.js +++ b/lib/cartodb/controllers/layergroup/dataview.js @@ -27,7 +27,7 @@ const ALLOWED_DATAVIEW_QUERY_PARAMS = [ 'categories', // number ]; -module.exports = class DataviewController { +module.exports = class DataviewLayergroupController { constructor ( dataviewBackend, pgConnection, diff --git a/lib/cartodb/controllers/layergroup/index.js b/lib/cartodb/controllers/layergroup/index.js deleted file mode 100644 index fbbe1fd8..00000000 --- a/lib/cartodb/controllers/layergroup/index.js +++ /dev/null @@ -1,112 +0,0 @@ -const DataviewBackend = require('../../backends/dataview'); -const AnalysisStatusBackend = require('../../backends/analysis-status'); - -const TileController = require('./tile'); -const AttributesController = require('./attributes'); -const StaticController = require('./static'); -const DataviewController = require('./dataview'); -const AnalysisController = require('./analysis'); - -/** - * @param {prepareContext} prepareContext - * @param {PgConnection} pgConnection - * @param {MapStore} mapStore - * @param {TileBackend} tileBackend - * @param {PreviewBackend} previewBackend - * @param {AttributesBackend} attributesBackend - * @param {SurrogateKeysCache} surrogateKeysCache - * @param {UserLimitsApi} userLimitsApi - * @param {LayergroupAffectedTables} layergroupAffectedTables - * @param {AnalysisBackend} analysisBackend - * @constructor - */ -function LayergroupController( - pgConnection, - mapStore, - tileBackend, - previewBackend, - attributesBackend, - surrogateKeysCache, - userLimitsApi, - layergroupAffectedTablesCache, - analysisBackend, - authApi -) { - this.pgConnection = pgConnection; - this.mapStore = mapStore; - this.tileBackend = tileBackend; - this.previewBackend = previewBackend; - this.attributesBackend = attributesBackend; - this.surrogateKeysCache = surrogateKeysCache; - this.userLimitsApi = userLimitsApi; - this.layergroupAffectedTablesCache = layergroupAffectedTablesCache; - - this.dataviewBackend = new DataviewBackend(analysisBackend); - this.analysisStatusBackend = new AnalysisStatusBackend(); - this.authApi = authApi; -} - -module.exports = LayergroupController; - -LayergroupController.prototype.register = function(app) { - - const tileController = new TileController( - this.tileBackend, - this.pgConnection, - this.mapStore, - this.userLimitsApi, - this.layergroupAffectedTablesCache, - this.authApi, - this.surrogateKeysCache - ); - - tileController.register(app); - - const attributesController = new AttributesController( - this.attributesBackend, - this.pgConnection, - this.mapStore, - this.userLimitsApi, - this.layergroupAffectedTablesCache, - this.authApi, - this.surrogateKeysCache - ); - - attributesController.register(app); - - const staticController = new StaticController( - this.previewBackend, - this.pgConnection, - this.mapStore, - this.userLimitsApi, - this.layergroupAffectedTablesCache, - this.authApi, - this.surrogateKeysCache - ); - - staticController.register(app); - - const dataviewController = new DataviewController( - this.dataviewBackend, - this.pgConnection, - this.mapStore, - this.userLimitsApi, - this.layergroupAffectedTablesCache, - this.authApi, - this.surrogateKeysCache - ); - - dataviewController.register(app); - - const analysisController = new AnalysisController( - this.analysisStatusBackend, - this.pgConnection, - this.mapStore, - this.userLimitsApi, - this.layergroupAffectedTablesCache, - this.authApi, - this.surrogateKeysCache - ); - - analysisController.register(app); -}; diff --git a/lib/cartodb/controllers/layergroup/static.js b/lib/cartodb/controllers/layergroup/preview.js similarity index 99% rename from lib/cartodb/controllers/layergroup/static.js rename to lib/cartodb/controllers/layergroup/preview.js index 70957b53..1918fd72 100644 --- a/lib/cartodb/controllers/layergroup/static.js +++ b/lib/cartodb/controllers/layergroup/preview.js @@ -12,7 +12,7 @@ const surrogateKeyHeader = require('../../middleware/surrogate-key-header'); const lastModifiedHeader = require('../../middleware/last-modified-header'); const sendResponse = require('../../middleware/send-response'); -module.exports = class StaticController { +module.exports = class PreviewLayergroupController { constructor ( previewBackend, pgConnection, diff --git a/lib/cartodb/controllers/layergroup/tile.js b/lib/cartodb/controllers/layergroup/tile.js index 091a8f35..39c0e5f7 100644 --- a/lib/cartodb/controllers/layergroup/tile.js +++ b/lib/cartodb/controllers/layergroup/tile.js @@ -22,7 +22,7 @@ const SUPPORTED_FORMATS = { mvt: true }; -module.exports = class TileController { +module.exports = class TileLayergroupController { constructor ( tileBackend, pgConnection, diff --git a/lib/cartodb/server.js b/lib/cartodb/server.js index 0641629c..bb5564b8 100644 --- a/lib/cartodb/server.js +++ b/lib/cartodb/server.js @@ -7,6 +7,12 @@ var cartodbRedis = require('cartodb-redis'); var _ = require('underscore'); var controller = require('./controllers'); +const AnalysisLayergroupController = require('./controllers/layergroup/analysis'); +const AttributesLayergroupController = require('./controllers/layergroup/attributes'); +const DataviewLayergroupController = require('./controllers/layergroup/dataview'); +const PreviewLayergroupController = require('./controllers/layergroup/preview'); +const TileLayergroupController = require('./controllers/layergroup/tile'); + const AdminTemplateController = require('./controllers/template/admin'); const PreviewTemplateController = require('./controllers/template/preview'); const TileTemplateController = require('./controllers/template/tile'); @@ -35,6 +41,8 @@ var PgQueryRunner = require('./backends/pg_query_runner'); var PgConnection = require('./backends/pg_connection'); var AnalysisBackend = require('./backends/analysis'); +const AnalysisStatusBackend = require('./backends/analysis-status'); +const DataviewBackend = require('./backends/dataview'); var timeoutErrorTilePath = __dirname + '/../../assets/render-timeout-fallback.png'; var timeoutErrorTile = require('fs').readFileSync(timeoutErrorTilePath, {encoding: null}); @@ -182,6 +190,9 @@ module.exports = function(serverOptions) { var mapBackend = new windshaft.backend.Map(rendererCache, mapStore, mapValidatorBackend); var analysisBackend = new AnalysisBackend(metadataBackend, serverOptions.analysis); + const analysisStatusBackend = new AnalysisStatusBackend(); + + const dataviewBackend = new DataviewBackend(analysisBackend); var statsBackend = new StatsBackend(); @@ -227,17 +238,54 @@ module.exports = function(serverOptions) { const templateRouter = express.Router(); const monitorRouter = express.Router(); - new controller.Layergroup( + new AnalysisLayergroupController( + analysisStatusBackend, pgConnection, mapStore, - tileBackend, - previewBackend, - attributesBackend, - surrogateKeysCache, userLimitsApi, layergroupAffectedTablesCache, - analysisBackend, - authApi + authApi, + surrogateKeysCache + ).register(mapRouter); + + new AttributesLayergroupController( + attributesBackend, + pgConnection, + mapStore, + userLimitsApi, + layergroupAffectedTablesCache, + authApi, + surrogateKeysCache + ).register(mapRouter); + + new DataviewLayergroupController( + dataviewBackend, + pgConnection, + mapStore, + userLimitsApi, + layergroupAffectedTablesCache, + authApi, + surrogateKeysCache + ).register(mapRouter); + + new PreviewLayergroupController( + previewBackend, + pgConnection, + mapStore, + userLimitsApi, + layergroupAffectedTablesCache, + authApi, + surrogateKeysCache + ).register(mapRouter); + + new TileLayergroupController( + tileBackend, + pgConnection, + mapStore, + userLimitsApi, + layergroupAffectedTablesCache, + authApi, + surrogateKeysCache ).register(mapRouter); new controller.Map(