Commit a4057635 authored by Boris Kocherov's avatar Boris Kocherov

[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 6b072483
...@@ -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>
......
/*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 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) { function get_used_dimensions(g) {
return g.getContent() return g.getContent()
.push(function (v) { .push(function (v) {
...@@ -53,159 +35,87 @@ ...@@ -53,159 +35,87 @@
return dimensions; return dimensions;
}); });
} }
function discoverDimensions(g, connection_name, used_dimensions) {
function xmla_request(func, prop) { return g.request("discoverMDDimensions", connection_name)
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)
.push(undefined, function (error) { .push(undefined, function (error) {
console.log(error); console.log(error);
}) })
.push(function (response) { .push(function (response) {
var arr = [], var arr = [],
i,
row; row;
if (response && response.numRows > 0) { for (i = 0; i < response.length; i += 1) {
while (response.hasMoreRows()) { row = response[i];
row = response.readAsObject(); if (row["DIMENSION_TYPE"] !== 2 &&
if (row["DIMENSION_TYPE"] !== 2) { used_dimensions.indexOf(row["DIMENSION_UNIQUE_NAME"]) < 0) {
if (used_dimensions.indexOf(row["DIMENSION_UNIQUE_NAME"]) < 0) {
arr.push({ arr.push({
const: row["DIMENSION_UNIQUE_NAME"] || undefined, const: row["DIMENSION_UNIQUE_NAME"] || undefined,
title: row["DIMENSION_NAME"] || undefined title: row["DIMENSION_NAME"] || undefined
}); });
} }
} }
response.nextRow(); return arr;
}
}
if (arr.length !== 0) {
schema.properties.dimension = {
title: " ",
oneOf: arr
};
}
}); });
} }
function discoverHierarchies(schema, opt) { function discoverHierarchies(g, connection_name, opt) {
return xmla_request_retry("discoverMDHierarchies", opt) return g.request("discoverMDHierarchies", connection_name, opt)
.push(undefined, function (error) { .push(undefined, function (error) {
console.log(error); console.log(error);
}) })
.push(function (response) { .push(function (response) {
var arr = [], var arr = [],
i,
row; row;
if (response && response.numRows > 0) { for (i = 0; i < response.length; i += 1) {
while (response.hasMoreRows()) { row = response[i];
row = response.readAsObject();
arr.push({ arr.push({
const: row["HIERARCHY_UNIQUE_NAME"] || undefined, const: row["HIERARCHY_UNIQUE_NAME"] || undefined,
title: row["HIERARCHY_NAME"] || undefined title: row["HIERARCHY_NAME"] || undefined
}); });
response.nextRow();
}
}
if (arr.length !== 0) {
schema.properties.hierarchy = {
title: " ",
oneOf: arr
};
} }
return arr;
}); });
} }
function discoverLevels(schema, opt) { function discoverLevels(g, connection_name, opt) {
return xmla_request_retry("discoverMDLevels", opt) return g.getLevels(connection_name, opt)
.push(undefined, function (error) { .push(undefined, function (error) {
console.log(error); console.log(error);
}) })
.push(function (response) { .push(function (response) {
var arr = [], var arr = [],
i,
row; row;
if (response && response.numRows > 0) { for (i = 0; i < response.length; i += 1) {
while (response.hasMoreRows()) { row = response[i];
row = response.readAsObject(); if (
if (row["LEVEL_TYPE"] !== 1) { // exclude all level type row["LEVEL_CARDINALITY"] < 150 &&
row["LEVEL_TYPE"] !== 1 // exclude all level type
) {
arr.push({ arr.push({
const: row["LEVEL_UNIQUE_NAME"] || undefined, const: row["LEVEL_UNIQUE_NAME"] || undefined,
title: row["LEVEL_NAME"] || undefined title: row["LEVEL_NAME"] || undefined
}); });
} }
response.nextRow();
}
}
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 = { var schema = {
"type": "object", "type": "object",
"additionalProperties": false, "additionalProperties": false,
"properties": {} "properties": {}
}, },
current_dimension; current_dimension;
if (!connection_settings) { if (!connection_name) {
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
return schema; return schema;
}); });
} }
if (!connection_settings.hasOwnProperty('properties')) {
connection_settings.properties = {};
}
if (!choice_settings) { if (!choice_settings) {
choice_settings = {}; choice_settings = {};
} }
...@@ -219,47 +129,46 @@ ...@@ -219,47 +129,46 @@
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
var tasks = [discoverDimensions(schema, used_dimensions, { var tasks = [discoverDimensions(g, connection_name, used_dimensions)];
urls: connection_settings.urls,
prop: {
restrictions: {
CATALOG_NAME: connection_settings.properties.Catalog,
CUBE_NAME: connection_settings.properties.Cube
}
}
})];
if (choice_settings.dimension) { if (choice_settings.dimension) {
tasks.push( tasks.push(
discoverHierarchies(schema, { discoverHierarchies(g, connection_name,{prop: {
urls: connection_settings.urls,
prop: {
restrictions: { restrictions: {
CATALOG_NAME: connection_settings.properties.Catalog,
CUBE_NAME: connection_settings.properties.Cube,
DIMENSION_UNIQUE_NAME: choice_settings.dimension DIMENSION_UNIQUE_NAME: choice_settings.dimension
} }
} }})
})
); );
} }
if (choice_settings.hierarchy) { if (choice_settings.hierarchy) {
tasks.push(discoverLevels(schema, { tasks.push(discoverLevels(g, connection_name, {
urls: connection_settings.urls,
prop: {
restrictions: {
CATALOG_NAME: connection_settings.properties.Catalog,
CUBE_NAME: connection_settings.properties.Cube,
DIMENSION_UNIQUE_NAME: choice_settings.dimension, DIMENSION_UNIQUE_NAME: choice_settings.dimension,
HIERARCHY_UNIQUE_NAME: choice_settings.hierarchy HIERARCHY_UNIQUE_NAME: choice_settings.hierarchy
}
}
})); }));
} }
return RSVP.all(tasks); 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; return schema;
}) })
.push(undefined, function () { .push(undefined, function () {
...@@ -277,6 +186,8 @@ ...@@ -277,6 +186,8 @@
}); });
}) })
.declareAcquiredMethod("getRemoteSettings", "getRemoteSettings") .declareAcquiredMethod("getRemoteSettings", "getRemoteSettings")
.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) {
...@@ -328,10 +239,10 @@ ...@@ -328,10 +239,10 @@
queue = RSVP.Queue(); queue = RSVP.Queue();
} }
function rerender_once(connection_settings, sub_gadget) { function rerender_once(connection_name, sub_gadget) {
return sub_gadget.getContent() return sub_gadget.getContent()
.push(function (content) { .push(function (content) {
return generateChoiceSchema(connection_settings, used_diemensions, content); return generateChoiceSchema(g, connection_name, used_diemensions, content);
}) })
.push(function (schema) { .push(function (schema) {
return gadget_settings.rerender({ return gadget_settings.rerender({
...@@ -349,25 +260,25 @@ ...@@ -349,25 +260,25 @@
.push(function (gadget) { .push(function (gadget) {
gadget_settings = gadget; gadget_settings = gadget;
return RSVP.all([ return RSVP.all([
getCurrentConnectionSettings(g, gadget), gadget.getContent("/connection_name"),
gadget.getSubGadget(sub_scope) gadget.getSubGadget(sub_scope)
]); ]);
}) })
.push(function (arr) { .push(function (arr) {
var connection_settings = arr[0], var connection_name = arr[0],
sub_gadget = arr[1]; sub_gadget = arr[1];
return rerender_once(connection_settings, sub_gadget) return rerender_once(connection_name, sub_gadget)
.push(function (changed) { .push(function (changed) {
if (changed && changed.length > 0) { if (changed && changed.length > 0) {
if (changed.indexOf('/dimension') >= 0) { if (changed.indexOf('/dimension') >= 0) {
return allRerender(); return allRerender();
} }
return rerender_once(connection_settings, sub_gadget); return rerender_once(connection_name, sub_gadget);
} }
}) })
.push(function (changed) { .push(function (changed) {
if (changed && changed.length > 0) { if (changed && changed.length > 0) {
return rerender_once(connection_settings, sub_gadget); return rerender_once(connection_name, sub_gadget);
} }
}); });
}); });
...@@ -441,20 +352,18 @@ ...@@ -441,20 +352,18 @@
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
return RSVP.all([ return RSVP.all([
g.getRemoteSettings(),
g.getContent("/connection_name"), g.getContent("/connection_name"),
g.getContent(path), g.getContent(path),
get_used_dimensions(g) get_used_dimensions(g)
]); ]);
}) })
.push(function (arr) { .push(function (arr) {
var connection_settings, var choice_settings;
choice_settings;
connection_settings = arr[0][arr[1]];
if (path !== "/columns/" && path !== "/rows/") { if (path !== "/columns/" && path !== "/rows/") {
choice_settings = arr[2]; 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"); throw new Error("urn: '" + url + "' not supported");
......
...@@ -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) {
row = response[i];
arr.push({ arr.push({
const: response["getDataSourceInfo"]() || undefined, const: row["DataSourceInfo"] || undefined,
title: response["getDataSourceName"]() || undefined, title: row["DataSourceName"] || undefined,
description: response["getDataSourceDescription"]() || 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) {
row = response[i];
arr.push({ arr.push({
const: response["getCatalogName"]() || undefined, const: row["CATALOG_NAME"] || undefined,
title: response["getCatalogName"]() || 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) {
row = response[i];
arr.push({ arr.push({
const: response["getCubeName"]() || undefined, const: row["CUBE_NAME"] || undefined,
title: response["getCubeName"]() || undefined title: row["CUBE_NAME"] || undefined
// title: response["getCatalogName"]() || 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 (!d.hasOwnProperty(kk)) {
if (value !== undefined) {
d[kk] = {};
} else {
return;
}
} }
d = d[kk]; if (arr[1] && arr[1].length !== 0) {
schema.properties.Catalog = {
title: " ",
oneOf: arr[1]
};
} }
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");
......
...@@ -5,6 +5,18 @@ ...@@ -5,6 +5,18 @@
"use strict"; "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) { function xmla_request(func, prop) {
var xmla = new Xmla({async: true}); var xmla = new Xmla({async: true});
prop = JSON.parse(JSON.stringify(prop)); prop = JSON.parse(JSON.stringify(prop));
...@@ -54,89 +66,60 @@ ...@@ -54,89 +66,60 @@
return queue; return queue;
} }
function discoverDimensions(schema, used_dimensions, opt) { function request(g, function_name, settings, connection_name) {
return xmla_request_retry("discoverMDDimensions", opt) var queue;
.push(undefined, function (error) { if (connection_name) {
console.log(error); queue = g.getConnectionSettings(connection_name);
}) } else {
.push(function (response) { queue = RSVP.Queue();
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();
}
}
if (arr.length !== 0) {
schema.properties.dimension = {
title: " ",
oneOf: arr
};
} }
}); return queue
.push(function (connection_settings) {
if (!settings) {
settings = {};
} }
if (!settings.prop) {
function discoverHierarchies(schema, opt) { settings.prop = {};
return xmla_request_retry("discoverMDHierarchies", 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();
arr.push({
const: row["HIERARCHY_UNIQUE_NAME"] || undefined,
title: row["HIERARCHY_NAME"] || undefined
});
response.nextRow();
} }
if (!settings.prop.restrictions) {
settings.prop.restrictions = {};
} }
if (arr.length !== 0) { if (connection_settings) {
schema.properties.hierarchy = { settings.urls = connection_settings.urls;
title: " ", settings.prop.restrictions.CATALOG_NAME = connection_settings.properties.Catalog;
oneOf: arr settings.prop.restrictions.CUBE_NAME = connection_settings.properties.Cube;
};
} }
return xmla_request_retry(function_name, settings);
}); });
} }
function discoverLevels(schema, opt) { function levelDiscovery(g, connection_name, row) {
return xmla_request_retry("discoverMDLevels", opt) var level_uname = row["LEVEL_UNIQUE_NAME"],
.push(undefined, function (error) { cache = g.props.cache[connection_name],
console.log(error); queue,
}) LEVEL_CARDINALITY = row.LEVEL_CARDINALITY;
.push(function (response) { if (LEVEL_CARDINALITY < 0) {
var arr = [], // XXX LEVEL_CARDINALITY broken in saiku xmla
row; queue = g.getMembersOnLevel(connection_name, level_uname);
if (response && response.numRows > 0) { } else {
while (response.hasMoreRows()) { queue = RSVP.Queue();
row = response.readAsObject();
arr.push({
const: row["LEVEL_UNIQUE_NAME"] || undefined,
title: row["LEVEL_NAME"] || undefined
});
response.nextRow();
}
} }
if (arr.length !== 0) { queue
schema.properties.level = { .push(function (members) {
title: " ", var level;
oneOf: arr if (LEVEL_CARDINALITY < 0 && members) {
LEVEL_CARDINALITY = members.length;
}
level = {
LEVEL_UNIQUE_NAME: row.LEVEL_UNIQUE_NAME,
LEVEL_TYPE: row.LEVEL_TYPE,
LEVEL_NAME: row.LEVEL_NAME || undefined,
LEVEL_CARDINALITY: LEVEL_CARDINALITY,
}; };
} cache.levels[level_uname] = level;
return level;
}); });
return queue;
} }
rJS(window) rJS(window)
...@@ -184,43 +167,92 @@ ...@@ -184,43 +167,92 @@
if (m_dict[key] !== null) { if (m_dict[key] !== null) {
g.props.cache[key] = { g.props.cache[key] = {
members: {}, members: {},
levels: {} levels: {},
membersOnLevel: {}
}; };
g.props.connections[key] = JSON.parse(m_dict[key]); g.props.connections[key] = JSON.parse(m_dict[key]);
} }
} }
} }
}) })
.declareMethod("request", function (function_name, settings, connection_name) { .declareMethod("request", function (function_name, connection_name, settings) {
var queue; return request(this, function_name, settings, connection_name)
if (connection_name) { .push(function (response) {
queue = this.getConnectionSettings(connection_name); var ret = [];
} else { while (response.hasMoreRows()) {
queue = RSVP.Queue(); ret.push(response.readAsObject());
} response.nextRow();
return queue
.push(function (connection_settings) {
if (!settings) {
settings = {};
}
if (connection_settings) {
settings.urls = connection_settings.urls;
settings.prop.restrictions.CATALOG_NAME = connection_settings.properties.Catalog;
settings.prop.restrictions.CUBE_NAME = connection_settings.properties.Cube;
} }
return xmla_request_retry(function_name, settings); return ret;
}) })
.push(undefined, function (error) { .push(undefined, function (error) {
console.error(error); console.error(error);
}); });
}) })
.declareMethod("getMembersOnLevel", function (connection_name, level_uname) { .declareMethod("getLevel", function (connection_name, level_uname) {
var g = this, var g = this,
cache = g.props.cache[connection_name]; cache = g.props.cache[connection_name],
queue;
if (cache.levels.hasOwnProperty(level_uname)) { if (cache.levels.hasOwnProperty(level_uname)) {
return getFromCache(cache.levels, level_uname);
}
queue = g.getLevels(connection_name, {
LEVEL_UNIQUE_NAME: level_uname
})
.push(function () {
return cache.levels[level_uname]; return cache.levels[level_uname];
})
.push(undefined, function (err) {
console.error(err);
});
cache.levels[level_uname] = queue;
return queue;
})
.declareMethod("getLevels", function (connection_name, restrictions) {
var g = this,
cache = g.props.cache[connection_name];
return request(g, "discoverMDLevels", {
prop: {
restrictions: restrictions
}
}, connection_name)
.push(function (response) {
var ret = [],
row,
level,
level_uname;
if (response && response.numRows > 0) {
while (response.hasMoreRows()) {
row = response.readAsObject();
level_uname = row["LEVEL_UNIQUE_NAME"];
if (cache.levels.hasOwnProperty(level_uname)) {
if (cache.levels[level_uname].hasOwnProperty("LEVEL_UNIQUE_NAME")) {
level = cache.levels[level_uname];
} else {
level = levelDiscovery(g, connection_name, row);
}
} else {
level = levelDiscovery(g, connection_name, row);
cache.levels[level_uname] = level;
}
ret.push(level);
response.nextRow();
}
}
return RSVP.all(ret);
})
.push(undefined, function (err) {
console.error(err);
});
})
.declareMethod("getMembersOnLevel", function (connection_name, level_uname) {
var g = this,
cache = g.props.cache[connection_name],
queue;
if (cache.membersOnLevel.hasOwnProperty(level_uname)) {
return getFromCache(cache.membersOnLevel, level_uname);
} }
return g.request("discoverMDMembers", { queue = request(g,"discoverMDMembers", {
prop: { prop: {
restrictions: { restrictions: {
LEVEL_UNIQUE_NAME: level_uname LEVEL_UNIQUE_NAME: level_uname
...@@ -231,7 +263,7 @@ ...@@ -231,7 +263,7 @@
var uname, var uname,
member, member,
i, i,
level = []; members = [];
while (r.hasMoreRows()) { while (r.hasMoreRows()) {
uname = r["getMemberUniqueName"](); uname = r["getMemberUniqueName"]();
if (level_uname !== r["getLevelUniqueName"]()) { if (level_uname !== r["getLevelUniqueName"]()) {
...@@ -246,7 +278,7 @@ ...@@ -246,7 +278,7 @@
}; };
r.nextRow(); r.nextRow();
cache.members[uname] = member; cache.members[uname] = member;
level.push(member); members.push(member);
} }
function compare(a, b) { function compare(a, b) {
...@@ -259,21 +291,27 @@ ...@@ -259,21 +291,27 @@
return 0; return 0;
} }
level.sort(compare); members.sort(compare);
for (i = 0; i < level.length; i += 1) { for (i = 0; i < members.length; i += 1) {
level[i].level_index = i; members[i].level_index = i;
} }
cache.levels[level_uname] = level; cache.membersOnLevel[level_uname] = members;
return level; return members;
})
.push(undefined, function (err) {
console.error(err);
}); });
}, {mutex: 'getMembersOnLevel'}) cache.membersOnLevel[level_uname] = queue;
return queue;
})
.declareMethod("getMember", function (connection_name, memeber_uname) { .declareMethod("getMember", function (connection_name, memeber_uname) {
var g = this, var g = this,
cache = g.props.cache[connection_name]; cache = g.props.cache[connection_name],
queue;
if (cache.members.hasOwnProperty(memeber_uname)) { if (cache.members.hasOwnProperty(memeber_uname)) {
return cache.members[memeber_uname]; return getFromCache(cache.members, memeber_uname);
} }
return g.request("discoverMDMembers", { queue = request(g, "discoverMDMembers", {
prop: { prop: {
restrictions: { restrictions: {
MEMBER_UNIQUE_NAME: memeber_uname, MEMBER_UNIQUE_NAME: memeber_uname,
...@@ -283,18 +321,25 @@ ...@@ -283,18 +321,25 @@
} }
}, connection_name) }, connection_name)
.push(function (r) { .push(function (r) {
if (r.length === 0) { if (r.rowCount() === 0) {
return; return;
} }
return g.getMembersOnLevel(connection_name, r["getLevelUniqueName"]()); return g.getMembersOnLevel(connection_name, r["getLevelUniqueName"]());
}) })
.push(function (level) { .push(function (members) {
if (!level) { if (!members) {
// cache.members[memeber_uname] = false;
return; return;
} }
return cache.members[memeber_uname]; return cache.members[memeber_uname];
})
.push(undefined, function (err) {
console.error(err);
// throw err;
}); });
}, {mutex: 'getMember'}) cache.members[memeber_uname] = queue;
return queue;
})
.declareMethod("getMemberWithOffset", function (connection_name, memeber_uname, offset) { .declareMethod("getMemberWithOffset", function (connection_name, memeber_uname, offset) {
var g = this, var g = this,
member; member;
......
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