Create layergroup controllers in server construction

This commit is contained in:
Daniel García Aubert 2018-03-28 19:37:31 +02:00
parent 51fade6bd3
commit 57e10a8d2b
8 changed files with 60 additions and 125 deletions

View File

@ -1,6 +1,5 @@
module.exports = { module.exports = {
Analyses: require('./analyses'), Analyses: require('./analyses'),
Layergroup: require('./layergroup'),
Map: require('./map'), Map: require('./map'),
ServerInfo: require('./server_info') ServerInfo: require('./server_info')
}; };

View File

@ -8,7 +8,7 @@ const { RATE_LIMIT_ENDPOINTS_GROUPS } = rateLimit;
const sendResponse = require('../../middleware/send-response'); const sendResponse = require('../../middleware/send-response');
const dbParamsFromResLocals = require('../../utils/database-params'); const dbParamsFromResLocals = require('../../utils/database-params');
module.exports = class AnalysisController { module.exports = class AnalysisLayergroupController {
constructor ( constructor (
analysisStatusBackend, analysisStatusBackend,
pgConnection, pgConnection,

View File

@ -12,7 +12,7 @@ const surrogateKeyHeader = require('../../middleware/surrogate-key-header');
const lastModifiedHeader = require('../../middleware/last-modified-header'); const lastModifiedHeader = require('../../middleware/last-modified-header');
const sendResponse = require('../../middleware/send-response'); const sendResponse = require('../../middleware/send-response');
module.exports = class AttributesController { module.exports = class AttributesLayergroupController {
constructor ( constructor (
attributesBackend, attributesBackend,
pgConnection, pgConnection,

View File

@ -27,7 +27,7 @@ const ALLOWED_DATAVIEW_QUERY_PARAMS = [
'categories', // number 'categories', // number
]; ];
module.exports = class DataviewController { module.exports = class DataviewLayergroupController {
constructor ( constructor (
dataviewBackend, dataviewBackend,
pgConnection, pgConnection,

View File

@ -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);
};

View File

@ -12,7 +12,7 @@ const surrogateKeyHeader = require('../../middleware/surrogate-key-header');
const lastModifiedHeader = require('../../middleware/last-modified-header'); const lastModifiedHeader = require('../../middleware/last-modified-header');
const sendResponse = require('../../middleware/send-response'); const sendResponse = require('../../middleware/send-response');
module.exports = class StaticController { module.exports = class PreviewLayergroupController {
constructor ( constructor (
previewBackend, previewBackend,
pgConnection, pgConnection,

View File

@ -22,7 +22,7 @@ const SUPPORTED_FORMATS = {
mvt: true mvt: true
}; };
module.exports = class TileController { module.exports = class TileLayergroupController {
constructor ( constructor (
tileBackend, tileBackend,
pgConnection, pgConnection,

View File

@ -7,6 +7,12 @@ var cartodbRedis = require('cartodb-redis');
var _ = require('underscore'); var _ = require('underscore');
var controller = require('./controllers'); 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 AdminTemplateController = require('./controllers/template/admin');
const PreviewTemplateController = require('./controllers/template/preview'); const PreviewTemplateController = require('./controllers/template/preview');
const TileTemplateController = require('./controllers/template/tile'); const TileTemplateController = require('./controllers/template/tile');
@ -35,6 +41,8 @@ var PgQueryRunner = require('./backends/pg_query_runner');
var PgConnection = require('./backends/pg_connection'); var PgConnection = require('./backends/pg_connection');
var AnalysisBackend = require('./backends/analysis'); 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 timeoutErrorTilePath = __dirname + '/../../assets/render-timeout-fallback.png';
var timeoutErrorTile = require('fs').readFileSync(timeoutErrorTilePath, {encoding: null}); 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 mapBackend = new windshaft.backend.Map(rendererCache, mapStore, mapValidatorBackend);
var analysisBackend = new AnalysisBackend(metadataBackend, serverOptions.analysis); var analysisBackend = new AnalysisBackend(metadataBackend, serverOptions.analysis);
const analysisStatusBackend = new AnalysisStatusBackend();
const dataviewBackend = new DataviewBackend(analysisBackend);
var statsBackend = new StatsBackend(); var statsBackend = new StatsBackend();
@ -227,17 +238,54 @@ module.exports = function(serverOptions) {
const templateRouter = express.Router(); const templateRouter = express.Router();
const monitorRouter = express.Router(); const monitorRouter = express.Router();
new controller.Layergroup( new AnalysisLayergroupController(
analysisStatusBackend,
pgConnection, pgConnection,
mapStore, mapStore,
tileBackend,
previewBackend,
attributesBackend,
surrogateKeysCache,
userLimitsApi, userLimitsApi,
layergroupAffectedTablesCache, 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); ).register(mapRouter);
new controller.Map( new controller.Map(