Create Map Controller while building server

This commit is contained in:
Daniel García Aubert 2018-03-28 19:58:30 +02:00
parent 57e10a8d2b
commit 5bb5bc42ee
5 changed files with 35 additions and 79 deletions

View File

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

View File

@ -1,7 +1,6 @@
const windshaft = require('windshaft');
const MapConfig = windshaft.model.MapConfig;
const Datasource = windshaft.model.Datasource;
const ResourceLocator = require('../../models/resource-locator');
const cors = require('../../middleware/cors');
const cleanUpQueryParams = require('../../middleware/clean-up-query-params');
const credentials = require('../../middleware/credentials');
@ -22,7 +21,6 @@ const layergroupMetadata = require('./middlewares/layergroup-metadata');
const mapError = require('./middlewares/map-error');
const sendResponse = require('../../middleware/send-response');
const CreateLayergroupMapConfigProvider = require('../../models/mapconfig/provider/create-layergroup-provider');
const LayergroupMetadata = require('../../utils/layergroup-metadata');
const rateLimit = require('../../middleware/rate-limit');
const { RATE_LIMIT_ENDPOINTS_GROUPS } = rateLimit;
@ -49,7 +47,8 @@ function AnonymousMapController (
layergroupAffectedTables,
mapConfigAdapter,
statsBackend,
authApi
authApi,
layergroupMetadata
) {
this.pgConnection = pgConnection;
this.templateMaps = templateMaps;
@ -58,13 +57,10 @@ function AnonymousMapController (
this.surrogateKeysCache = surrogateKeysCache;
this.userLimitsApi = userLimitsApi;
this.layergroupAffectedTables = layergroupAffectedTables;
this.mapConfigAdapter = mapConfigAdapter;
const resourceLocator = new ResourceLocator(global.environment);
this.layergroupMetadata = new LayergroupMetadata(resourceLocator);
this.statsBackend = statsBackend;
this.authApi = authApi;
this.layergroupMetadata = layergroupMetadata;
}
module.exports = AnonymousMapController;
@ -106,7 +102,7 @@ AnonymousMapController.prototype.composeCreateMapMiddleware = function () {
lastModifiedHeader({ now: true }),
lastUpdatedTimeLayergroup(),
layerStats(this.pgConnection, this.statsBackend),
layergroupIdHeader(this.templateMaps ,useTemplateHash),
layergroupIdHeader(this.templateMaps, useTemplateHash),
layergroupMetadata(this.layergroupMetadata, includeQuery),
sendResponse(),
mapError({ label, addContext })

View File

@ -1,60 +0,0 @@
const AnonymousMapController = require('./anonymous');
const NamedMapController = require('./named');
module.exports = class MapController {
constructor (
pgConnection,
templateMaps,
mapBackend,
metadataBackend,
surrogateKeysCache,
userLimitsApi,
layergroupAffectedTablesCache,
mapConfigAdapter,
statsBackend,
authApi
) {
this.pgConnection = pgConnection;
this.templateMaps = templateMaps;
this.mapBackend = mapBackend;
this.metadataBackend = metadataBackend;
this.surrogateKeysCache = surrogateKeysCache;
this.userLimitsApi = userLimitsApi;
this.layergroupAffectedTablesCache = layergroupAffectedTablesCache;
this.mapConfigAdapter = mapConfigAdapter;
this.statsBackend = statsBackend;
this.authApi = authApi;
}
register (mapRouter, templateRouter) {
const anonymousMapController = new AnonymousMapController(
this.pgConnection,
this.templateMaps,
this.mapBackend,
this.metadataBackend,
this.surrogateKeysCache,
this.userLimitsApi,
this.layergroupAffectedTablesCache,
this.mapConfigAdapter,
this.statsBackend,
this.authApi
);
anonymousMapController.register(mapRouter);
const namedMapController = new NamedMapController(
this.pgConnection,
this.templateMaps,
this.mapBackend,
this.metadataBackend,
this.surrogateKeysCache,
this.userLimitsApi,
this.layergroupAffectedTablesCache,
this.mapConfigAdapter,
this.statsBackend,
this.authApi
);
namedMapController.register(templateRouter);
}
};

View File

@ -1,4 +1,3 @@
const ResourceLocator = require('../../models/resource-locator');
const cleanUpQueryParams = require('../../middleware/clean-up-query-params');
const credentials = require('../../middleware/credentials');
const dbConnSetup = require('../../middleware/db-conn-setup');
@ -19,7 +18,6 @@ const mapError = require('./middlewares/map-error');
const sendResponse = require('../../middleware/send-response');
const NamedMapMapConfigProvider = require('../../models/mapconfig/provider/named-map-provider');
const CreateLayergroupMapConfigProvider = require('../../models/mapconfig/provider/create-layergroup-provider');
const LayergroupMetadata = require('../../utils/layergroup-metadata');
const rateLimit = require('../../middleware/rate-limit');
const { RATE_LIMIT_ENDPOINTS_GROUPS } = rateLimit;
@ -46,7 +44,8 @@ function NamedMapController (
layergroupAffectedTables,
mapConfigAdapter,
statsBackend,
authApi
authApi,
layergroupMetadata
) {
this.pgConnection = pgConnection;
this.templateMaps = templateMaps;
@ -55,13 +54,10 @@ function NamedMapController (
this.surrogateKeysCache = surrogateKeysCache;
this.userLimitsApi = userLimitsApi;
this.layergroupAffectedTables = layergroupAffectedTables;
this.mapConfigAdapter = mapConfigAdapter;
const resourceLocator = new ResourceLocator(global.environment);
this.layergroupMetadata = new LayergroupMetadata(resourceLocator);
this.statsBackend = statsBackend;
this.authApi = authApi;
this.layergroupMetadata = layergroupMetadata;
}
module.exports = NamedMapController;

View File

@ -7,12 +7,16 @@ 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 AnonymousMapController = require('./controllers/map/anonymous');
const NamedMapController = require('./controllers/map/named');
const AdminTemplateController = require('./controllers/template/admin');
const PreviewTemplateController = require('./controllers/template/preview');
const TileTemplateController = require('./controllers/template/tile');
@ -59,6 +63,9 @@ var MapConfigAdapter = require('./models/mapconfig/adapter');
var StatsBackend = require('./backends/stats');
const ResourceLocator = require('./models/resource-locator');
const LayergroupMetadata = require('./utils/layergroup-metadata');
const lzmaMiddleware = require('./middleware/lzma');
const errorMiddleware = require('./middleware/error-middleware');
const servedByHostHeader = require('./middleware/served-by-host-header');
@ -228,6 +235,9 @@ module.exports = function(serverOptions) {
var TablesExtentApi = require('./api/tables_extent_api');
var tablesExtentApi = new TablesExtentApi(pgQueryRunner);
const resourceLocator = new ResourceLocator(global.environment);
const layergroupMetadata = new LayergroupMetadata(resourceLocator);
var versions = getAndValidateVersions(serverOptions);
/*******************************************************************************************************************
@ -288,7 +298,7 @@ module.exports = function(serverOptions) {
surrogateKeysCache
).register(mapRouter);
new controller.Map(
new AnonymousMapController(
pgConnection,
templateMaps,
mapBackend,
@ -298,8 +308,23 @@ module.exports = function(serverOptions) {
layergroupAffectedTablesCache,
mapConfigAdapter,
statsBackend,
authApi
).register(mapRouter, templateRouter);
authApi,
layergroupMetadata
).register(mapRouter);
new NamedMapController(
pgConnection,
templateMaps,
mapBackend,
metadataBackend,
surrogateKeysCache,
userLimitsApi,
layergroupAffectedTablesCache,
mapConfigAdapter,
statsBackend,
authApi,
layergroupMetadata
).register(templateRouter);
new TileTemplateController(
namedMapProviderCache,