Commit a4057635 by Boris Kocherov

[erp5_only_office] xmla: xmla_client improved olap_wizard and remote_settings fo…

…rms completely use new xmla_client
1 parent 6b072483
......@@ -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.
.declareMethod('appReady', function () {
......
......@@ -9,8 +9,6 @@
<script src="../rsvp.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>
</head>
......
/*jslint nomen: true, maxlen: 200, indent: 2*/
/*global rJS, console, window, document, RSVP, Xmla*/
/*global rJS, console, window, document, RSVP*/
(function (window, rJS) {
"use strict";
function getCurrentConnectionSettings(g, gadget) {
var connections;
return RSVP.Queue()
.push(function () {
return g.getRemoteSettings();
})
.push(function (c) {
connections = c;
return gadget.getContent("/connection_name");
})
.push(function (connection_name) {
return connections[connection_name];
})
.push(undefined, function (err) {
console.error(err);
});
}
function get_used_dimensions(g) {
return g.getContent()
.push(function (v) {
......@@ -53,159 +35,87 @@
return dimensions;
});
}
function xmla_request(func, prop) {
var xmla = new Xmla({async: true});
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 discoverDimensions(schema, used_dimensions, opt) {
return xmla_request_retry("discoverMDDimensions", opt)
function discoverDimensions(g, connection_name, used_dimensions) {
return g.request("discoverMDDimensions", connection_name)
.push(undefined, function (error) {
console.log(error);
})
.push(function (response) {
var arr = [],
i,
row;
if (response && response.numRows > 0) {
while (response.hasMoreRows()) {
row = response.readAsObject();
if (row["DIMENSION_TYPE"] !== 2) {
if (used_dimensions.indexOf(row["DIMENSION_UNIQUE_NAME"]) < 0) {
arr.push({
const: row["DIMENSION_UNIQUE_NAME"] || undefined,
title: row["DIMENSION_NAME"] || undefined
});
}
}
response.nextRow();
for (i = 0; i < response.length; i += 1) {
row = response[i];
if (row["DIMENSION_TYPE"] !== 2 &&
used_dimensions.indexOf(row["DIMENSION_UNIQUE_NAME"]) < 0) {
arr.push({
const: row["DIMENSION_UNIQUE_NAME"] || undefined,
title: row["DIMENSION_NAME"] || undefined
});
}
}
if (arr.length !== 0) {
schema.properties.dimension = {
title: " ",
oneOf: arr
};
}
return arr;
});
}
function discoverHierarchies(schema, opt) {
return xmla_request_retry("discoverMDHierarchies", opt)
function discoverHierarchies(g, connection_name, opt) {
return g.request("discoverMDHierarchies", connection_name, opt)
.push(undefined, function (error) {
console.log(error);
})
.push(function (response) {
var arr = [],
i,
row;
if (response && response.numRows > 0) {
while (response.hasMoreRows()) {
row = response.readAsObject();
arr.push({
const: row["HIERARCHY_UNIQUE_NAME"] || undefined,
title: row["HIERARCHY_NAME"] || undefined
});
response.nextRow();
}
}
if (arr.length !== 0) {
schema.properties.hierarchy = {
title: " ",
oneOf: arr
};
for (i = 0; i < response.length; i += 1) {
row = response[i];
arr.push({
const: row["HIERARCHY_UNIQUE_NAME"] || undefined,
title: row["HIERARCHY_NAME"] || undefined
});
}
return arr;
});
}
function discoverLevels(schema, opt) {
return xmla_request_retry("discoverMDLevels", opt)
function discoverLevels(g, connection_name, opt) {
return g.getLevels(connection_name, opt)
.push(undefined, function (error) {
console.log(error);
})
.push(function (response) {
var arr = [],
i,
row;
if (response && response.numRows > 0) {
while (response.hasMoreRows()) {
row = response.readAsObject();
if (row["LEVEL_TYPE"] !== 1) { // exclude all level type
arr.push({
const: row["LEVEL_UNIQUE_NAME"] || undefined,
title: row["LEVEL_NAME"] || undefined
});
}
response.nextRow();
for (i = 0; i < response.length; i += 1) {
row = response[i];
if (
row["LEVEL_CARDINALITY"] < 150 &&
row["LEVEL_TYPE"] !== 1 // exclude all level type
) {
arr.push({
const: row["LEVEL_UNIQUE_NAME"] || undefined,
title: row["LEVEL_NAME"] || undefined
});
}
}
if (arr.length !== 0) {
schema.properties.level = {
title: " ",
oneOf: arr
};
}
return arr;
});
}
function generateChoiceSchema(connection_settings, used_dimensions, choice_settings) {
function generateChoiceSchema(g, connection_name, used_dimensions, choice_settings) {
var schema = {
"type": "object",
"additionalProperties": false,
"properties": {}
},
current_dimension;
if (!connection_settings) {
if (!connection_name) {
return new RSVP.Queue()
.push(function () {
return schema;
});
}
if (!connection_settings.hasOwnProperty('properties')) {
connection_settings.properties = {};
}
if (!choice_settings) {
choice_settings = {};
}
......@@ -219,47 +129,46 @@
return new RSVP.Queue()
.push(function () {
var tasks = [discoverDimensions(schema, used_dimensions, {
urls: connection_settings.urls,
prop: {
restrictions: {
CATALOG_NAME: connection_settings.properties.Catalog,
CUBE_NAME: connection_settings.properties.Cube
}
}
})];
var tasks = [discoverDimensions(g, connection_name, used_dimensions)];
if (choice_settings.dimension) {
tasks.push(
discoverHierarchies(schema, {
urls: connection_settings.urls,
prop: {
restrictions: {
CATALOG_NAME: connection_settings.properties.Catalog,
CUBE_NAME: connection_settings.properties.Cube,
DIMENSION_UNIQUE_NAME: choice_settings.dimension
}
discoverHierarchies(g, connection_name,{prop: {
restrictions: {
DIMENSION_UNIQUE_NAME: choice_settings.dimension
}
})
}})
);
}
if (choice_settings.hierarchy) {
tasks.push(discoverLevels(schema, {
urls: connection_settings.urls,
prop: {
restrictions: {
CATALOG_NAME: connection_settings.properties.Catalog,
CUBE_NAME: connection_settings.properties.Cube,
DIMENSION_UNIQUE_NAME: choice_settings.dimension,
HIERARCHY_UNIQUE_NAME: choice_settings.hierarchy
}
}
tasks.push(discoverLevels(g, connection_name, {
DIMENSION_UNIQUE_NAME: choice_settings.dimension,
HIERARCHY_UNIQUE_NAME: choice_settings.hierarchy
}));
}
return RSVP.all(tasks);
})
.push(function () {
.push(function (arr) {
if (arr[0].length !== 0) {
schema.properties.dimension = {
title: " ",
oneOf: arr[0]
};
}
if (arr[1] && arr[1].length !== 0) {
schema.properties.hierarchy = {
title: " ",
oneOf: arr[1]
};
}
if (arr[2] && arr[2].length !== 0) {
schema.properties.level = {
title: " ",
oneOf: arr[2]
};
}
return schema;
})
.push(undefined, function () {
......@@ -277,6 +186,8 @@
});
})
.declareAcquiredMethod("getRemoteSettings", "getRemoteSettings")
.declareAcquiredMethod("request", "xmla_request")
.declareAcquiredMethod("getLevels", "xmla_getLevels")
.allowPublicAcquisition("notifyValid", function (arr, scope) {
})
.allowPublicAcquisition("notifyInvalid", function (arr, scope) {
......@@ -328,10 +239,10 @@
queue = RSVP.Queue();
}
function rerender_once(connection_settings, sub_gadget) {
function rerender_once(connection_name, sub_gadget) {
return sub_gadget.getContent()
.push(function (content) {
return generateChoiceSchema(connection_settings, used_diemensions, content);
return generateChoiceSchema(g, connection_name, used_diemensions, content);
})
.push(function (schema) {
return gadget_settings.rerender({
......@@ -349,25 +260,25 @@
.push(function (gadget) {
gadget_settings = gadget;
return RSVP.all([
getCurrentConnectionSettings(g, gadget),
gadget.getContent("/connection_name"),
gadget.getSubGadget(sub_scope)
]);
})
.push(function (arr) {
var connection_settings = arr[0],
var connection_name = arr[0],
sub_gadget = arr[1];
return rerender_once(connection_settings, sub_gadget)
return rerender_once(connection_name, sub_gadget)
.push(function (changed) {
if (changed && changed.length > 0) {
if (changed.indexOf('/dimension') >= 0) {
return allRerender();
}
return rerender_once(connection_settings, sub_gadget);
return rerender_once(connection_name, sub_gadget);
}
})
.push(function (changed) {
if (changed && changed.length > 0) {
return rerender_once(connection_settings, sub_gadget);
return rerender_once(connection_name, sub_gadget);
}
});
});
......@@ -441,20 +352,18 @@
return new RSVP.Queue()
.push(function () {
return RSVP.all([
g.getRemoteSettings(),
g.getContent("/connection_name"),
g.getContent(path),
get_used_dimensions(g)
]);
})
.push(function (arr) {
var connection_settings,
choice_settings;
connection_settings = arr[0][arr[1]];
var choice_settings;
if (path !== "/columns/" && path !== "/rows/") {
choice_settings = arr[2];
}
return generateChoiceSchema(connection_settings, arr[3], choice_settings);
return generateChoiceSchema(g, arr[0], arr[1], choice_settings);
});
}
throw new Error("urn: '" + url + "' not supported");
......
......@@ -9,8 +9,6 @@
<script src="../rsvp.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>
</head>
......
/*jslint nomen: true, maxlen: 200, indent: 2*/
/*global rJS, console, window, document, RSVP, Xmla*/
/*global rJS, console, window, document, RSVP*/
(function (window, rJS) {
"use strict";
function xmla_request(func, prop) {
var xmla = new Xmla({async: true});
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)
function discoverDataSources(g, opt) {
return g.request("discoverDataSources", undefined, opt)
.push(undefined, function (error) {
console.log(error);
})
.push(function (response) {
if (response && response.numRows > 0) {
schema.properties.DataSourceInfo = {
title: " ",
oneOf: []
};
var arr = schema.properties.DataSourceInfo.oneOf;
while (response.hasMoreRows()) {
arr.push({
const: response["getDataSourceInfo"]() || undefined,
title: response["getDataSourceName"]() || undefined,
description: response["getDataSourceDescription"]() || undefined
});
response.nextRow();
}
if (!response) {
return;
}
var arr = [],
i,
row;
for (i = 0; i < response.length; i += 1) {
row = response[i];
arr.push({
const: row["DataSourceInfo"] || undefined,
title: row["DataSourceName"] || undefined,
description: row["DataSourceDescription"] || undefined
});
}
return arr;
});
}
function discoverDBCatalogs(schema, opt) {
return xmla_request_retry("discoverDBCatalogs", opt)
function discoverDBCatalogs(g, opt) {
return g.request("discoverDBCatalogs", undefined, opt)
.push(undefined, function (error) {
console.log(error);
})
.push(function (response) {
if (response && response.numRows > 0) {
schema.properties.Catalog = {
title: " ",
oneOf: []
};
var arr = schema.properties.Catalog.oneOf;
while (response.hasMoreRows()) {
arr.push({
const: response["getCatalogName"]() || undefined,
title: response["getCatalogName"]() || undefined
});
response.nextRow();
}
if (!response) {
return;
}
var arr = [],
i,
row;
for (i = 0; i < response.length; i += 1) {
row = response[i];
arr.push({
const: row["CATALOG_NAME"] || undefined,
title: row["CATALOG_NAME"] || undefined
});
}
return arr;
});
}
function discoverMDCubes(schema, opt) {
return xmla_request_retry("discoverMDCubes", opt)
function discoverMDCubes(g, opt) {
return g.request("discoverMDCubes", undefined, opt)
.push(undefined, function (error) {
console.log(error);
})
.push(function (response) {
if (response && response.numRows > 0) {
schema.properties.Cube = {
title: " ",
oneOf: []
};
var arr = schema.properties.Cube.oneOf;
while (response.hasMoreRows()) {
arr.push({
const: response["getCubeName"]() || undefined,
title: response["getCubeName"]() || undefined
// title: response["getCatalogName"]() || undefined
});
response.nextRow();
}
if (!response) {
return;
}
var arr = [],
i,
row;
for (i = 0; i < response.length; i += 1) {
row = response[i];
arr.push({
const: row["CUBE_NAME"] || undefined,
title: row["CUBE_NAME"] || undefined
});
}
return arr;
});
}
function generateSchema(settings) {
function generateSchema(g, settings) {
var schema = {
"type": "object",
"additionalProperties": false,
......@@ -147,11 +97,11 @@
return new RSVP.Queue()
.push(function () {
return RSVP.all([
discoverDataSources(schema, {
discoverDataSources(g, {
urls: settings.urls,
prop: {}
}),
discoverDBCatalogs(schema, {
discoverDBCatalogs(g, {
urls: settings.urls,
prop: {
properties: {
......@@ -159,7 +109,7 @@
}
}
}),
discoverMDCubes(schema, {
discoverMDCubes(g, {
urls: settings.urls,
prop: {
properties: {
......@@ -170,39 +120,27 @@
})
]);
})
.push(function () {
return schema;
});
}
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];
.push(function (arr) {
if (arr[0] && arr[0].length !== 0) {
schema.properties.DataSourceInfo = {
title: " ",
oneOf: arr[0]
};
}
} else {
if (!d.hasOwnProperty(kk)) {
if (value !== undefined) {
d[kk] = {};
} else {
return;
}
if (arr[1] && arr[1].length !== 0) {
schema.properties.Catalog = {
title: " ",
oneOf: arr[1]
};
}
d = d[kk];
}
}
if (arr[2] && arr[2].length !== 0) {
schema.properties.Cube = {
title: " ",
oneOf: arr[2]
};
}
return schema;
});
}
rJS(window)
......@@ -210,6 +148,8 @@
g.props = {};
g.props.xmla_connections = {};
})
.declareAcquiredMethod("request", "xmla_request")
.declareAcquiredMethod("getLevels", "xmla_getLevels")
.allowPublicAcquisition("notifyValid", function (arr, scope) {
})
.allowPublicAcquisition("notifyInvalid", function (arr, scope) {
......@@ -245,7 +185,7 @@
return gadget.getContent(settings_path);
})
.push(function (settings) {
return generateSchema(settings);
return generateSchema(g, settings);
})
.push(function (schema) {
return gadget_settings.rerender({
......@@ -289,14 +229,15 @@
return g.notifyChange();
})
.allowPublicAcquisition("resolveExternalReference", function (arr) {
var url = arr[0],
var g = this,
url = arr[0],
schema_path = arr[1],
path = arr[2],
connection_path = path.split('/').slice(0, -1).join('/');
if ("urn:jio:properties_from_xmla.connection.json" === url) {
return this.getContent(connection_path)
.push(function (settings) {
return generateSchema(settings);
return generateSchema(g, settings);
});
}
throw new Error("urn: '" + url + "' not supported");
......
......@@ -5,6 +5,18 @@
"use strict";
function getFromCache(cache, key) {
if (cache[key].hasOwnProperty("push") &&
typeof cache[key].push === "function") {
return cache[key]
.push(function () {
return cache[key];
});
} else {
return cache[key];
}
}
function xmla_request(func, prop) {
var xmla = new Xmla({async: true});
prop = JSON.parse(JSON.stringify(prop));
......@@ -54,89 +66,60 @@
return queue;
}
function discoverDimensions(schema, used_dimensions, opt) {
return xmla_request_retry("discoverMDDimensions", opt)
.push(undefined, function (error) {
console.log(error);
})
.push(function (response) {
var arr = [],
row;
if (response && response.numRows > 0) {
while (response.hasMoreRows()) {
row = response.readAsObject();
if (row["DIMENSION_TYPE"] !== 2) {
if (used_dimensions.indexOf(row["DIMENSION_UNIQUE_NAME"]) < 0) {
arr.push({
const: row["DIMENSION_UNIQUE_NAME"] || undefined,
title: row["DIMENSION_NAME"] || undefined
});
}
}
response.nextRow();
}
function request(g, function_name, settings, connection_name) {
var queue;