Commit 9903d48a authored by Boris Kocherov's avatar Boris Kocherov Committed by Romain Courteaud

[erp5_only_office] xmla: xmla_client improved olap_wizard and remote_settings...

[erp5_only_office] xmla: xmla_client improved olap_wizard and remote_settings forms completely use new xmla_client
parent 4a2554c6
...@@ -416,6 +416,24 @@ DocsAPI.DocEditor.version = function () { ...@@ -416,6 +416,24 @@ DocsAPI.DocEditor.version = function () {
} }
}); });
}) })
.allowPublicAcquisition("xmla_request", function (arr) {
return this.getDeclaredGadget("xmla_client")
.push(function (g) {
return g.request(arr[0], arr[1], arr[2]);
})
.push(undefined, function (err) {
console.error(err);
});
})
.allowPublicAcquisition("xmla_getLevels", function (arr) {
return this.getDeclaredGadget("xmla_client")
.push(function (g) {
return g.getLevels(arr[0], arr[1], arr[2]);
})
.push(undefined, function (err) {
console.error(err);
});
})
// methods emulating Gateway used for connection with ooffice begin. // methods emulating Gateway used for connection with ooffice begin.
.declareMethod('appReady', function () { .declareMethod('appReady', function () {
......
...@@ -9,8 +9,6 @@ ...@@ -9,8 +9,6 @@
<script src="../rsvp.js"></script> <script src="../rsvp.js"></script>
<script src="../renderjs.js"></script> <script src="../renderjs.js"></script>
<script src="../jio.js"></script>
<script src="web-apps/vendor/xmla4js/Xmla-compiled.js"></script>
<script src="olap_wizard.js"></script> <script src="olap_wizard.js"></script>
</head> </head>
......
...@@ -9,8 +9,6 @@ ...@@ -9,8 +9,6 @@
<script src="../rsvp.js"></script> <script src="../rsvp.js"></script>
<script src="../renderjs.js"></script> <script src="../renderjs.js"></script>
<script src="../jio.js"></script>
<script src="web-apps/vendor/xmla4js/Xmla-compiled.js"></script>
<script src="remote_settings.js"></script> <script src="remote_settings.js"></script>
</head> </head>
......
/*jslint nomen: true, maxlen: 200, indent: 2*/ /*jslint nomen: true, maxlen: 200, indent: 2*/
/*global rJS, console, window, document, RSVP, Xmla*/ /*global rJS, console, window, document, RSVP*/
(function (window, rJS) { (function (window, rJS) {
"use strict"; "use strict";
function xmla_request(func, prop) { function discoverDataSources(g, opt) {
var xmla = new Xmla({async: true}); return g.request("discoverDataSources", undefined, opt)
prop = JSON.parse(JSON.stringify(prop));
// return function () {
return new RSVP.Queue()
.push(function () {
return new RSVP.Promise(function (resolve, reject) {
prop.success = function (xmla, options, response) {
resolve(response);
};
prop.error = function (xmla, options, response) {
reject(response);
};
xmla[func](prop);
});
});
}
function xmla_request_retry(func, settings) {
var queue,
urls = settings.urls || [""],
i;
function make_request(url) {
return function (error) {
settings.prop.url = url;
return xmla_request(func, settings.prop)
.push(undefined, function (response) {
// fix mondrian Internal and Sql errors
if (response) {
switch (response["code"]) {
case "SOAP-ENV:Server.00HSBE02":
case "SOAP-ENV:00UE001.Internal Error":
// rarely server error, so try again
return xmla_request(func, settings.prop);
}
}
throw response;
});
};
}
queue = make_request(urls[0])();
for (i = 1; i < urls.length; i += 1) {
queue.push(undefined, make_request(urls[i]));
}
return queue;
}
function discoverDataSources(schema, opt) {
return xmla_request_retry("discoverDataSources", opt)
.push(undefined, function (error) { .push(undefined, function (error) {
console.log(error); console.log(error);
}) })
.push(function (response) { .push(function (response) {
if (response && response.numRows > 0) { if (!response) {
schema.properties.DataSourceInfo = { return;
title: " ", }
oneOf: [] var arr = [],
}; i,
var arr = schema.properties.DataSourceInfo.oneOf; row;
while (response.hasMoreRows()) { for (i = 0; i < response.length; i += 1) {
arr.push({ row = response[i];
const: response["getDataSourceInfo"]() || undefined, arr.push({
title: response["getDataSourceName"]() || undefined, const: row["DataSourceInfo"] || undefined,
description: response["getDataSourceDescription"]() || undefined title: row["DataSourceName"] || undefined,
}); description: row["DataSourceDescription"] || undefined
response.nextRow(); });
}
} }
return arr;
}); });
} }
function discoverDBCatalogs(schema, opt) { function discoverDBCatalogs(g, opt) {
return xmla_request_retry("discoverDBCatalogs", opt) return g.request("discoverDBCatalogs", undefined, opt)
.push(undefined, function (error) { .push(undefined, function (error) {
console.log(error); console.log(error);
}) })
.push(function (response) { .push(function (response) {
if (response && response.numRows > 0) { if (!response) {
schema.properties.Catalog = { return;
title: " ", }
oneOf: [] var arr = [],
}; i,
var arr = schema.properties.Catalog.oneOf; row;
while (response.hasMoreRows()) { for (i = 0; i < response.length; i += 1) {
arr.push({ row = response[i];
const: response["getCatalogName"]() || undefined, arr.push({
title: response["getCatalogName"]() || undefined const: row["CATALOG_NAME"] || undefined,
}); title: row["CATALOG_NAME"] || undefined
response.nextRow(); });
}
} }
return arr;
}); });
} }
function discoverMDCubes(schema, opt) { function discoverMDCubes(g, opt) {
return xmla_request_retry("discoverMDCubes", opt) return g.request("discoverMDCubes", undefined, opt)
.push(undefined, function (error) { .push(undefined, function (error) {
console.log(error); console.log(error);
}) })
.push(function (response) { .push(function (response) {
if (response && response.numRows > 0) { if (!response) {
schema.properties.Cube = { return;
title: " ", }
oneOf: [] var arr = [],
}; i,
var arr = schema.properties.Cube.oneOf; row;
while (response.hasMoreRows()) { for (i = 0; i < response.length; i += 1) {
arr.push({ row = response[i];
const: response["getCubeName"]() || undefined, arr.push({
title: response["getCubeName"]() || undefined const: row["CUBE_NAME"] || undefined,
// title: response["getCatalogName"]() || undefined title: row["CUBE_NAME"] || undefined
}); });
response.nextRow();
}
} }
return arr;
}); });
} }
function generateSchema(settings) { function generateSchema(g, settings) {
var schema = { var schema = {
"type": "object", "type": "object",
"additionalProperties": false, "additionalProperties": false,
...@@ -147,11 +97,11 @@ ...@@ -147,11 +97,11 @@
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
return RSVP.all([ return RSVP.all([
discoverDataSources(schema, { discoverDataSources(g, {
urls: settings.urls, urls: settings.urls,
prop: {} prop: {}
}), }),
discoverDBCatalogs(schema, { discoverDBCatalogs(g, {
urls: settings.urls, urls: settings.urls,
prop: { prop: {
properties: { properties: {
...@@ -159,7 +109,7 @@ ...@@ -159,7 +109,7 @@
} }
} }
}), }),
discoverMDCubes(schema, { discoverMDCubes(g, {
urls: settings.urls, urls: settings.urls,
prop: { prop: {
properties: { properties: {
...@@ -170,39 +120,27 @@ ...@@ -170,39 +120,27 @@
}) })
]); ]);
}) })
.push(function () { .push(function (arr) {
return schema; if (arr[0] && arr[0].length !== 0) {
}); schema.properties.DataSourceInfo = {
} title: " ",
oneOf: arr[0]
function decodeJsonPointer(_str) { };
// https://tools.ietf.org/html/rfc6901#section-5
return _str.replace(/~1/g, '/').replace(/~0/g, '~');
}
function convertOnMultiLevel(d, key, value) {
var ii,
kk,
key_list = key.split("/");
for (ii = 1; ii < key_list.length; ii += 1) {
kk = decodeJsonPointer(key_list[ii]);
if (ii === key_list.length - 1) {
if (value !== undefined) {
d[kk] = value[0];
} else {
return d[kk];
} }
} else { if (arr[1] && arr[1].length !== 0) {
if (!d.hasOwnProperty(kk)) { schema.properties.Catalog = {
if (value !== undefined) { title: " ",
d[kk] = {}; oneOf: arr[1]
} else { };
return;
}
} }
d = d[kk]; if (arr[2] && arr[2].length !== 0) {
} schema.properties.Cube = {
} title: " ",
oneOf: arr[2]
};
}
return schema;
});
} }
rJS(window) rJS(window)
...@@ -210,6 +148,8 @@ ...@@ -210,6 +148,8 @@
g.props = {}; g.props = {};
g.props.xmla_connections = {}; g.props.xmla_connections = {};
}) })
.declareAcquiredMethod("request", "xmla_request")
.declareAcquiredMethod("getLevels", "xmla_getLevels")
.allowPublicAcquisition("notifyValid", function (arr, scope) { .allowPublicAcquisition("notifyValid", function (arr, scope) {
}) })
.allowPublicAcquisition("notifyInvalid", function (arr, scope) { .allowPublicAcquisition("notifyInvalid", function (arr, scope) {
...@@ -245,7 +185,7 @@ ...@@ -245,7 +185,7 @@
return gadget.getContent(settings_path); return gadget.getContent(settings_path);
}) })
.push(function (settings) { .push(function (settings) {
return generateSchema(settings); return generateSchema(g, settings);
}) })
.push(function (schema) { .push(function (schema) {
return gadget_settings.rerender({ return gadget_settings.rerender({
...@@ -289,14 +229,15 @@ ...@@ -289,14 +229,15 @@
return g.notifyChange(); return g.notifyChange();
}) })
.allowPublicAcquisition("resolveExternalReference", function (arr) { .allowPublicAcquisition("resolveExternalReference", function (arr) {
var url = arr[0], var g = this,
url = arr[0],
schema_path = arr[1], schema_path = arr[1],
path = arr[2], path = arr[2],
connection_path = path.split('/').slice(0, -1).join('/'); connection_path = path.split('/').slice(0, -1).join('/');
if ("urn:jio:properties_from_xmla.connection.json" === url) { if ("urn:jio:properties_from_xmla.connection.json" === url) {
return this.getContent(connection_path) return this.getContent(connection_path)
.push(function (settings) { .push(function (settings) {
return generateSchema(settings); return generateSchema(g, settings);
}); });
} }
throw new Error("urn: '" + url + "' not supported"); throw new Error("urn: '" + url + "' not supported");
......
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