Reorder code

This commit is contained in:
Daniel García Aubert 2018-05-30 19:07:28 +02:00
parent 2fb6c08702
commit 1d0210a372

View File

@ -51,44 +51,61 @@ function NamedMapMapConfigProvider(
module.exports = NamedMapMapConfigProvider;
NamedMapMapConfigProvider.prototype.getMapConfig = function(callback) {
NamedMapMapConfigProvider.prototype.getMapConfig = function (callback) {
if (!!this.err || this.mapConfig !== null) {
return callback(this.err, this.mapConfig, this.rendererParams, this.context);
}
var context = {};
this.getTemplate((err, template) => {
this.getDBParams(this.owner, (err, rendererParams) => {
if (err) {
this.err = err;
return callback(err);
}
this.getDBParams(this.owner, (err, rendererParams) => {
this.rendererParams = rendererParams;
this.metadataBackend.getUserMapKey(this.owner, (err, apiKey) => {
if (err) {
this.err = err;
return callback(err);
}
this.metadataBackend.getUserMapKey(this.owner, (err, apiKey) => {
var context = {};
context.analysisConfiguration = {
user: this.owner,
db: {
host: rendererParams.dbhost,
port: rendererParams.dbport,
dbname: rendererParams.dbname,
user: rendererParams.dbuser,
pass: rendererParams.dbpassword
},
batch: {
username: this.owner,
apiKey: apiKey
}
};
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);
}
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;
let requestMapConfig;
try {
requestMapConfig = this.templateMaps.instance(template, templateParams);
@ -97,37 +114,22 @@ NamedMapMapConfigProvider.prototype.getMapConfig = function(callback) {
return callback(err);
}
context.analysisConfiguration = {
user: this.owner,
db: {
host: rendererParams.dbhost,
port: rendererParams.dbport,
dbname: rendererParams.dbname,
user: rendererParams.dbuser,
pass: rendererParams.dbpassword
},
batch: {
username: this.owner,
apiKey: apiKey
}
};
this.mapConfigAdapter.getMapConfig(this.owner, requestMapConfig, rendererParams, context, (err, mapConfig) => {
if (err) {
this.err = err;
return callback(err);
}
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.mapConfig = (mapConfig === null) ? null : new MapConfig(mapConfig, context.datasource);
this.analysesResults = context.analysesResults || [];
this.rendererParams = rendererParams;
this.context = context;
this.context.limits = renderLimits || {};
return callback(null, this.mapConfig, this.rendererParams, this.context);