Commit 806e4521 authored by Marius Wybrands's avatar Marius Wybrands

Initial commit. exportService.TabellenExport,...

Initial commit. exportService.TabellenExport, exportService.AuspraegungInformation, testService.whoami, rechercheService.MerkmalsKatalog, rechercheService.MerkmalAuspraegungenKatalog
parents
const axios = require('axios');
var convert = require('xml-js');
var constParams = {};
var baseService;
var testService = {};
var rechercheService = {};
var exportService = {};
module.exports.initWebservice = function(params){
// force params to be an obj
params = params || {};
constParams.passwort = addDefault(params.passwort);
constParams.kennung = addDefault(params.kennung);
constParams.baseUrl = params.baseUrl || "https://www-genesis.destatis.de/genesisWS/web";
constParams.sprache = params.sprache || "de";
constParams.timeout = params.timeout || "10000";
baseService = axios.create({
baseURL: constParams.baseUrl,
timeout: constParams.timeout
});
};
exportService.TabellenExport = function(requestParameter){
// force params to be an obj
requestParameter = requestParameter || {};
var params = {};
params.method = "TabellenExport";
params = addCendentials(params);
params.namen = addDefault(requestParameter.namen);
params.bereich = addBereich(requestParameter.bereich);
params.format = addDatenFormat(requestParameter.format);
params.strukturinformation=addStrukturInformationen(requestParameter.strukturInformationen);
params.komprimieren= addKomprimieren(requestParameter.komprimieren);
params.transponieren=addTransponieren(requestParameter.transponieren);
params.startjahr= addDefault(requestParameter.startJahr);
params.endjahr= addDefault(requestParameter.endJahr);
params.zeitscheiben=addDefault(requestParameter.zeitscheiben);
params.regionalmerkmal=addDefault(requestParameter.regionalMerkmal);
params.regionalschluessel=addDefault(requestParameter.regionalSchluessel);
params.sachmerkmal=addDefault(requestParameter.sachMerkmal);
params.sachschluessel=addDefault(requestParameter.sachSchluessel);
params.sachmerkmal2=addDefault(requestParameter.sachMerkmal2);
params.sachschluessel2=addDefault(requestParameter.sachSchluessel2);
params.sachmerkmal3=addDefault(requestParameter.sachMerkmal3);
params.sachschluessel3=addDefault(requestParameter.sachSchluessel3);
params.stand= addStand(requestParameter.stand);
params.auftrag = addAuftrag(requestParameter.sachSchluessel3);
params = addLanguage(params);
return new Promise(function (resolve, reject) {
sendRequest('ExportService_2010', params).then(result => {
resolve(result['soapenv:Envelope']['soapenv:Body'][params.method + 'Response'][params.method + 'Return']['tabellen']['tabellen']['tabellenDaten']['_text']);
});
})
}
exportService.AuspraegungInformation = function(requestParameter){
// force params to be an obj
requestParameter = requestParameter || {};
var params = {};
params.method = "AuspraegungInformation";
params = addCendentials(params);
params.name = addDefault(requestParameter.name);
params.bereich = addBereich(requestParameter.bereich);
params = addLanguage(params);
return new Promise(function (resolve, reject) {
sendRequest('ExportService_2010', params).then(result => {
resolve(result['soapenv:Envelope']['soapenv:Body'][params.method + 'Response'][params.method + 'Return']);
});
})
}
testService.whoami = function() {
return new Promise(function (resolve, reject) {
baseService.get('genesisWS/web/TestService', {
params: {
method: 'whoami'
}
}).then(function (response) {
var result1 = convert.xml2json(response.data, {compact: true, spaces: 4});
result1 = JSON.parse(result1);
resolve(result1['soapenv:Envelope']['soapenv:Body']['whoamiResponse']['whoamiReturn']['_text']);
})
.catch(function (error) {
console.log(error);
reject(error);
})
.then(function () {
// always executed
});
})
}
rechercheService.MerkmalsKatalog = function(requestParameter){
// force params to be an obj
requestParameter = requestParameter || {};
var params = {};
params.method = "MerkmalsKatalog";
params = addCendentials(params);
params.filter = addFilter(requestParameter.filter);
params.kriterium = addKriterium(requestParameter.kriterium);
params.typ = addTyp(requestParameter.typ);
params.bereich = addBereich(requestParameter.bereich);
params.listenLaenge = addListenLaenge(requestParameter.listenLaenge);
params = addLanguage(params);
return new Promise(function (resolve, reject) {
sendRequest('RechercheService_2010', params).then(result => {
resolve(result['soapenv:Envelope']['soapenv:Body'][params.method + 'Response'][params.method + 'Return']);
});
})
}
rechercheService.MerkmalAuspraegungenKatalog = function(requestParameter){
// force params to be an obj
requestParameter = requestParameter || {};
var params = {};
params.method = "MerkmalAuspraegungenKatalog";
params = addCendentials(params);
params.name = addDefault(requestParameter.name);
params.auswahl = addAuswahl(requestParameter.auswahl);
params.kriterium = addKriterium(requestParameter.kriterium);
params.bereich = addBereich(requestParameter.bereich);
params.listenLaenge = addListenLaenge(requestParameter.listenLaenge);
params = addLanguage(params);
return new Promise(function (resolve, reject) {
sendRequest('RechercheService_2010', params).then(result => {
resolve(result['soapenv:Envelope']['soapenv:Body'][params.method + 'Response'][params.method + 'Return']);
});
})
}
var sendRequest = function(service,requestParams){
return new Promise(function (resolve, reject) {
baseService.get(service, {params: requestParams}).then(response => {
var parsed = responseParser(response, requestParams.method);
resolve(parsed);
})
.catch(function (error) {
console.log("------------------ ERROR ------------------");
console.log(error);
reject(error);
})
.then(function () {
});
});
}
var responseParser = function(response, method) {
var response1 = convert.xml2json(response.data, {compact: true, spaces: 4});
response1 = JSON.parse(response1);
return response1;
};
var addCendentials = function (params) {
params.kennung = constParams.kennung;
params.passwort = constParams.passwort;
return params;
}
var addLanguage = function (params) {
params.sprache = constParams.sprache;
return params;
}
var addDefault = function (param) {
return param || "";
}
var addKomprimieren = function (param) {
return param || "true";
}
var addTransponieren = function (param) {
return param || "false";
}
var addStrukturInformationen = function (param) {
return param || "false";
}
var addDatenFormat = function (param) {
return param || "csv";
}
var addGrafikFormat = function (param) {
return param || "png";
}
var addBereich = function (param) {
return param || "Alle";
}
var addAuftrag = function (param) {
return param || "false";
}
var addStand = function (param) {
return param || "01.01.1900";
}
var addListenLaenge = function (param) {
return param || "500";
}
var addFilter = function (param) {
return param || "";
}
var addKriterium = function (param) {
return param || "Code";
}
var addTyp = function (param) {
return param || "alle";
}
var addAuswahl = function (param) {
return param || "";
}
module.exports.exportService = exportService;
module.exports.testService = testService;
module.exports.rechercheService = rechercheService;
{
"name": "genesis-online-wrapper",
"version": "0.0.1",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://gitlab.uni-oldenburg.de/kije1598/genesis-online-wrapper.git"
},
"keywords": [
"database",
"wrapper",
"germany",
"statistisches bundesland"
],
"author": "Marius Wybrands",
"license": "ISC"
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment