Use generic adapter
This commit is contained in:
@@ -20,6 +20,7 @@ var AnalysisMapConfigAdapter = require('../models/mapconfig/adapter/analysis-map
|
||||
var NamedMapMapConfigProvider = require('../models/mapconfig/provider/named-map-provider');
|
||||
var CreateLayergroupMapConfigProvider = require('../models/mapconfig/provider/create-layergroup-provider');
|
||||
var SqlWrapMapConfigAdapter = require('../models/mapconfig/adapter/sql-wrap-mapconfig-adapter');
|
||||
var MapConfigAdapter = require('../models/mapconfig/adapter');
|
||||
|
||||
/**
|
||||
* @param {AuthApi} authApi
|
||||
@@ -54,6 +55,14 @@ function MapController(authApi, pgConnection, templateMaps, mapBackend, metadata
|
||||
this.namedLayersAdapter = new MapConfigNamedLayersAdapter(templateMaps, pgConnection);
|
||||
this.overviewsAdapter = overviewsAdapter;
|
||||
this.sqlWrapMapConfigAdapter = new SqlWrapMapConfigAdapter();
|
||||
|
||||
this.mapConfigAdapter = new MapConfigAdapter([
|
||||
this.sqlWrapMapConfigAdapter,
|
||||
this.analysisMapConfigAdapter,
|
||||
this.namedLayersAdapter,
|
||||
this.overviewsAdapter,
|
||||
this.turboCartoAdapter
|
||||
]);
|
||||
}
|
||||
|
||||
util.inherits(MapController, BaseController);
|
||||
@@ -135,7 +144,6 @@ MapController.prototype.create = function(req, res, prepareConfigFn) {
|
||||
|
||||
var mapConfig;
|
||||
|
||||
var user = req.context.user;
|
||||
var context = {};
|
||||
|
||||
step(
|
||||
@@ -158,27 +166,7 @@ MapController.prototype.create = function(req, res, prepareConfigFn) {
|
||||
apiKey: req.params.api_key
|
||||
}
|
||||
};
|
||||
return requestMapConfig;
|
||||
},
|
||||
function prepareSqlWrap(err, requestMapConfig) {
|
||||
assert.ifError(err);
|
||||
self.sqlWrapMapConfigAdapter.getMapConfig(user, requestMapConfig, req.params, context, this);
|
||||
},
|
||||
function prepareAnalysisLayers(err, requestMapConfig) {
|
||||
assert.ifError(err);
|
||||
self.analysisMapConfigAdapter.getMapConfig(user, requestMapConfig, req.params, context, this);
|
||||
},
|
||||
function beforeLayergroupCreate(err, requestMapConfig) {
|
||||
assert.ifError(err);
|
||||
self.namedLayersAdapter.getMapConfig(user, requestMapConfig, req.params, context, this);
|
||||
},
|
||||
function addOverviewsInformation(err, requestMapConfig) {
|
||||
assert.ifError(err);
|
||||
self.overviewsAdapter.getMapConfig(req.context.user, requestMapConfig, req.params, context, this);
|
||||
},
|
||||
function parseTurboCarto(err, requestMapConfig) {
|
||||
assert.ifError(err);
|
||||
self.turboCartoAdapter.getMapConfig(req.context.user, requestMapConfig, req.params, context, this);
|
||||
self.mapConfigAdapter.getMapConfig(req.context.user, requestMapConfig, req.params, context, this);
|
||||
},
|
||||
function createLayergroup(err, requestMapConfig) {
|
||||
assert.ifError(err);
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
'use strict';
|
||||
|
||||
function MapConfigAdapter(adapters) {
|
||||
this.adapters = adapters;
|
||||
}
|
||||
|
||||
module.exports = MapConfigAdapter;
|
||||
|
||||
MapConfigAdapter.prototype.getMapConfig = function(user, requestMapConfig, params, context, callback) {
|
||||
var self = this;
|
||||
var i = 0;
|
||||
var tasksLeft = this.adapters.length;
|
||||
|
||||
function next(err, _requestMapConfig) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
if (tasksLeft-- === 0) {
|
||||
return callback(null, _requestMapConfig);
|
||||
}
|
||||
var nextAdapter = self.adapters[i++];
|
||||
nextAdapter.getMapConfig(user, _requestMapConfig, params, context, next);
|
||||
}
|
||||
|
||||
next(null, requestMapConfig);
|
||||
};
|
||||
Reference in New Issue
Block a user