Extract method to get and build context
This commit is contained in:
@@ -56,17 +56,68 @@ NamedMapMapConfigProvider.prototype.getMapConfig = function (callback) {
|
||||
return callback(this.err, this.mapConfig, this.rendererParams, this.context);
|
||||
}
|
||||
|
||||
this.getDBParams(this.owner, (err, rendererParams) => {
|
||||
this.getContext((err, context) => {
|
||||
if (err) {
|
||||
this.err = err;
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
const { owner, rendererParams } = this;
|
||||
|
||||
var templateParams = {};
|
||||
|
||||
if (this.config) {
|
||||
try {
|
||||
templateParams = _.isString(this.config) ? JSON.parse(this.config) : this.config;
|
||||
} catch (e) {
|
||||
const error = new Error('malformed config parameter, should be a valid JSON');
|
||||
this.err = error;
|
||||
return callback(err);
|
||||
}
|
||||
}
|
||||
|
||||
context.templateParams = templateParams;
|
||||
|
||||
this.getTemplate((err, template) => {
|
||||
if (err) {
|
||||
this.err = err;
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
let requestMapConfig;
|
||||
|
||||
try {
|
||||
requestMapConfig = this.templateMaps.instance(template, templateParams);
|
||||
} catch (err) {
|
||||
this.err = err;
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
this.mapConfigAdapter.getMapConfig(owner, requestMapConfig, rendererParams, context, (err, mapConfig) => {
|
||||
if (err) {
|
||||
this.err = err;
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
this.mapConfig = (mapConfig === null) ? null : new MapConfig(mapConfig, context.datasource);
|
||||
this.analysesResults = context.analysesResults || [];
|
||||
|
||||
return callback(null, this.mapConfig, this.rendererParams, this.context);
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
NamedMapMapConfigProvider.prototype.getContext = function (callback) {
|
||||
this.getDBParams(this.owner, (err, rendererParams) => {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
this.rendererParams = rendererParams;
|
||||
|
||||
this.metadataBackend.getUserMapKey(this.owner, (err, apiKey) => {
|
||||
if (err) {
|
||||
this.err = err;
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
@@ -87,54 +138,17 @@ NamedMapMapConfigProvider.prototype.getMapConfig = function (callback) {
|
||||
}
|
||||
};
|
||||
|
||||
var templateParams = {};
|
||||
if (this.config) {
|
||||
try {
|
||||
templateParams = _.isString(this.config) ? JSON.parse(this.config) : this.config;
|
||||
} catch (e) {
|
||||
const error = new Error('malformed config parameter, should be a valid JSON');
|
||||
this.err = error;
|
||||
return callback(err);
|
||||
}
|
||||
}
|
||||
|
||||
context.templateParams = templateParams;
|
||||
|
||||
this.getTemplate((err, template) => {
|
||||
this.userLimitsBackend.getRenderLimits(this.owner, this.params.api_key, (err, renderLimits) => {
|
||||
if (err) {
|
||||
this.err = err;
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
let requestMapConfig;
|
||||
try {
|
||||
requestMapConfig = this.templateMaps.instance(template, templateParams);
|
||||
} catch (err) {
|
||||
this.err = err;
|
||||
return callback(err);
|
||||
}
|
||||
context.limits = renderLimits || {};
|
||||
|
||||
this.mapConfigAdapter.getMapConfig(this.owner, requestMapConfig, rendererParams, context, (err, mapConfig) => {
|
||||
if (err) {
|
||||
this.err = err;
|
||||
return callback(err);
|
||||
}
|
||||
this.context = context;
|
||||
|
||||
this.context = context;
|
||||
this.mapConfig = (mapConfig === null) ? null : new MapConfig(mapConfig, context.datasource);
|
||||
this.analysesResults = context.analysesResults || [];
|
||||
|
||||
this.userLimitsBackend.getRenderLimits(this.owner, this.params.api_key, (err, renderLimits) => {
|
||||
if (err) {
|
||||
this.err = err;
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
this.context.limits = renderLimits || {};
|
||||
|
||||
return callback(null, this.mapConfig, this.rendererParams, this.context);
|
||||
});
|
||||
});
|
||||
return callback(null, context);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user